@@ -119,15 +119,15 @@ pub struct SuperCombinator {
119
119
pub arity : uint ,
120
120
pub name : Name ,
121
121
pub assembly_id : uint ,
122
- pub instructions : ~ [ Instruction ] ,
122
+ pub instructions : Vec < Instruction > ,
123
123
pub typ : Qualified < Type , Name >
124
124
}
125
125
pub struct Assembly {
126
- pub superCombinators : ~ [ SuperCombinator ] ,
127
- pub instance_dictionaries : ~ [ ~ [ uint ] ] ,
128
- pub classes : ~ [ Class < Id > ] ,
129
- pub instances : ~ [ ( ~ [ Constraint < Name > ] , Type ) ] ,
130
- pub data_definitions : ~ [ DataDefinition < Name > ] ,
126
+ pub superCombinators : Vec < SuperCombinator > ,
127
+ pub instance_dictionaries : Vec < Vec < uint > > ,
128
+ pub classes : Vec < Class < Id > > ,
129
+ pub instances : Vec < ( Vec < Constraint < Name > > , Type ) > ,
130
+ pub data_definitions : Vec < DataDefinition < Name > > ,
131
131
pub offset : uint
132
132
}
133
133
@@ -381,13 +381,13 @@ enum ArgList<'a> {
381
381
382
382
pub struct Compiler < ' a > {
383
383
///Hashmap containging class names mapped to the functions it contains
384
- pub instance_dictionaries : Vec < ( ~ [ ( Name , Type ) ] , ~ [ uint ] ) > ,
384
+ pub instance_dictionaries : Vec < ( Vec < ( Name , Type ) > , Vec < uint > ) > ,
385
385
pub stackSize : uint ,
386
386
///Array of all the assemblies which can be used to lookup functions in
387
387
pub assemblies : Vec < & ' a Assembly > ,
388
388
module : Option < & ' a Module < Id > > ,
389
389
variables : ScopedMap < Name , Var < ' a > > ,
390
- context : ~ [ Constraint < Name > ]
390
+ context : Vec < Constraint < Name > >
391
391
}
392
392
393
393
@@ -443,7 +443,7 @@ impl <'a> Compiler<'a> {
443
443
instance_dictionaries : FromVec :: from_vec ( instance_dictionaries) ,
444
444
offset : self . assemblies . iter ( ) . flat_map ( |assembly| assembly. superCombinators . iter ( ) ) . len ( ) ,
445
445
classes : module. classes . clone ( ) ,
446
- instances : FromVec :: < ( ~ [ Constraint < Name > ] , Type ) > :: from_vec (
446
+ instances : FromVec :: < ( Vec < Constraint < Name > > , Type ) > :: from_vec (
447
447
module. instances . iter ( )
448
448
. map ( |x| ( x. constraints . clone ( ) , Type :: new_op ( x. classname . name , box [ x. typ . clone ( ) ] ) ) )
449
449
. collect ( )
@@ -458,7 +458,7 @@ impl <'a> Compiler<'a> {
458
458
self . context = bind. name . typ . constraints . clone ( ) ;
459
459
let mut instructions = Vec :: new ( ) ;
460
460
let mut arity = 0 ;
461
- self . scope ( |this| {
461
+ self . scope ( & mut |this| {
462
462
if dict_arg == 1 {
463
463
this. new_stack_var ( Name { name : intern ( "$dict" ) , uid : 0 } ) ;
464
464
}
@@ -579,7 +579,7 @@ impl <'a> Compiler<'a> {
579
579
self . variables . insert ( identifier, StackVariable ( index) ) ;
580
580
}
581
581
582
- fn scope ( & mut self , f: | & mut Compiler | ) {
582
+ fn scope ( & mut self , f : & mut FnMut ( & mut Compiler ) ) {
583
583
self . variables . enter_scope ( ) ;
584
584
let stackSize = self . stackSize ;
585
585
f ( self ) ;
@@ -605,7 +605,7 @@ impl <'a> Compiler<'a> {
605
605
else {
606
606
let fromInteger = Identifier ( Id {
607
607
name : Name { name : intern ( "fromInteger" ) , uid : 0 } ,
608
- typ : qualified ( ~ [ ] , function_type_ ( int_type ( ) , literal. typ . clone ( ) ) ) ,
608
+ typ : qualified ( vec ! [ ] , function_type_ ( int_type ( ) , literal. typ . clone ( ) ) ) ,
609
609
} ) ;
610
610
let number = Literal ( Literal { typ : int_type ( ) , value : Integral ( i) } ) ;
611
611
let apply = Apply ( box fromInteger, box number) ;
@@ -619,7 +619,7 @@ impl <'a> Compiler<'a> {
619
619
else {
620
620
let fromRational = Identifier ( Id {
621
621
name : Name { name : intern ( "fromRational" ) , uid : 0 } ,
622
- typ : qualified ( ~ [ ] , function_type_ ( double_type ( ) , literal. typ . clone ( ) ) ) ,
622
+ typ : qualified ( vec ! [ ] , function_type_ ( double_type ( ) , literal. typ . clone ( ) ) ) ,
623
623
} ) ;
624
624
let number = Literal ( Literal {
625
625
typ : double_type ( ) ,
@@ -643,7 +643,7 @@ impl <'a> Compiler<'a> {
643
643
self . compile_apply ( expr, Nil , instructions, strict) ;
644
644
}
645
645
& Let ( ref bindings, ref body) => {
646
- self . scope ( |this| {
646
+ self . scope ( & mut |this| {
647
647
for bind in bindings. iter ( ) {
648
648
this. new_stack_var ( bind. name . name . clone ( ) ) ;
649
649
//Workaround since this compiles non-recursive bindings
@@ -665,7 +665,7 @@ impl <'a> Compiler<'a> {
665
665
for i in range ( 0 , alternatives. len ( ) ) {
666
666
let alt = & alternatives[ i] ;
667
667
668
- self . scope ( |this| {
668
+ self . scope ( & mut |this| {
669
669
let pattern_start = instructions. len ( ) as int ;
670
670
let mut branches = Vec :: new ( ) ;
671
671
let stack_increase = this. compile_pattern ( & alt. pattern , & mut branches, instructions, this. stackSize - 1 ) ;
@@ -929,7 +929,7 @@ impl <'a> Compiler<'a> {
929
929
930
930
///Walks through the class and all of its super classes, calling 'f' on each of them
931
931
///Returning Some(..) from the function quits and returns that value
932
- fn walk_classes < T > ( & self , class : Name , f : & mut | & [ TypeDeclaration < Name > ] | -> Option < T > ) -> Option < T > {
932
+ fn walk_classes < T > ( & self , class : Name , f : & mut FnMut ( & [ TypeDeclaration < Name > ] ) -> Option < T > ) -> Option < T > {
933
933
let ( constraints, _, declarations) = self . find_class ( class)
934
934
. expect ( "Compiler error: Expected class" ) ;
935
935
//Look through the functions in any super classes first
@@ -1130,7 +1130,7 @@ fn add() {
1130
1130
let file = "main = primIntAdd 1 2" ;
1131
1131
let assembly = compile ( file) ;
1132
1132
1133
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ PushInt ( 2 ) , PushInt ( 1 ) , Add , Update ( 0 ) , Unwind ] ) ;
1133
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ PushInt ( 2 ) , PushInt ( 1 ) , Add , Update ( 0 ) , Unwind ] ) ;
1134
1134
}
1135
1135
1136
1136
#[ test]
@@ -1140,16 +1140,16 @@ r"add x y = primDoubleAdd x y
1140
1140
main = add 2. 3." ;
1141
1141
let assembly = compile ( file) ;
1142
1142
1143
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ Push ( 1 ) , Eval , Push ( 0 ) , Eval , DoubleAdd , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1144
- assert_eq ! ( assembly. superCombinators[ 1 ] . instructions, ~ [ PushFloat ( 3. ) , PushFloat ( 2. ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1143
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ Push ( 1 ) , Eval , Push ( 0 ) , Eval , DoubleAdd , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1144
+ assert_eq ! ( assembly. superCombinators[ 1 ] . instructions, vec! [ PushFloat ( 3. ) , PushFloat ( 2. ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1145
1145
}
1146
1146
#[ test]
1147
1147
fn push_num_double ( ) {
1148
1148
let file =
1149
1149
r"main = primDoubleAdd 2 3" ;
1150
1150
let assembly = compile ( file) ;
1151
1151
1152
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ PushFloat ( 3. ) , PushFloat ( 2. ) , DoubleAdd , Update ( 0 ) , Unwind ] ) ;
1152
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ PushFloat ( 3. ) , PushFloat ( 2. ) , DoubleAdd , Update ( 0 ) , Unwind ] ) ;
1153
1153
}
1154
1154
1155
1155
#[ test]
@@ -1159,7 +1159,7 @@ r"add x y = primIntAdd x y
1159
1159
main = add 2 3" ;
1160
1160
let assembly = compile ( file) ;
1161
1161
1162
- assert_eq ! ( assembly. superCombinators[ 1 ] . instructions, ~ [ PushInt ( 3 ) , PushInt ( 2 ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1162
+ assert_eq ! ( assembly. superCombinators[ 1 ] . instructions, vec! [ PushInt ( 3 ) , PushInt ( 2 ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1163
1163
}
1164
1164
1165
1165
#[ test]
@@ -1168,7 +1168,7 @@ fn compile_constructor() {
1168
1168
r"main = primIntAdd 1 0 : []" ;
1169
1169
let assembly = compile ( file) ;
1170
1170
1171
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) , Update ( 0 ) , Unwind ] ) ;
1171
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) , Update ( 0 ) , Unwind ] ) ;
1172
1172
}
1173
1173
1174
1174
#[ test]
@@ -1177,7 +1177,7 @@ fn compile_tuple() {
1177
1177
r"test x y = (primIntAdd 0 1, x, y)" ;
1178
1178
let assembly = compile ( file) ;
1179
1179
1180
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ Push ( 1 ) , Push ( 0 ) , PushInt ( 1 ) , PushInt ( 0 ) , Add , Pack ( 0 , 3 ) , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1180
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ Push ( 1 ) , Push ( 0 ) , PushInt ( 1 ) , PushInt ( 0 ) , Add , Pack ( 0 , 3 ) , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1181
1181
}
1182
1182
1183
1183
#[ test]
@@ -1189,7 +1189,7 @@ r"main = case [primIntAdd 1 0] of
1189
1189
let assembly = compile ( file) ;
1190
1190
1191
1191
1192
- assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, ~ [ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) ,
1192
+ assert_eq ! ( assembly. superCombinators[ 0 ] . instructions, vec! [ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) ,
1193
1193
Push ( 0 ) , CaseJump ( 1 ) , Jump ( 14 ) , Split ( 2 ) , Push ( 1 ) , Eval , Slide ( 2 ) , Jump ( 22 ) , Pop ( 2 ) ,
1194
1194
Push ( 0 ) , CaseJump ( 0 ) , Jump ( 22 ) , Split ( 0 ) , PushInt ( 2 ) , Slide ( 0 ) , Jump ( 22 ) , Pop ( 0 ) , Slide ( 1 ) , Eval , Update ( 0 ) , Unwind ] ) ;
1195
1195
}
@@ -1208,7 +1208,7 @@ main = test (primIntAdd 6 0)";
1208
1208
1209
1209
let main = & assembly. superCombinators [ 0 ] ;
1210
1210
assert_eq ! ( main. name. name, intern( "main" ) ) ;
1211
- assert_eq ! ( main. instructions, ~ [ PushInt ( 0 ) , PushInt ( 6 ) , Add , PushGlobal ( 1 ) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1211
+ assert_eq ! ( main. instructions, vec! [ PushInt ( 0 ) , PushInt ( 6 ) , Add , PushGlobal ( 1 ) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1212
1212
}
1213
1213
1214
1214
#[ test]
@@ -1225,7 +1225,7 @@ main x = primIntAdd (test x) 6";
1225
1225
1226
1226
let main = assembly. superCombinators [ 0 ] ;
1227
1227
assert_eq ! ( main. name. name, intern( "main" ) ) ;
1228
- assert_eq ! ( main. instructions, ~ [ PushInt ( 6 ) , Push ( 1 ) , PushDictionaryMember ( 0 ) , Mkap , Eval , Add , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1228
+ assert_eq ! ( main. instructions, vec! [ PushInt ( 6 ) , Push ( 1 ) , PushDictionaryMember ( 0 ) , Mkap , Eval , Add , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1229
1229
}
1230
1230
1231
1231
#[ test]
@@ -1237,7 +1237,7 @@ fn compile_prelude() {
1237
1237
1238
1238
let sc = & assembly. superCombinators [ 0 ] ;
1239
1239
let id_index = prelude. superCombinators . iter ( ) . position ( |sc| sc. name . name == intern ( "id" ) ) . unwrap ( ) ;
1240
- assert_eq ! ( sc. instructions, ~ [ PushInt ( 0 ) , PushInt ( 2 ) , Add , PushGlobal ( id_index) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1240
+ assert_eq ! ( sc. instructions, vec! [ PushInt ( 0 ) , PushInt ( 2 ) , Add , PushGlobal ( id_index) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1241
1241
}
1242
1242
1243
1243
#[ test]
0 commit comments