Significant improvement to eval routine and tests
This commit is contained in:
parent
9b981921b4
commit
df5cb47cb4
4 changed files with 397 additions and 11 deletions
35
src/func.rs
35
src/func.rs
|
|
@ -81,7 +81,13 @@ pub fn func_call(
|
|||
let mut n_args: Ast = args.clone();
|
||||
if !called_func.eval_lazy {
|
||||
match eval(args, vars.clone(), funcs.clone(), called_func.loose_syms) {
|
||||
Ok(rc_seg) => n_args = rc_seg.clone(),
|
||||
Ok(rc_seg) => {
|
||||
if let Ctr::Seg(ast) = rc_seg {
|
||||
n_args = ast
|
||||
} else {
|
||||
return Err("Panicking: eval returned not a list for function args.".to_string())
|
||||
}
|
||||
},
|
||||
Err(s) => return Err(
|
||||
format!(
|
||||
"error evaluating args to {}: {}",
|
||||
|
|
@ -166,15 +172,32 @@ pub fn func_call(
|
|||
);
|
||||
}
|
||||
|
||||
let result = eval(f.ast.clone(), vars.clone(), funcs, called_func.loose_syms);
|
||||
let mut result = Ctr::None;
|
||||
let mut iterate = f.ast.clone();
|
||||
loop {
|
||||
if let Ctr::Seg(ast) = iterate.borrow().clone().car {
|
||||
match eval(ast, vars.clone(), funcs.clone(), called_func.loose_syms) {
|
||||
Ok(ctr) => {
|
||||
if let Ctr::Seg(ast) = ctr {
|
||||
result = ast.borrow().clone().car;
|
||||
}
|
||||
},
|
||||
Err(e) => return Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
match iterate.clone().borrow().clone().cdr {
|
||||
Ctr::Seg(next) => iterate = next.clone(),
|
||||
Ctr::None => break,
|
||||
_ => panic!("function body not in standard form!")
|
||||
}
|
||||
}
|
||||
|
||||
for n in 0..f.arg_syms.len() {
|
||||
vars.borrow_mut().remove(&f.arg_syms[n].clone());
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(r) => Ok(r.borrow().clone().car),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
return Ok(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue