1
1
use interner:: * ;
2
2
use core:: * ;
3
3
use core:: Expr :: * ;
4
- use types:: { int_type, double_type, function_type, function_type_, qualified} ;
4
+ use types:: { int_type, double_type, function_type, function_type_, qualified, extract_applied_type } ;
5
5
use typecheck:: { Types , DataTypes , TypeEnvironment , find_specialized_instances} ;
6
6
use scoped_map:: ScopedMap ;
7
7
use std:: iter:: range_step;
8
8
use std:: io:: IoResult ;
9
+ use std:: borrow:: ToOwned ;
9
10
10
11
use core:: translate:: { translate_module, translate_modules} ;
11
12
use lambda_lift:: do_lambda_lift;
@@ -144,7 +145,7 @@ impl Globals for Assembly {
144
145
for class in self . classes . iter ( ) {
145
146
for decl in class. declarations . iter ( ) {
146
147
if decl. name == name {
147
- return Some ( Var :: Class ( & decl. typ . value , decl. typ . constraints , & class. variable ) ) ;
148
+ return Some ( Var :: Class ( & decl. typ . value , & * decl. typ . constraints , & class. variable ) ) ;
148
149
}
149
150
}
150
151
}
@@ -153,7 +154,7 @@ impl Globals for Assembly {
153
154
for sc in self . superCombinators . iter ( ) {
154
155
if name == sc. name {
155
156
if sc. typ . constraints . len ( ) > 0 {
156
- return Some ( Var :: Constraint ( self . offset + index, & sc. typ . value , sc. typ . constraints ) ) ;
157
+ return Some ( Var :: Constraint ( self . offset + index, & sc. typ . value , & * sc. typ . constraints ) ) ;
157
158
}
158
159
else {
159
160
return Some ( Var :: Global ( self . offset + index) ) ;
@@ -180,7 +181,7 @@ fn find_global<'a>(module: &'a Module<Id>, offset: uint, name: Name) -> Option<V
180
181
for class in module. classes . iter ( ) {
181
182
for decl in class. declarations . iter ( ) {
182
183
if decl. name == name {
183
- return Some ( Var :: Class ( & decl. typ . value , decl. typ . constraints , & class. variable ) ) ;
184
+ return Some ( Var :: Class ( & decl. typ . value , & * decl. typ . constraints , & class. variable ) ) ;
184
185
}
185
186
}
186
187
}
@@ -195,7 +196,7 @@ fn find_global<'a>(module: &'a Module<Id>, offset: uint, name: Name) -> Option<V
195
196
let typ = bind. expression . get_type ( ) ;
196
197
let constraints = & bind. name . typ . constraints ;
197
198
if constraints. len ( ) > 0 {
198
- Var :: Constraint ( offset + global_index, typ, * constraints)
199
+ Var :: Constraint ( offset + global_index, typ, & * * constraints)
199
200
}
200
201
else {
201
202
Var :: Global ( offset + global_index)
@@ -275,13 +276,6 @@ impl Types for Module<Id> {
275
276
}
276
277
}
277
278
278
- fn extract_applied_type < ' a > ( typ : & ' a Type ) -> & ' a Type {
279
- match typ {
280
- & Type :: Application ( ref lhs, _) => extract_applied_type ( * lhs) ,
281
- _ => typ
282
- }
283
- }
284
-
285
279
impl Types for Assembly {
286
280
///Lookup a type
287
281
fn find_type < ' a > ( & ' a self , name : & Name ) -> Option < & ' a Qualified < Type , Name > > {
@@ -318,11 +312,11 @@ impl Types for Assembly {
318
312
for & ( ref constraints, ref op) in self . instances . iter ( ) {
319
313
match op {
320
314
& Type :: Application ( ref op, ref t) => {
321
- let x = match extract_applied_type ( * op) {
315
+ let x = match extract_applied_type ( & * * op) {
322
316
& Type :: Constructor ( ref x) => x,
323
317
_ => panic ! ( )
324
318
} ;
325
- let y = match extract_applied_type ( * t) {
319
+ let y = match extract_applied_type ( & * * t) {
326
320
& Type :: Constructor ( ref x) => x,
327
321
_ => panic ! ( )
328
322
} ;
@@ -331,8 +325,7 @@ impl Types for Assembly {
331
325
_ => panic ! ( )
332
326
} ;
333
327
if classname. name == x. name && y. name == z. name {
334
- let o : & Type = * t;
335
- return Some ( ( constraints. as_slice ( ) , o) ) ;
328
+ return Some ( ( constraints. as_slice ( ) , & * * t) ) ;
336
329
}
337
330
}
338
331
_ => ( )
@@ -443,7 +436,7 @@ impl <'a> Compiler<'a> {
443
436
Assembly {
444
437
superCombinators : superCombinators,
445
438
instance_dictionaries : instance_dictionaries,
446
- offset : self . assemblies . iter ( ) . flat_map ( | assembly| assembly. superCombinators . iter ( ) ) . len ( ) ,
439
+ offset : self . assemblies . iter ( ) . fold ( 0 , |sum , assembly| sum + assembly. superCombinators . len ( ) ) ,
447
440
classes : module. classes . clone ( ) ,
448
441
instances : module. instances . iter ( )
449
442
. map ( |x| ( x. constraints . clone ( ) , Type :: new_op ( x. classname . name , vec ! [ x. typ. clone( ) ] ) ) )
@@ -485,7 +478,7 @@ impl <'a> Compiler<'a> {
485
478
match expr {
486
479
& Lambda ( ref ident, ref body) => {
487
480
self . new_stack_var ( ident. name . clone ( ) ) ;
488
- 1 + self . compile_lambda_binding ( * body, instructions)
481
+ 1 + self . compile_lambda_binding ( & * * body, instructions)
489
482
}
490
483
_ => {
491
484
self . compile ( expr, instructions, true ) ;
@@ -502,7 +495,7 @@ impl <'a> Compiler<'a> {
502
495
Some ( ref module) => {
503
496
let n = self . assemblies . len ( ) ;
504
497
let offset = if n > 0 {
505
- let assembly = self . assemblies . get ( n- 1 ) ;
498
+ let assembly = self . assemblies [ n - 1 ] ;
506
499
assembly. offset + assembly. superCombinators . len ( )
507
500
}
508
501
else {
@@ -608,7 +601,7 @@ impl <'a> Compiler<'a> {
608
601
name : Name { name : intern ( "fromInteger" ) , uid : 0 } ,
609
602
typ : qualified ( vec ! [ ] , function_type_ ( int_type ( ) , literal. typ . clone ( ) ) ) ,
610
603
} ) ;
611
- let number = Literal ( Literal { typ : int_type ( ) , value : Integral ( i) } ) ;
604
+ let number = Literal ( LiteralData { typ : int_type ( ) , value : Integral ( i) } ) ;
612
605
let apply = Apply ( box fromInteger, box number) ;
613
606
self . compile ( & apply, instructions, strict) ;
614
607
}
@@ -622,7 +615,7 @@ impl <'a> Compiler<'a> {
622
615
name : Name { name : intern ( "fromRational" ) , uid : 0 } ,
623
616
typ : qualified ( vec ! [ ] , function_type_ ( double_type ( ) , literal. typ . clone ( ) ) ) ,
624
617
} ) ;
625
- let number = Literal ( Literal {
618
+ let number = Literal ( LiteralData {
626
619
typ : double_type ( ) ,
627
620
value : Fractional ( f)
628
621
} ) ;
@@ -653,12 +646,12 @@ impl <'a> Compiler<'a> {
653
646
this. compile ( & bind. expression , instructions, false ) ;
654
647
this. stackSize += 1 ;
655
648
}
656
- this. compile ( * body, instructions, strict) ;
649
+ this. compile ( & * * body, instructions, strict) ;
657
650
instructions. push ( Slide ( bindings. len ( ) ) ) ;
658
651
} ) ;
659
652
}
660
653
& Case ( ref body, ref alternatives) => {
661
- self . compile ( * body, instructions, true ) ;
654
+ self . compile ( & * * body, instructions, true ) ;
662
655
self . stackSize += 1 ;
663
656
//Dummy variable for the case expression
664
657
//Storage for all the jumps that should go to the end of the case expression
@@ -680,19 +673,19 @@ impl <'a> Compiler<'a> {
680
673
//We need to set all the jump instructions to their actual location
681
674
//and append Slide instructions to bring the stack back to normal if the match fails
682
675
for j in range_step ( pattern_end, pattern_start, -1 ) {
683
- match * instructions. get ( j as uint ) {
676
+ match instructions[ j as uint ] {
684
677
Jump ( _) => {
685
- * instructions. get_mut ( j as uint ) = Jump ( instructions. len ( ) ) ;
678
+ instructions[ j as uint ] = Jump ( instructions. len ( ) ) ;
686
679
}
687
- JumpFalse ( _) => * instructions. get_mut ( j as uint ) = JumpFalse ( instructions. len ( ) ) ,
680
+ JumpFalse ( _) => instructions[ j as uint ] = JumpFalse ( instructions. len ( ) ) ,
688
681
Split ( size) => instructions. push ( Pop ( size) ) ,
689
682
_ => ( )
690
683
}
691
684
}
692
685
} ) ;
693
686
}
694
687
for branch in end_branches. iter ( ) {
695
- * instructions. get_mut ( * branch) = Jump ( instructions. len ( ) ) ;
688
+ instructions[ * branch] = Jump ( instructions. len ( ) ) ;
696
689
}
697
690
//Remove the matched expr
698
691
instructions. push ( Slide ( 1 ) ) ;
@@ -707,7 +700,7 @@ impl <'a> Compiler<'a> {
707
700
//Unroll the applications until the function is found
708
701
match * expr {
709
702
Apply ( ref func, ref arg) => {
710
- return self . compile_apply ( * func, ArgList :: Cons ( * arg, & args) , instructions, strict)
703
+ return self . compile_apply ( & * * func, ArgList :: Cons ( & * * arg, & args) , instructions, strict)
711
704
}
712
705
_ => ( )
713
706
}
@@ -839,15 +832,15 @@ impl <'a> Compiler<'a> {
839
832
Some ( index) => instructions. push ( PushDictionaryMember ( index) ) ,
840
833
None => {
841
834
let dictionary_key = find_specialized_instances ( function_type, actual_type, constraints) ;
842
- self . push_dictionary ( constraints, dictionary_key, instructions) ;
835
+ self . push_dictionary ( constraints, & * dictionary_key, instructions) ;
843
836
}
844
837
}
845
838
}
846
839
_ => {
847
840
//get dictionary index
848
841
//push dictionary
849
842
let dictionary_key = find_specialized_instances ( function_type, actual_type, constraints) ;
850
- self . push_dictionary ( constraints, dictionary_key, instructions) ;
843
+ self . push_dictionary ( constraints, & * dictionary_key, instructions) ;
851
844
}
852
845
}
853
846
}
@@ -873,8 +866,8 @@ impl <'a> Compiler<'a> {
873
866
debug ! ( "App for ({:?} {:?})" , lhs, rhs) ;
874
867
//For function in functions
875
868
// Mkap function fold_dictionary(rhs)
876
- self . fold_dictionary ( class, * lhs, instructions) ;
877
- self . fold_dictionary ( class, * rhs, instructions) ;
869
+ self . fold_dictionary ( class, & * * lhs, instructions) ;
870
+ self . fold_dictionary ( class, & * * rhs, instructions) ;
878
871
instructions. push ( MkapDictionary ) ;
879
872
}
880
873
Type :: Variable ( ref var) => {
@@ -912,7 +905,7 @@ impl <'a> Compiler<'a> {
912
905
}
913
906
let mut ii = 0 ;
914
907
for c in constraints. iter ( ) {
915
- let result = self . walk_classes ( c. class , & mut |declarations| {
908
+ let result = self . walk_classes ( c. class , & mut |declarations| -> Option < uint > {
916
909
for decl in declarations. iter ( ) {
917
910
if decl. name == name {
918
911
return Some ( ii)
@@ -946,7 +939,7 @@ impl <'a> Compiler<'a> {
946
939
//Check if the dictionary already exist
947
940
let dict_len = self . instance_dictionaries . len ( ) ;
948
941
for ii in range ( 0 , dict_len) {
949
- if self . instance_dictionaries . get ( ii ) . ref0 ( ) . equiv ( & constraints) {
942
+ if self . instance_dictionaries [ ii ] . 0 == constraints {
950
943
return ii;
951
944
}
952
945
}
@@ -962,13 +955,6 @@ impl <'a> Compiler<'a> {
962
955
963
956
fn add_class ( & self , constraints : & [ ( Name , Type ) ] , function_indexes : & mut Vec < uint > ) {
964
957
965
- fn extract_applied_type < ' a > ( typ : & ' a Type ) -> & ' a Type {
966
- match typ {
967
- & Type :: Application ( ref lhs, _) => extract_applied_type ( * lhs) ,
968
- _ => typ
969
- }
970
- }
971
-
972
958
for & ( ref class_name, ref typ) in constraints. iter ( ) {
973
959
self . walk_classes ( * class_name, & mut |declarations| -> Option < ( ) > {
974
960
for decl in declarations. iter ( ) {
@@ -1053,8 +1039,8 @@ fn try_find_instance_type<'a>(class_var: &TypeVariable, class_type: &Type, actua
1053
1039
None
1054
1040
}
1055
1041
( & Type :: Application ( ref lhs1, ref rhs1) , & Type :: Application ( ref lhs2, ref rhs2) ) => {
1056
- try_find_instance_type ( class_var, * lhs1, * lhs2)
1057
- . or_else ( || try_find_instance_type ( class_var, * rhs1, * rhs2) )
1042
+ try_find_instance_type ( class_var, & * * lhs1, & * * lhs2)
1043
+ . or_else ( || try_find_instance_type ( class_var, & * * rhs1, & * * rhs2) )
1058
1044
}
1059
1045
_ => None
1060
1046
}
@@ -1063,10 +1049,10 @@ fn try_find_instance_type<'a>(class_var: &TypeVariable, class_type: &Type, actua
1063
1049
#[ allow( dead_code) ]
1064
1050
pub fn compile ( contents : & str ) -> Assembly {
1065
1051
let mut type_env = TypeEnvironment :: new ( ) ;
1066
- compile_with_type_env ( & mut type_env, [ ] , contents)
1052
+ compile_with_type_env ( & mut type_env, & [ ] , contents)
1067
1053
}
1068
1054
#[ allow( dead_code) ]
1069
- pub fn compile_with_type_env ( type_env : & mut TypeEnvironment , assemblies : & [ & Assembly ] , contents : & str ) -> Assembly {
1055
+ pub fn compile_with_type_env < ' a > ( type_env : & ' a mut TypeEnvironment < ' a > , assemblies : & [ & ' a Assembly ] , contents : & str ) -> Assembly {
1070
1056
use parser:: Parser ;
1071
1057
1072
1058
let mut parser = Parser :: new ( contents. as_slice ( ) . chars ( ) ) ;
0 commit comments