Significant improvement to eval routine and tests

This commit is contained in:
Aidan 2021-06-22 00:50:37 -07:00
parent 9b981921b4
commit df5cb47cb4
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 397 additions and 11 deletions

View file

@ -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)
}
}
}