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" }
|
simplerepl = { path = "../simplerepl" }
|
||||||
llvm-sys = "*"
|
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 std::collections::HashMap;
|
||||||
use parser::{AST, ASTNode, Expression, Function};
|
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
|
(self.reduce_binop(op, left, right), None) //can assume both arguments are maximally reduced
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Call(name, args) => {
|
Call(name, mut args) => {
|
||||||
let reduced_args: Vec<Expression> = args.into_iter().map(|arg| {
|
let mut f = true;
|
||||||
self.reduce_expr(arg).0
|
for arg in args.iter_mut() {
|
||||||
}).collect();
|
if arg.is_reducible() {
|
||||||
self.reduce_call(name, reduced_args)
|
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!(),
|
Conditional(_,_,_) => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user