Run rustfmt on some files

This commit is contained in:
greg 2016-12-29 02:01:48 -08:00
parent d4d61ce5ad
commit af45004afa
2 changed files with 79 additions and 66 deletions

View File

@ -124,9 +124,7 @@ impl CodeGen for Expression {
let int_type = LLVMWrap::Int64TypeInContext(data.context);
match self {
&Variable(ref name) => {
*data.variables.get(name).unwrap()
},
&Variable(ref name) => *data.variables.get(name).unwrap(),
&BinExp(ref op, ref left, ref right) if op == "=" => {
if let Variable(ref name) = **left {
let new_value = right.codegen(data);
@ -135,7 +133,7 @@ impl CodeGen for Expression {
} else {
panic!("Bad variable assignment")
}
},
}
&BinExp(ref op, ref left, ref right) => {
let lhs = left.codegen(data);
let rhs = right.codegen(data);
@ -149,12 +147,12 @@ impl CodeGen for Expression {
};
generator(data.builder, lhs, rhs, "temp")
},
}
&Number(ref n) => {
let native_val = *n as u64;
let int_value: LLVMValueRef = LLVMWrap::ConstInt(int_type, native_val, false);
int_value
},
}
_ => unimplemented!(),
}
}

View File

@ -10,7 +10,7 @@ enum SideEffect {
}
struct Varmap {
map: HashMap<String, Expression>
map: HashMap<String, Expression>,
}
impl Varmap {
@ -37,18 +37,18 @@ pub struct Evaluator {
}
impl Evaluator {
pub fn new() -> Evaluator {
Evaluator { varmap: Varmap::new(),
Evaluator {
varmap: Varmap::new(),
funcmap: Funcmap::new(),
frames: Vec::new(),
}
}
pub fn run(&mut self, ast: AST) -> Vec<String> {
ast.into_iter().map(|astnode| {
self.reduce(astnode)
}).collect()
ast.into_iter()
.map(|astnode| self.reduce(astnode))
.collect()
}
fn add_binding(&mut self, var: String, value: Expression) {
@ -109,7 +109,7 @@ impl Evaluator {
loop {
node = self.step(node);
if !node.is_reducible() {
break
break;
}
}
@ -132,7 +132,7 @@ impl Evaluator {
for side_effect in l {
self.perform_side_effect(side_effect);
}
},
}
}
}
@ -146,12 +146,12 @@ impl Evaluator {
} else {
(ExprNode(expr), None)
}
},
}
FuncNode(func) => {
let fn_name = func.prototype.name.clone();
self.add_function(fn_name, func);
(ExprNode(Expression::Null), None)
},
}
}
}
@ -166,7 +166,7 @@ impl Evaluator {
None => (Null, None),
Some(expr) => (expr, None),
}
},
}
BinExp(op, box left, box right) => {
if right.is_reducible() {
let new = self.reduce_expr(right);
@ -179,8 +179,8 @@ impl Evaluator {
Variable(var) => {
self.add_binding(var, right);
return (Null, None); //TODO variable binding should be an effect
},
_ => ()
}
_ => (),
}
}
@ -190,14 +190,12 @@ impl Evaluator {
} else {
(self.reduce_binop(op, left, right), None) //can assume both arguments are maximally reduced
}
},
}
Call(name, mut args) => {
let mut f = true;
for arg in args.iter_mut() {
if arg.is_reducible() {
take_mut::take(arg, |arg| {
self.reduce_expr(arg).0
});
take_mut::take(arg, |arg| self.reduce_expr(arg).0);
f = false;
break;
}
@ -207,7 +205,7 @@ impl Evaluator {
} else {
(Call(name, args), None)
}
},
}
Conditional(_, _, _) => unimplemented!(),
}
}
@ -215,39 +213,56 @@ impl Evaluator {
fn reduce_binop(&mut self, op: String, left: Expression, right: Expression) -> Expression {
use parser::Expression::*;
match &op[..] {
"+" => match (left, right) {
"+" => {
match (left, right) {
(Number(l), Number(r)) => Number(l + r),
(StringLiteral(s1), StringLiteral(s2)) => StringLiteral(format!("{}{}", s1, s2)),
(StringLiteral(s1), StringLiteral(s2)) => {
StringLiteral(format!("{}{}", s1, s2))
}
_ => Null,
},
"-" => match (left, right) {
}
}
"-" => {
match (left, right) {
(Number(l), Number(r)) => Number(l - r),
_ => Null,
},
"*" => match (left, right) {
}
}
"*" => {
match (left, right) {
(Number(l), Number(r)) => Number(l * r),
_ => Null,
},
"/" => match (left, right) {
}
}
"/" => {
match (left, right) {
(Number(l), Number(r)) if r != 0.0 => Number(l / r),
_ => Null,
},
"%" => match (left, right) {
}
}
"%" => {
match (left, right) {
(Number(l), Number(r)) => Number(l % r),
_ => Null,
},
"=" => match (left, right) {
}
}
"=" => {
match (left, right) {
(Variable(var), right) => {
self.add_binding(var, right);
Null
},
}
_ => Null,
},
}
}
_ => Null,
}
}
fn reduce_call(&mut self, name: String, arguments: Vec<Expression>) -> (Expression, Option<SideEffect>) {
fn reduce_call(&mut self,
name: String,
arguments: Vec<Expression>)
-> (Expression, Option<SideEffect>) {
use parser::Expression::*;
// ugly hack for now
@ -262,11 +277,11 @@ impl Evaluator {
let function = match self.lookup_function(name) {
Some(func) => func,
None => return (Null, None)
None => return (Null, None),
};
if function.prototype.parameters.len() != arguments.len() {
return (Null, None)
return (Null, None);
}
let mut frame: Varmap = Varmap::new();