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

Commit 587092f

Browse files
committed
Fixed (duplicated) imports, formatting strings, removed FromVec
1 parent f5829cc commit 587092f

17 files changed

+299
-332
lines changed

compiler.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use interner::*;
22
use core::*;
3-
use types::{int_type, double_type, function_type, function_type_, Qualified, qualified};
3+
use types::{int_type, double_type, function_type, function_type_, qualified};
44
use typecheck::{Types, DataTypes, TypeEnvironment, find_specialized_instances};
55
use scoped_map::ScopedMap;
66
use std::iter::range_step;
7-
use std::vec::FromVec;
87
use std::io::IoResult;
98

109
use core::translate::{translate_module, translate_modules};
@@ -259,11 +258,11 @@ impl Types for Module<Id> {
259258
for instance in self.instances.iter() {
260259
let y = match extract_applied_type(&instance.typ) {
261260
&TypeConstructor(ref x) => x,
262-
_ => fail!()
261+
_ => panic!()
263262
};
264263
let z = match extract_applied_type(typ) {
265264
&TypeConstructor(ref x) => x,
266-
_ => fail!()
265+
_ => panic!()
267266
};
268267
if classname == instance.classname && y.name == z.name {
269268
return Some((instance.constraints.as_slice(), &instance.typ));
@@ -318,15 +317,15 @@ impl Types for Assembly {
318317
&TypeApplication(ref op, ref t) => {
319318
let x = match extract_applied_type(*op) {
320319
&TypeConstructor(ref x) => x,
321-
_ => fail!()
320+
_ => panic!()
322321
};
323322
let y = match extract_applied_type(*t) {
324323
&TypeConstructor(ref x) => x,
325-
_ => fail!()
324+
_ => panic!()
326325
};
327326
let z = match extract_applied_type(typ) {
328327
&TypeConstructor(ref x) => x,
329-
_ => fail!()
328+
_ => panic!()
330329
};
331330
if classname.name == x.name && y.name == z.name {
332331
let o : &Type = *t;
@@ -439,16 +438,15 @@ impl <'a> Compiler<'a> {
439438
}
440439
self.module = None;
441440
Assembly {
442-
superCombinators: FromVec::from_vec(superCombinators),
443-
instance_dictionaries: FromVec::from_vec(instance_dictionaries),
441+
superCombinators: superCombinators,
442+
instance_dictionaries: instance_dictionaries,
444443
offset: self.assemblies.iter().flat_map(|assembly| assembly.superCombinators.iter()).len(),
445444
classes: module.classes.clone(),
446-
instances: FromVec::<(Vec<Constraint<Name>>, Type)>::from_vec(
447-
module.instances.iter()
445+
instances: module.instances.iter()
448446
.map(|x| (x.constraints.clone(), Type::new_op(x.classname.name, box [x.typ.clone()])))
449447
.collect()
450-
),
451-
data_definitions: FromVec::from_vec(data_definitions)
448+
,
449+
data_definitions: data_definitions
452450
}
453451
}
454452

@@ -476,7 +474,7 @@ impl <'a> Compiler<'a> {
476474
typ: bind.name.typ.clone(),
477475
name: bind.name.name,
478476
arity: arity,
479-
instructions: FromVec::from_vec(instructions)
477+
instructions: instructions
480478
}
481479
}
482480

@@ -699,7 +697,7 @@ impl <'a> Compiler<'a> {
699697
instructions.push(Eval);
700698
}
701699
}
702-
&Lambda(_, _) => fail!("Error: Found non-lifted lambda when compiling expression")
700+
&Lambda(_, _) => panic!("Error: Found non-lifted lambda when compiling expression")
703701
}
704702
}
705703
fn compile_apply<'a>(&mut self, expr: &Expr<Id>, args: ArgList<'a>, instructions: &mut Vec<Instruction>, strict: bool) {
@@ -719,7 +717,7 @@ impl <'a> Compiler<'a> {
719717
//might be created which is returned here and added to the assembly
720718
let mut is_primitive = false;
721719
let var = self.find(name.name)
722-
.unwrap_or_else(|| fail!("Error: Undefined variable {}", *name));
720+
.unwrap_or_else(|| panic!("Error: Undefined variable {}", *name));
723721
match var {
724722
PrimitiveVariable(..) => is_primitive = true,
725723
_ => ()
@@ -748,7 +746,7 @@ impl <'a> Compiler<'a> {
748746
instructions.push(instruction);
749747
}
750748
else {
751-
fail!("Expected {} arguments for {}, got {}", num_args, name, arg_length)
749+
panic!("Expected {} arguments for {}, got {}", num_args, name, arg_length)
752750
}
753751
is_function = false;
754752
}
@@ -765,7 +763,7 @@ impl <'a> Compiler<'a> {
765763
GlobalVariable(index) => {
766764
instructions.push(PushGlobal(index));
767765
}
768-
_ => fail!()
766+
_ => panic!()
769767
}
770768
}
771769
}
@@ -820,7 +818,7 @@ impl <'a> Compiler<'a> {
820818
instructions.push(PushGlobal(index));
821819
instructions.push(Mkap);
822820
}
823-
_ => fail!("Unregistered instance function {}", instance_fn_name)
821+
_ => panic!("Unregistered instance function {}", instance_fn_name)
824822
}
825823
}
826824
None => {
@@ -900,14 +898,14 @@ impl <'a> Compiler<'a> {
900898
debug!("No dict for {}", var);
901899
}
902900
}
903-
_ => fail!("Did not expect generic")
901+
_ => panic!("Did not expect generic")
904902
}
905903
}
906904

907905
///Lookup which index in the instance dictionary that holds the function called 'name'
908906
fn push_dictionary_member(&self, constraints: &[Constraint<Name>], name: Name) -> Option<uint> {
909907
if constraints.len() == 0 {
910-
fail!("Attempted to push dictionary member '{}' with no constraints", name)
908+
panic!("Attempted to push dictionary member '{}' with no constraints", name)
911909
}
912910
let mut ii = 0;
913911
for c in constraints.iter() {
@@ -951,11 +949,11 @@ impl <'a> Compiler<'a> {
951949
}
952950

953951
if constraints.len() == 0 {
954-
fail!("Error: Attempted to compile dictionary with no constraints at <unknown>");
952+
panic!("Error: Attempted to compile dictionary with no constraints at <unknown>");
955953
}
956954
let mut function_indexes = Vec::new();
957955
self.add_class(constraints, &mut function_indexes);
958-
self.instance_dictionaries.push((constraints.to_owned(), FromVec::from_vec(function_indexes)));
956+
self.instance_dictionaries.push((constraints.to_owned(), function_indexes));
959957
dict_len
960958
}
961959

@@ -973,7 +971,7 @@ impl <'a> Compiler<'a> {
973971
for decl in declarations.iter() {
974972
let x = match extract_applied_type(typ) {
975973
&TypeConstructor(ref x) => x,
976-
_ => fail!("{}", typ)
974+
_ => panic!("{}", typ)
977975
};
978976
let mut b = String::from_str("#");
979977
b.push_str(x.name.as_slice());
@@ -987,7 +985,7 @@ impl <'a> Compiler<'a> {
987985
Some(ConstraintVariable(index, _, _)) => {
988986
function_indexes.push(index as uint);//TODO this is not really correct since this function requires a dictionary
989987
}
990-
var => fail!("Did not find function {} {}", name, var)
988+
var => panic!("Did not find function {} {}", name, var)
991989
}
992990
}
993991
None
@@ -1009,7 +1007,7 @@ impl <'a> Compiler<'a> {
10091007
branches.push(instructions.len());
10101008
instructions.push(Jump(0));
10111009
}
1012-
_ => fail!("Undefined constructor {}", *name)
1010+
_ => panic!("Undefined constructor {}", *name)
10131011
}
10141012
instructions.push(Split(patterns.len()));
10151013
self.stackSize += patterns.len();

0 commit comments

Comments
 (0)