@@ -126,7 +126,7 @@ pub struct SuperCombinator {
126
126
pub typ : Qualified < Type , Name >
127
127
}
128
128
pub struct Assembly {
129
- pub superCombinators : Vec < SuperCombinator > ,
129
+ pub super_combinators : Vec < SuperCombinator > ,
130
130
pub instance_dictionaries : Vec < Vec < usize > > ,
131
131
pub classes : Vec < Class < Id > > ,
132
132
pub instances : Vec < ( Vec < Constraint < Name > > , Type ) > ,
@@ -151,7 +151,7 @@ impl Globals for Assembly {
151
151
}
152
152
153
153
let mut index = 0 ;
154
- for sc in self . superCombinators . iter ( ) {
154
+ for sc in self . super_combinators . iter ( ) {
155
155
if name == sc. name {
156
156
if sc. typ . constraints . len ( ) > 0 {
157
157
return Some ( Var :: Constraint ( self . offset + index, & sc. typ . value , & * sc. typ . constraints ) ) ;
@@ -215,8 +215,8 @@ fn find_global<'a>(module: &'a Module<Id>, offset: usize, name: Name) -> Option<
215
215
216
216
fn find_constructor ( module : & Module < Id > , name : Name ) -> Option < ( u16 , u16 ) > {
217
217
218
- for dataDef in module. data_definitions . iter ( ) {
219
- for ctor in dataDef . constructors . iter ( ) {
218
+ for data_def in module. data_definitions . iter ( ) {
219
+ for ctor in data_def . constructors . iter ( ) {
220
220
if name == ctor. name {
221
221
return Some ( ( ctor. tag as u16 , ctor. arity as u16 ) ) ;
222
222
}
@@ -279,7 +279,7 @@ impl Types for Module<Id> {
279
279
impl Types for Assembly {
280
280
///Lookup a type
281
281
fn find_type < ' a > ( & ' a self , name : & Name ) -> Option < & ' a Qualified < Type , Name > > {
282
- for sc in self . superCombinators . iter ( ) {
282
+ for sc in self . super_combinators . iter ( ) {
283
283
if sc. name == * name {
284
284
return Some ( & sc. typ ) ;
285
285
}
@@ -377,7 +377,7 @@ enum ArgList<'a> {
377
377
pub struct Compiler < ' a > {
378
378
///Hashmap containging class names mapped to the functions it contains
379
379
pub instance_dictionaries : Vec < ( Vec < ( Name , Type ) > , Vec < usize > ) > ,
380
- pub stackSize : usize ,
380
+ pub stack_size : usize ,
381
381
///Array of all the assemblies which can be used to lookup functions in
382
382
pub assemblies : Vec < & ' a Assembly > ,
383
383
module : Option < & ' a Module < Id > > ,
@@ -399,7 +399,7 @@ impl <'a> Compiler<'a> {
399
399
variables. insert ( Name { name : intern ( name) , uid : 0 } , Var :: Primitive ( 1 , instruction) ) ;
400
400
}
401
401
Compiler { instance_dictionaries : Vec :: new ( ) ,
402
- stackSize : 0 , assemblies : Vec :: new ( ) ,
402
+ stack_size : 0 , assemblies : Vec :: new ( ) ,
403
403
module : None ,
404
404
variables : variables,
405
405
context : Vec :: new ( )
@@ -408,7 +408,7 @@ impl <'a> Compiler<'a> {
408
408
409
409
pub fn compile_module ( & mut self , module : & ' a Module < Id > ) -> Assembly {
410
410
self . module = Some ( module) ;
411
- let mut superCombinators = Vec :: new ( ) ;
411
+ let mut super_combinators = Vec :: new ( ) ;
412
412
let mut instance_dictionaries = Vec :: new ( ) ;
413
413
let mut data_definitions = Vec :: new ( ) ;
414
414
@@ -425,7 +425,7 @@ impl <'a> Compiler<'a> {
425
425
426
426
for bind in bindings {
427
427
let sc = self . compile_binding ( bind) ;
428
- superCombinators . push ( sc) ;
428
+ super_combinators . push ( sc) ;
429
429
}
430
430
431
431
@@ -434,9 +434,9 @@ impl <'a> Compiler<'a> {
434
434
}
435
435
self . module = None ;
436
436
Assembly {
437
- superCombinators : superCombinators ,
437
+ super_combinators : super_combinators ,
438
438
instance_dictionaries : instance_dictionaries,
439
- offset : self . assemblies . iter ( ) . fold ( 0 , |sum, assembly| sum + assembly. superCombinators . len ( ) ) ,
439
+ offset : self . assemblies . iter ( ) . fold ( 0 , |sum, assembly| sum + assembly. super_combinators . len ( ) ) ,
440
440
classes : module. classes . clone ( ) ,
441
441
instances : module. instances . iter ( )
442
442
. map ( |x| ( x. constraints . clone ( ) , Type :: new_op ( x. classname . name , vec ! [ x. typ. clone( ) ] ) ) )
@@ -496,7 +496,7 @@ impl <'a> Compiler<'a> {
496
496
let n = self . assemblies . len ( ) ;
497
497
let offset = if n > 0 {
498
498
let assembly = self . assemblies [ n - 1 ] ;
499
- assembly. offset + assembly. superCombinators . len ( )
499
+ assembly. offset + assembly. super_combinators . len ( )
500
500
}
501
501
else {
502
502
0
@@ -566,18 +566,18 @@ impl <'a> Compiler<'a> {
566
566
}
567
567
568
568
fn new_stack_var ( & mut self , identifier : Name ) {
569
- self . variables . insert ( identifier, Var :: Stack ( self . stackSize ) ) ;
570
- self . stackSize += 1 ;
569
+ self . variables . insert ( identifier, Var :: Stack ( self . stack_size ) ) ;
570
+ self . stack_size += 1 ;
571
571
}
572
572
fn new_var_at ( & mut self , identifier : Name , index : usize ) {
573
573
self . variables . insert ( identifier, Var :: Stack ( index) ) ;
574
574
}
575
575
576
576
fn scope ( & mut self , f : & mut FnMut ( & mut Compiler ) ) {
577
577
self . variables . enter_scope ( ) ;
578
- let stackSize = self . stackSize ;
578
+ let stack_size = self . stack_size ;
579
579
f ( self ) ;
580
- self . stackSize = stackSize ;
580
+ self . stack_size = stack_size ;
581
581
self . variables . exit_scope ( ) ;
582
582
}
583
583
@@ -597,12 +597,12 @@ impl <'a> Compiler<'a> {
597
597
instructions. push ( PushFloat ( i as f64 ) ) ;
598
598
}
599
599
else {
600
- let fromInteger = Identifier ( Id {
600
+ let from_integer = Identifier ( Id {
601
601
name : Name { name : intern ( "fromInteger" ) , uid : 0 } ,
602
602
typ : qualified ( vec ! [ ] , function_type_ ( int_type ( ) , literal. typ . clone ( ) ) ) ,
603
603
} ) ;
604
604
let number = Literal ( LiteralData { typ : int_type ( ) , value : Integral ( i) } ) ;
605
- let apply = Apply ( box fromInteger , box number) ;
605
+ let apply = Apply ( box from_integer , box number) ;
606
606
self . compile ( & apply, instructions, strict) ;
607
607
}
608
608
}
@@ -611,15 +611,15 @@ impl <'a> Compiler<'a> {
611
611
instructions. push ( PushFloat ( f) ) ;
612
612
}
613
613
else {
614
- let fromRational = Identifier ( Id {
614
+ let from_rational = Identifier ( Id {
615
615
name : Name { name : intern ( "fromRational" ) , uid : 0 } ,
616
616
typ : qualified ( vec ! [ ] , function_type_ ( double_type ( ) , literal. typ . clone ( ) ) ) ,
617
617
} ) ;
618
618
let number = Literal ( LiteralData {
619
619
typ : double_type ( ) ,
620
620
value : Fractional ( f)
621
621
} ) ;
622
- let apply = Apply ( box fromRational , box number) ;
622
+ let apply = Apply ( box from_rational , box number) ;
623
623
self . compile ( & apply, instructions, strict) ;
624
624
}
625
625
}
@@ -642,17 +642,17 @@ impl <'a> Compiler<'a> {
642
642
this. new_stack_var ( bind. name . name . clone ( ) ) ;
643
643
//Workaround since this compiles non-recursive bindings
644
644
//The stack is not actually increased until after the binding is compiled
645
- this. stackSize -= 1 ;
645
+ this. stack_size -= 1 ;
646
646
this. compile ( & bind. expression , instructions, false ) ;
647
- this. stackSize += 1 ;
647
+ this. stack_size += 1 ;
648
648
}
649
649
this. compile ( & * * body, instructions, strict) ;
650
650
instructions. push ( Slide ( bindings. len ( ) ) ) ;
651
651
} ) ;
652
652
}
653
653
& Case ( ref body, ref alternatives) => {
654
654
self . compile ( & * * body, instructions, true ) ;
655
- self . stackSize += 1 ;
655
+ self . stack_size += 1 ;
656
656
//Dummy variable for the case expression
657
657
//Storage for all the jumps that should go to the end of the case expression
658
658
let mut end_branches = Vec :: new ( ) ;
@@ -662,7 +662,7 @@ impl <'a> Compiler<'a> {
662
662
self . scope ( & mut |this| {
663
663
let pattern_start = instructions. len ( ) as isize ;
664
664
let mut branches = Vec :: new ( ) ;
665
- let i = this. stackSize - 1 ;
665
+ let i = this. stack_size - 1 ;
666
666
let stack_increase = this. compile_pattern ( & alt. pattern , & mut branches, instructions, i) ;
667
667
let pattern_end = instructions. len ( ) as isize ;
668
668
this. compile ( & alt. expression , instructions, strict) ;
@@ -773,7 +773,7 @@ impl <'a> Compiler<'a> {
773
773
self . compile ( expr, instructions, strict) ;
774
774
}
775
775
}
776
- self . stackSize -= arg_length;
776
+ self . stack_size -= arg_length;
777
777
if is_function {
778
778
for _ in range ( 0 , arg_length) {
779
779
instructions. push ( Mkap ) ;
@@ -790,7 +790,7 @@ impl <'a> Compiler<'a> {
790
790
let i = self . compile_args ( rest, instructions, strict) ;
791
791
//The stack has increased by 1 until the function compiles and reduces it wtih Pack or Mkap
792
792
self . compile ( arg, instructions, strict) ;
793
- self . stackSize += 1 ;
793
+ self . stack_size += 1 ;
794
794
i + 1
795
795
}
796
796
ArgList :: Nil => 0
@@ -1000,9 +1000,9 @@ impl <'a> Compiler<'a> {
1000
1000
_ => panic ! ( "Undefined constructor {:?}" , * name)
1001
1001
}
1002
1002
instructions. push ( Split ( patterns. len ( ) ) ) ;
1003
- self . stackSize += patterns. len ( ) ;
1003
+ self . stack_size += patterns. len ( ) ;
1004
1004
for ( i, p) in patterns. iter ( ) . enumerate ( ) {
1005
- let index = self . stackSize - patterns. len ( ) + i;
1005
+ let index = self . stack_size - patterns. len ( ) + i;
1006
1006
self . new_var_at ( p. name . clone ( ) , index) ;
1007
1007
}
1008
1008
patterns. len ( )
@@ -1120,7 +1120,7 @@ fn add() {
1120
1120
let file = "main = primIntAdd 1 2" ;
1121
1121
let assembly = compile ( file) ;
1122
1122
1123
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ PushInt ( 2 ) , PushInt ( 1 ) , Add , Update ( 0 ) , Unwind ] ) ;
1123
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ PushInt ( 2 ) , PushInt ( 1 ) , Add , Update ( 0 ) , Unwind ] ) ;
1124
1124
}
1125
1125
1126
1126
#[ test]
@@ -1130,16 +1130,16 @@ r"add x y = primDoubleAdd x y
1130
1130
main = add 2. 3." ;
1131
1131
let assembly = compile ( file) ;
1132
1132
1133
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ Push ( 1 ) , Eval , Push ( 0 ) , Eval , DoubleAdd , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1134
- assert_eq ! ( assembly. superCombinators [ 1 ] . instructions, vec![ PushFloat ( 3. ) , PushFloat ( 2. ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1133
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ Push ( 1 ) , Eval , Push ( 0 ) , Eval , DoubleAdd , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1134
+ assert_eq ! ( assembly. super_combinators [ 1 ] . instructions, vec![ PushFloat ( 3. ) , PushFloat ( 2. ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1135
1135
}
1136
1136
#[ test]
1137
1137
fn push_num_double ( ) {
1138
1138
let file =
1139
1139
r"main = primDoubleAdd 2 3" ;
1140
1140
let assembly = compile ( file) ;
1141
1141
1142
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ PushFloat ( 3. ) , PushFloat ( 2. ) , DoubleAdd , Update ( 0 ) , Unwind ] ) ;
1142
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ PushFloat ( 3. ) , PushFloat ( 2. ) , DoubleAdd , Update ( 0 ) , Unwind ] ) ;
1143
1143
}
1144
1144
1145
1145
#[ test]
@@ -1149,7 +1149,7 @@ r"add x y = primIntAdd x y
1149
1149
main = add 2 3" ;
1150
1150
let assembly = compile ( file) ;
1151
1151
1152
- assert_eq ! ( assembly. superCombinators [ 1 ] . instructions, vec![ PushInt ( 3 ) , PushInt ( 2 ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1152
+ assert_eq ! ( assembly. super_combinators [ 1 ] . instructions, vec![ PushInt ( 3 ) , PushInt ( 2 ) , PushGlobal ( 0 ) , Mkap , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1153
1153
}
1154
1154
1155
1155
#[ test]
@@ -1158,7 +1158,7 @@ fn compile_constructor() {
1158
1158
r"main = primIntAdd 1 0 : []" ;
1159
1159
let assembly = compile ( file) ;
1160
1160
1161
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) , Update ( 0 ) , Unwind ] ) ;
1161
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) , Update ( 0 ) , Unwind ] ) ;
1162
1162
}
1163
1163
1164
1164
#[ test]
@@ -1167,7 +1167,7 @@ fn compile_tuple() {
1167
1167
r"test x y = (primIntAdd 0 1, x, y)" ;
1168
1168
let assembly = compile ( file) ;
1169
1169
1170
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ Push ( 1 ) , Push ( 0 ) , PushInt ( 1 ) , PushInt ( 0 ) , Add , Pack ( 0 , 3 ) , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1170
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ Push ( 1 ) , Push ( 0 ) , PushInt ( 1 ) , PushInt ( 0 ) , Add , Pack ( 0 , 3 ) , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1171
1171
}
1172
1172
1173
1173
#[ test]
@@ -1179,7 +1179,7 @@ r"main = case [primIntAdd 1 0] of
1179
1179
let assembly = compile ( file) ;
1180
1180
1181
1181
1182
- assert_eq ! ( assembly. superCombinators [ 0 ] . instructions, vec![ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) ,
1182
+ assert_eq ! ( assembly. super_combinators [ 0 ] . instructions, vec![ Pack ( 0 , 0 ) , PushInt ( 0 ) , PushInt ( 1 ) , Add , Pack ( 1 , 2 ) ,
1183
1183
Push ( 0 ) , CaseJump ( 1 ) , Jump ( 14 ) , Split ( 2 ) , Push ( 1 ) , Eval , Slide ( 2 ) , Jump ( 22 ) , Pop ( 2 ) ,
1184
1184
Push ( 0 ) , CaseJump ( 0 ) , Jump ( 22 ) , Split ( 0 ) , PushInt ( 2 ) , Slide ( 0 ) , Jump ( 22 ) , Pop ( 0 ) , Slide ( 1 ) , Eval , Update ( 0 ) , Unwind ] ) ;
1185
1185
}
@@ -1196,7 +1196,7 @@ instance Test Int where
1196
1196
main = test (primIntAdd 6 0)" ;
1197
1197
let assembly = compile ( file) ;
1198
1198
1199
- let main = & assembly. superCombinators [ 0 ] ;
1199
+ let main = & assembly. super_combinators [ 0 ] ;
1200
1200
assert_eq ! ( main. name. name, intern( "main" ) ) ;
1201
1201
assert_eq ! ( main. instructions, vec![ PushInt ( 0 ) , PushInt ( 6 ) , Add , PushGlobal ( 1 ) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1202
1202
}
@@ -1213,7 +1213,7 @@ instance Test Int where
1213
1213
main x = primIntAdd (test x) 6" ;
1214
1214
let assembly = compile ( file) ;
1215
1215
1216
- let main = & assembly. superCombinators [ 0 ] ;
1216
+ let main = & assembly. super_combinators [ 0 ] ;
1217
1217
assert_eq ! ( main. name. name, intern( "main" ) ) ;
1218
1218
assert_eq ! ( main. instructions, vec![ PushInt ( 6 ) , Push ( 1 ) , PushDictionaryMember ( 0 ) , Mkap , Eval , Add , Update ( 0 ) , Pop ( 2 ) , Unwind ] ) ;
1219
1219
}
@@ -1225,8 +1225,8 @@ fn compile_prelude() {
1225
1225
1226
1226
let assembly = compile_with_type_env ( & mut type_env, & [ & prelude] , r"main = id (primIntAdd 2 0)" ) ;
1227
1227
1228
- let sc = & assembly. superCombinators [ 0 ] ;
1229
- let id_index = prelude. superCombinators . iter ( ) . position ( |sc| sc. name . name == intern ( "id" ) ) . unwrap ( ) ;
1228
+ let sc = & assembly. super_combinators [ 0 ] ;
1229
+ let id_index = prelude. super_combinators . iter ( ) . position ( |sc| sc. name . name == intern ( "id" ) ) . unwrap ( ) ;
1230
1230
assert_eq ! ( sc. instructions, vec![ PushInt ( 0 ) , PushInt ( 2 ) , Add , PushGlobal ( id_index) , Mkap , Eval , Update ( 0 ) , Unwind ] ) ;
1231
1231
}
1232
1232
@@ -1273,7 +1273,7 @@ newtype Test a = Test [a]
1273
1273
test = Test [1::Int]" ;
1274
1274
let assembly = compile ( file) ;
1275
1275
1276
- let test = & assembly. superCombinators [ 0 ] ;
1276
+ let test = & assembly. super_combinators [ 0 ] ;
1277
1277
assert_eq ! ( test. instructions, vec![ Pack ( 0 , 0 ) , PushInt ( 1 ) , Pack ( 1 , 2 ) , Update ( 0 ) , Unwind ] ) ;
1278
1278
}
1279
1279
0 commit comments