Fixed evaluation of function calls
This bit still isn't quite small-step but maybe that's okay for functions
This commit is contained in:
parent
ed9d1312d1
commit
9cc9c5977d
16
main.schala
16
main.schala
@ -1,7 +1,17 @@
|
||||
|
||||
fn add(a, b)
|
||||
a + b
|
||||
end
|
||||
|
||||
fn subtract(a, b)
|
||||
a - b
|
||||
end
|
||||
|
||||
fn main()
|
||||
a = 4
|
||||
b = 20
|
||||
a + b
|
||||
first_value = add(20, 20)
|
||||
second_value = subtract(700, 650)
|
||||
first_value + second_value
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
|
11
src/eval.rs
11
src/eval.rs
@ -8,7 +8,6 @@ type Reduction<T> = (T, Option<SideEffect>);
|
||||
#[derive(Debug)]
|
||||
enum SideEffect {
|
||||
Print(String),
|
||||
Bundle(Vec<SideEffect>),
|
||||
AddBinding(String, Expression),
|
||||
}
|
||||
|
||||
@ -128,11 +127,6 @@ impl Evaluator {
|
||||
use self::SideEffect::*;
|
||||
match side_effect {
|
||||
Print(s) => println!("{}", s),
|
||||
Bundle(l) => {
|
||||
for side_effect in l {
|
||||
self.perform_side_effect(side_effect);
|
||||
}
|
||||
}
|
||||
AddBinding(var, value) => {
|
||||
self.add_binding(var, value);
|
||||
}
|
||||
@ -285,19 +279,18 @@ impl Evaluator {
|
||||
|
||||
self.frames.push(frame);
|
||||
let mut retval = Null;
|
||||
let mut side_effects = Vec::new();
|
||||
for expr in function.body.iter() {
|
||||
retval = expr.clone();
|
||||
while retval.is_reducible() {
|
||||
let r = self.reduce_expr(retval);
|
||||
retval = r.0;
|
||||
if let Some(s) = r.1 {
|
||||
side_effects.push(s);
|
||||
self.perform_side_effect(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.frames.pop();
|
||||
(retval, Some(SideEffect::Bundle(side_effects)))
|
||||
(retval, None)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user