Small-step function arg evaluation
This commit is contained in:
parent
907af38f44
commit
a01b6c874e
@ -7,4 +7,5 @@ authors = ["greg <greg.shuflin@protonmail.com>"]
|
||||
|
||||
simplerepl = { path = "../simplerepl" }
|
||||
llvm-sys = "*"
|
||||
take_mut = "0.1.3"
|
||||
|
||||
|
23
src/eval.rs
23
src/eval.rs
@ -1,3 +1,5 @@
|
||||
extern crate take_mut;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use parser::{AST, ASTNode, Expression, Function};
|
||||
|
||||
@ -189,11 +191,22 @@ impl Evaluator {
|
||||
(self.reduce_binop(op, left, right), None) //can assume both arguments are maximally reduced
|
||||
}
|
||||
},
|
||||
Call(name, args) => {
|
||||
let reduced_args: Vec<Expression> = args.into_iter().map(|arg| {
|
||||
self.reduce_expr(arg).0
|
||||
}).collect();
|
||||
self.reduce_call(name, reduced_args)
|
||||
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
|
||||
});
|
||||
f = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if f {
|
||||
self.reduce_call(name, args)
|
||||
} else {
|
||||
(Call(name, args), None)
|
||||
}
|
||||
},
|
||||
Conditional(_,_,_) => unimplemented!(),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user