Make function binding a SideEffect
This commit is contained in:
parent
2722533efd
commit
872e9ce7ee
10
src/eval.rs
10
src/eval.rs
@ -9,6 +9,7 @@ type Reduction<T> = (T, Option<SideEffect>);
|
|||||||
enum SideEffect {
|
enum SideEffect {
|
||||||
Print(String),
|
Print(String),
|
||||||
AddBinding(String, Expression),
|
AddBinding(String, Expression),
|
||||||
|
AddFunctionBinding(Function),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EnvFrame {
|
struct EnvFrame {
|
||||||
@ -140,6 +141,9 @@ impl Evaluator {
|
|||||||
Print(s) => println!("{}", s),
|
Print(s) => println!("{}", s),
|
||||||
AddBinding(var, value) => {
|
AddBinding(var, value) => {
|
||||||
self.add_binding(var, value);
|
self.add_binding(var, value);
|
||||||
|
},
|
||||||
|
AddFunctionBinding(function) => {
|
||||||
|
self.add_function(function.prototype.name.clone(), function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,10 +160,8 @@ impl Evaluator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FuncDefNode(func) => {
|
FuncDefNode(func) => {
|
||||||
let fn_name = func.prototype.name.clone();
|
let binding = Some(SideEffect::AddFunctionBinding(func.clone()));
|
||||||
// TODO get rid of this clone
|
(ExprNode(Expression::Lambda(func)), binding)
|
||||||
self.add_function(fn_name, func.clone());
|
|
||||||
(ExprNode(Expression::Lambda(func)), None)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user