Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit f5829cc

Browse files
committed
Fixed fields named where, replace ~[] with Vec, remove old boxed closures
Replacments for boxed closures are made for ease of replacing them, not with any thoughts for speed for effeciency
1 parent 34e52e8 commit f5829cc

File tree

15 files changed

+266
-262
lines changed

15 files changed

+266
-262
lines changed

builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use types::*;
22
use interner::intern;
33

44
///Returns an array of all the compiler primitves which exist (not including numeric primitives atm)
5-
pub fn builtins() -> ~[(&'static str, Type)] {
5+
pub fn builtins() -> Vec<(&'static str, Type)> {
66
let var = Generic(TypeVariable { id: intern("a"), kind: StarKind, age: 0 } );
77
let var2 = Generic(TypeVariable { id: intern("b"), kind: StarKind, age: 0 } );
8-
~[("error", function_type_(list_type(char_type()), var.clone())),
8+
vec![("error", function_type_(list_type(char_type()), var.clone())),
99
("seq", function_type_(var.clone(), function_type_(var2.clone(), var2.clone()))),
1010
("readFile", function_type_(list_type(char_type()), io(list_type(char_type())))),
1111
("io_bind", function_type_(io(var.clone()),

compiler.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ pub struct SuperCombinator {
119119
pub arity : uint,
120120
pub name: Name,
121121
pub assembly_id: uint,
122-
pub instructions : ~[Instruction],
122+
pub instructions : Vec<Instruction>,
123123
pub typ: Qualified<Type, Name>
124124
}
125125
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>>,
131131
pub offset: uint
132132
}
133133

@@ -381,13 +381,13 @@ enum ArgList<'a> {
381381

382382
pub struct Compiler<'a> {
383383
///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>)>,
385385
pub stackSize : uint,
386386
///Array of all the assemblies which can be used to lookup functions in
387387
pub assemblies: Vec<&'a Assembly>,
388388
module: Option<&'a Module<Id>>,
389389
variables: ScopedMap<Name, Var<'a>>,
390-
context: ~[Constraint<Name>]
390+
context: Vec<Constraint<Name>>
391391
}
392392

393393

@@ -443,7 +443,7 @@ impl <'a> Compiler<'a> {
443443
instance_dictionaries: FromVec::from_vec(instance_dictionaries),
444444
offset: self.assemblies.iter().flat_map(|assembly| assembly.superCombinators.iter()).len(),
445445
classes: module.classes.clone(),
446-
instances: FromVec::<(~[Constraint<Name>], Type)>::from_vec(
446+
instances: FromVec::<(Vec<Constraint<Name>>, Type)>::from_vec(
447447
module.instances.iter()
448448
.map(|x| (x.constraints.clone(), Type::new_op(x.classname.name, box [x.typ.clone()])))
449449
.collect()
@@ -458,7 +458,7 @@ impl <'a> Compiler<'a> {
458458
self.context = bind.name.typ.constraints.clone();
459459
let mut instructions = Vec::new();
460460
let mut arity = 0;
461-
self.scope(|this| {
461+
self.scope(&mut |this| {
462462
if dict_arg == 1 {
463463
this.new_stack_var(Name { name: intern("$dict"), uid: 0 });
464464
}
@@ -579,7 +579,7 @@ impl <'a> Compiler<'a> {
579579
self.variables.insert(identifier, StackVariable(index));
580580
}
581581

582-
fn scope(&mut self, f: |&mut Compiler|) {
582+
fn scope(&mut self, f: &mut FnMut(&mut Compiler)) {
583583
self.variables.enter_scope();
584584
let stackSize = self.stackSize;
585585
f(self);
@@ -605,7 +605,7 @@ impl <'a> Compiler<'a> {
605605
else {
606606
let fromInteger = Identifier(Id {
607607
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())),
609609
});
610610
let number = Literal(Literal { typ: int_type(), value: Integral(i) });
611611
let apply = Apply(box fromInteger, box number);
@@ -619,7 +619,7 @@ impl <'a> Compiler<'a> {
619619
else {
620620
let fromRational = Identifier(Id {
621621
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())),
623623
});
624624
let number = Literal(Literal {
625625
typ: double_type(),
@@ -643,7 +643,7 @@ impl <'a> Compiler<'a> {
643643
self.compile_apply(expr, Nil, instructions, strict);
644644
}
645645
&Let(ref bindings, ref body) => {
646-
self.scope(|this| {
646+
self.scope(&mut |this| {
647647
for bind in bindings.iter() {
648648
this.new_stack_var(bind.name.name.clone());
649649
//Workaround since this compiles non-recursive bindings
@@ -665,7 +665,7 @@ impl <'a> Compiler<'a> {
665665
for i in range(0, alternatives.len()) {
666666
let alt = &alternatives[i];
667667

668-
self.scope(|this| {
668+
self.scope(&mut |this| {
669669
let pattern_start = instructions.len() as int;
670670
let mut branches = Vec::new();
671671
let stack_increase = this.compile_pattern(&alt.pattern, &mut branches, instructions, this.stackSize - 1);
@@ -929,7 +929,7 @@ impl <'a> Compiler<'a> {
929929

930930
///Walks through the class and all of its super classes, calling 'f' on each of them
931931
///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> {
933933
let (constraints, _, declarations) = self.find_class(class)
934934
.expect("Compiler error: Expected class");
935935
//Look through the functions in any super classes first
@@ -1130,7 +1130,7 @@ fn add() {
11301130
let file = "main = primIntAdd 1 2";
11311131
let assembly = compile(file);
11321132

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]);
11341134
}
11351135

11361136
#[test]
@@ -1140,16 +1140,16 @@ r"add x y = primDoubleAdd x y
11401140
main = add 2. 3.";
11411141
let assembly = compile(file);
11421142

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]);
11451145
}
11461146
#[test]
11471147
fn push_num_double() {
11481148
let file =
11491149
r"main = primDoubleAdd 2 3";
11501150
let assembly = compile(file);
11511151

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]);
11531153
}
11541154

11551155
#[test]
@@ -1159,7 +1159,7 @@ r"add x y = primIntAdd x y
11591159
main = add 2 3";
11601160
let assembly = compile(file);
11611161

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]);
11631163
}
11641164

11651165
#[test]
@@ -1168,7 +1168,7 @@ fn compile_constructor() {
11681168
r"main = primIntAdd 1 0 : []";
11691169
let assembly = compile(file);
11701170

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]);
11721172
}
11731173

11741174
#[test]
@@ -1177,7 +1177,7 @@ fn compile_tuple() {
11771177
r"test x y = (primIntAdd 0 1, x, y)";
11781178
let assembly = compile(file);
11791179

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]);
11811181
}
11821182

11831183
#[test]
@@ -1189,7 +1189,7 @@ r"main = case [primIntAdd 1 0] of
11891189
let assembly = compile(file);
11901190

11911191

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),
11931193
Push(0), CaseJump(1), Jump(14), Split(2), Push(1), Eval, Slide(2), Jump(22), Pop(2),
11941194
Push(0), CaseJump(0), Jump(22), Split(0), PushInt(2), Slide(0), Jump(22), Pop(0), Slide(1), Eval, Update(0), Unwind]);
11951195
}
@@ -1208,7 +1208,7 @@ main = test (primIntAdd 6 0)";
12081208

12091209
let main = &assembly.superCombinators[0];
12101210
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]);
12121212
}
12131213

12141214
#[test]
@@ -1225,7 +1225,7 @@ main x = primIntAdd (test x) 6";
12251225

12261226
let main = assembly.superCombinators[0];
12271227
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]);
12291229
}
12301230

12311231
#[test]
@@ -1237,7 +1237,7 @@ fn compile_prelude() {
12371237

12381238
let sc = &assembly.superCombinators[0];
12391239
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]);
12411241
}
12421242

12431243
#[test]

0 commit comments

Comments
 (0)