add more unit tests for function calls
This commit is contained in:
parent
a6abc993a5
commit
9b981921b4
4 changed files with 339 additions and 19 deletions
24
src/func.rs
24
src/func.rs
|
|
@ -32,9 +32,9 @@ pub struct ExternalOperation {
|
|||
// TODO: Intermediate evaluation to simplify branches with no argument in them
|
||||
// Simplified branches must not have side effects.
|
||||
// TODO: Apply Memoization?
|
||||
ast: Ast,
|
||||
pub ast: Ast,
|
||||
// list of argument string tokens
|
||||
arg_syms: Vec<String>
|
||||
pub arg_syms: Vec<String>
|
||||
}
|
||||
|
||||
/* A stored function may either be a pointer to a function
|
||||
|
|
@ -94,11 +94,16 @@ pub fn func_call(
|
|||
|
||||
match &called_func.args {
|
||||
Args::Lazy(num) => {
|
||||
if *num < 0 {
|
||||
}
|
||||
|
||||
if !(*num == (list_len(n_args.clone()) as i128 - 1)) {
|
||||
return Err(format!("expected {} args in call to {}", num, called_func.name))
|
||||
let called_arg_count = list_len(n_args.clone()) as i128;
|
||||
if *num > -1 && (*num != called_arg_count) {
|
||||
return Err(
|
||||
format!(
|
||||
"expected {} args in call to {}. Got {}.",
|
||||
num,
|
||||
called_func.name,
|
||||
called_arg_count
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -151,10 +156,13 @@ pub fn func_call(
|
|||
match &called_func.function {
|
||||
Operation::Internal(f) => Ok((f)(n_args, vars, funcs)),
|
||||
Operation::External(f) => {
|
||||
|
||||
for n in 0..f.arg_syms.len() {
|
||||
let iter_arg = list_idx(n_args.clone(), n as u128);
|
||||
|
||||
vars.borrow_mut().insert(
|
||||
f.arg_syms[n].clone(),
|
||||
Rc::new(list_idx(n_args.clone(), n as u128))
|
||||
Rc::new(iter_arg)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue