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

Commit d123fe9

Browse files
committed
Renamed camelCase variables into snake_case
1 parent 64a303e commit d123fe9

File tree

5 files changed

+188
-192
lines changed

5 files changed

+188
-192
lines changed

compiler.rs

+41-41
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub struct SuperCombinator {
126126
pub typ: Qualified<Type, Name>
127127
}
128128
pub struct Assembly {
129-
pub superCombinators: Vec<SuperCombinator>,
129+
pub super_combinators: Vec<SuperCombinator>,
130130
pub instance_dictionaries: Vec<Vec<usize>>,
131131
pub classes: Vec<Class<Id>>,
132132
pub instances: Vec<(Vec<Constraint<Name>>, Type)>,
@@ -151,7 +151,7 @@ impl Globals for Assembly {
151151
}
152152

153153
let mut index = 0;
154-
for sc in self.superCombinators.iter() {
154+
for sc in self.super_combinators.iter() {
155155
if name == sc.name {
156156
if sc.typ.constraints.len() > 0 {
157157
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<
215215

216216
fn find_constructor(module: &Module<Id>, name: Name) -> Option<(u16, u16)> {
217217

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() {
220220
if name == ctor.name {
221221
return Some((ctor.tag as u16, ctor.arity as u16));
222222
}
@@ -279,7 +279,7 @@ impl Types for Module<Id> {
279279
impl Types for Assembly {
280280
///Lookup a type
281281
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() {
283283
if sc.name == *name {
284284
return Some(&sc.typ);
285285
}
@@ -377,7 +377,7 @@ enum ArgList<'a> {
377377
pub struct Compiler<'a> {
378378
///Hashmap containging class names mapped to the functions it contains
379379
pub instance_dictionaries: Vec<(Vec<(Name, Type)>, Vec<usize>)>,
380-
pub stackSize : usize,
380+
pub stack_size : usize,
381381
///Array of all the assemblies which can be used to lookup functions in
382382
pub assemblies: Vec<&'a Assembly>,
383383
module: Option<&'a Module<Id>>,
@@ -399,7 +399,7 @@ impl <'a> Compiler<'a> {
399399
variables.insert(Name { name: intern(name), uid: 0 }, Var::Primitive(1, instruction));
400400
}
401401
Compiler { instance_dictionaries: Vec::new(),
402-
stackSize : 0, assemblies: Vec::new(),
402+
stack_size : 0, assemblies: Vec::new(),
403403
module: None,
404404
variables: variables,
405405
context: Vec::new()
@@ -408,7 +408,7 @@ impl <'a> Compiler<'a> {
408408

409409
pub fn compile_module(&mut self, module : &'a Module<Id>) -> Assembly {
410410
self.module = Some(module);
411-
let mut superCombinators = Vec::new();
411+
let mut super_combinators = Vec::new();
412412
let mut instance_dictionaries = Vec::new();
413413
let mut data_definitions = Vec::new();
414414

@@ -425,7 +425,7 @@ impl <'a> Compiler<'a> {
425425

426426
for bind in bindings {
427427
let sc = self.compile_binding(bind);
428-
superCombinators.push(sc);
428+
super_combinators.push(sc);
429429
}
430430

431431

@@ -434,9 +434,9 @@ impl <'a> Compiler<'a> {
434434
}
435435
self.module = None;
436436
Assembly {
437-
superCombinators: superCombinators,
437+
super_combinators: super_combinators,
438438
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()),
440440
classes: module.classes.clone(),
441441
instances: module.instances.iter()
442442
.map(|x| (x.constraints.clone(), Type::new_op(x.classname.name, vec![x.typ.clone()])))
@@ -496,7 +496,7 @@ impl <'a> Compiler<'a> {
496496
let n = self.assemblies.len();
497497
let offset = if n > 0 {
498498
let assembly = self.assemblies[n - 1];
499-
assembly.offset + assembly.superCombinators.len()
499+
assembly.offset + assembly.super_combinators.len()
500500
}
501501
else {
502502
0
@@ -566,18 +566,18 @@ impl <'a> Compiler<'a> {
566566
}
567567

568568
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;
571571
}
572572
fn new_var_at(&mut self, identifier : Name, index: usize) {
573573
self.variables.insert(identifier, Var::Stack(index));
574574
}
575575

576576
fn scope(&mut self, f: &mut FnMut(&mut Compiler)) {
577577
self.variables.enter_scope();
578-
let stackSize = self.stackSize;
578+
let stack_size = self.stack_size;
579579
f(self);
580-
self.stackSize = stackSize;
580+
self.stack_size = stack_size;
581581
self.variables.exit_scope();
582582
}
583583

@@ -597,12 +597,12 @@ impl <'a> Compiler<'a> {
597597
instructions.push(PushFloat(i as f64));
598598
}
599599
else {
600-
let fromInteger = Identifier(Id {
600+
let from_integer = Identifier(Id {
601601
name: Name { name: intern("fromInteger"), uid: 0 },
602602
typ: qualified(vec![], function_type_(int_type(), literal.typ.clone())),
603603
});
604604
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);
606606
self.compile(&apply, instructions, strict);
607607
}
608608
}
@@ -611,15 +611,15 @@ impl <'a> Compiler<'a> {
611611
instructions.push(PushFloat(f));
612612
}
613613
else {
614-
let fromRational = Identifier(Id {
614+
let from_rational = Identifier(Id {
615615
name: Name { name: intern("fromRational"), uid: 0 },
616616
typ: qualified(vec![], function_type_(double_type(), literal.typ.clone())),
617617
});
618618
let number = Literal(LiteralData {
619619
typ: double_type(),
620620
value: Fractional(f)
621621
});
622-
let apply = Apply(box fromRational, box number);
622+
let apply = Apply(box from_rational, box number);
623623
self.compile(&apply, instructions, strict);
624624
}
625625
}
@@ -642,17 +642,17 @@ impl <'a> Compiler<'a> {
642642
this.new_stack_var(bind.name.name.clone());
643643
//Workaround since this compiles non-recursive bindings
644644
//The stack is not actually increased until after the binding is compiled
645-
this.stackSize -= 1;
645+
this.stack_size -= 1;
646646
this.compile(&bind.expression, instructions, false);
647-
this.stackSize += 1;
647+
this.stack_size += 1;
648648
}
649649
this.compile(&**body, instructions, strict);
650650
instructions.push(Slide(bindings.len()));
651651
});
652652
}
653653
&Case(ref body, ref alternatives) => {
654654
self.compile(&**body, instructions, true);
655-
self.stackSize += 1;
655+
self.stack_size += 1;
656656
//Dummy variable for the case expression
657657
//Storage for all the jumps that should go to the end of the case expression
658658
let mut end_branches = Vec::new();
@@ -662,7 +662,7 @@ impl <'a> Compiler<'a> {
662662
self.scope(&mut |this| {
663663
let pattern_start = instructions.len() as isize;
664664
let mut branches = Vec::new();
665-
let i = this.stackSize - 1;
665+
let i = this.stack_size - 1;
666666
let stack_increase = this.compile_pattern(&alt.pattern, &mut branches, instructions, i);
667667
let pattern_end = instructions.len() as isize;
668668
this.compile(&alt.expression, instructions, strict);
@@ -773,7 +773,7 @@ impl <'a> Compiler<'a> {
773773
self.compile(expr, instructions, strict);
774774
}
775775
}
776-
self.stackSize -= arg_length;
776+
self.stack_size -= arg_length;
777777
if is_function {
778778
for _ in range(0, arg_length) {
779779
instructions.push(Mkap);
@@ -790,7 +790,7 @@ impl <'a> Compiler<'a> {
790790
let i = self.compile_args(rest, instructions, strict);
791791
//The stack has increased by 1 until the function compiles and reduces it wtih Pack or Mkap
792792
self.compile(arg, instructions, strict);
793-
self.stackSize += 1;
793+
self.stack_size += 1;
794794
i + 1
795795
}
796796
ArgList::Nil => 0
@@ -1000,9 +1000,9 @@ impl <'a> Compiler<'a> {
10001000
_ => panic!("Undefined constructor {:?}", *name)
10011001
}
10021002
instructions.push(Split(patterns.len()));
1003-
self.stackSize += patterns.len();
1003+
self.stack_size += patterns.len();
10041004
for (i, p) in patterns.iter().enumerate() {
1005-
let index = self.stackSize - patterns.len() + i;
1005+
let index = self.stack_size - patterns.len() + i;
10061006
self.new_var_at(p.name.clone(), index);
10071007
}
10081008
patterns.len()
@@ -1120,7 +1120,7 @@ fn add() {
11201120
let file = "main = primIntAdd 1 2";
11211121
let assembly = compile(file);
11221122

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]);
11241124
}
11251125

11261126
#[test]
@@ -1130,16 +1130,16 @@ r"add x y = primDoubleAdd x y
11301130
main = add 2. 3.";
11311131
let assembly = compile(file);
11321132

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]);
11351135
}
11361136
#[test]
11371137
fn push_num_double() {
11381138
let file =
11391139
r"main = primDoubleAdd 2 3";
11401140
let assembly = compile(file);
11411141

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]);
11431143
}
11441144

11451145
#[test]
@@ -1149,7 +1149,7 @@ r"add x y = primIntAdd x y
11491149
main = add 2 3";
11501150
let assembly = compile(file);
11511151

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

11551155
#[test]
@@ -1158,7 +1158,7 @@ fn compile_constructor() {
11581158
r"main = primIntAdd 1 0 : []";
11591159
let assembly = compile(file);
11601160

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

11641164
#[test]
@@ -1167,7 +1167,7 @@ fn compile_tuple() {
11671167
r"test x y = (primIntAdd 0 1, x, y)";
11681168
let assembly = compile(file);
11691169

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

11731173
#[test]
@@ -1179,7 +1179,7 @@ r"main = case [primIntAdd 1 0] of
11791179
let assembly = compile(file);
11801180

11811181

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),
11831183
Push(0), CaseJump(1), Jump(14), Split(2), Push(1), Eval, Slide(2), Jump(22), Pop(2),
11841184
Push(0), CaseJump(0), Jump(22), Split(0), PushInt(2), Slide(0), Jump(22), Pop(0), Slide(1), Eval, Update(0), Unwind]);
11851185
}
@@ -1196,7 +1196,7 @@ instance Test Int where
11961196
main = test (primIntAdd 6 0)";
11971197
let assembly = compile(file);
11981198

1199-
let main = &assembly.superCombinators[0];
1199+
let main = &assembly.super_combinators[0];
12001200
assert_eq!(main.name.name, intern("main"));
12011201
assert_eq!(main.instructions, vec![PushInt(0), PushInt(6), Add, PushGlobal(1), Mkap, Eval, Update(0), Unwind]);
12021202
}
@@ -1213,7 +1213,7 @@ instance Test Int where
12131213
main x = primIntAdd (test x) 6";
12141214
let assembly = compile(file);
12151215

1216-
let main = &assembly.superCombinators[0];
1216+
let main = &assembly.super_combinators[0];
12171217
assert_eq!(main.name.name, intern("main"));
12181218
assert_eq!(main.instructions, vec![PushInt(6), Push(1), PushDictionaryMember(0), Mkap, Eval, Add, Update(0), Pop(2), Unwind]);
12191219
}
@@ -1225,8 +1225,8 @@ fn compile_prelude() {
12251225

12261226
let assembly = compile_with_type_env(&mut type_env, &[&prelude], r"main = id (primIntAdd 2 0)");
12271227

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();
12301230
assert_eq!(sc.instructions, vec![PushInt(0), PushInt(2), Add, PushGlobal(id_index), Mkap, Eval, Update(0), Unwind]);
12311231
}
12321232

@@ -1273,7 +1273,7 @@ newtype Test a = Test [a]
12731273
test = Test [1::Int]";
12741274
let assembly = compile(file);
12751275

1276-
let test = &assembly.superCombinators[0];
1276+
let test = &assembly.super_combinators[0];
12771277
assert_eq!(test.instructions, vec![Pack(0, 0), PushInt(1), Pack(1, 2), Update(0), Unwind]);
12781278
}
12791279

0 commit comments

Comments
 (0)