diff --git a/src/eval.rs b/src/eval.rs index 1125aa4..5b37a07 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -17,7 +17,7 @@ use std::rc::Rc; use std::cell::RefCell; -use crate::segment::{Ast, Ctr}; +use crate::segment::{Ast, Ctr, new_ast}; use crate::func::{FTable, func_call}; use crate::vars::VTable; @@ -50,21 +50,19 @@ fn eval_inner( * (and set new.cdr to result) * 5. return new ast */ - let ret: Ast; - let mret = ret.clone().borrow_mut(); - let ast_inner = ast.clone().borrow_mut(); + let ret = new_ast(Ctr::None, Ctr::None); match process_ctr( - ast_inner.car, + ast.borrow().clone().car, vars.clone(), funcs.clone(), sym_loose, first_item, true, - mret.cdr + ret.borrow().clone().cdr ) { Ok(ctr) => { - mret.car = ctr; + ret.borrow_mut().car = ctr; }, Err(err) => { return Err(err) @@ -72,7 +70,7 @@ fn eval_inner( } match process_ctr( - ast_inner.cdr, + ast.borrow().clone().cdr, vars.clone(), funcs.clone(), sym_loose, @@ -81,7 +79,7 @@ fn eval_inner( Ctr::None ) { Ok(ctr) => { - mret.cdr = ctr; + ret.borrow_mut().cdr = ctr; }, Err(err) => { return Err(err) @@ -108,23 +106,23 @@ fn process_ctr( * 4. finally, return a clone (shallow copy) of datum */ - match ctr { + match ctr.clone() { Ctr::Symbol(token) => { let mut tok = token; if let Some(s) = vars.borrow().get(&tok) { // is function, or variable alias? if first_item { - if let Ctr::Symbol(t) = *s.clone() { - if let Some(f) = funcs.borrow().get(&t) { + if let Ctr::Symbol(t) = &*(s.clone()) { + if let Some(_f) = funcs.borrow().get(t) { // leave this set for the function call case below - tok = t; + tok = t.clone(); } } // is a basic value. } else { - return Ok(*s.clone()) + return Ok((*s.clone()).clone()) } // variable not found case @@ -136,7 +134,7 @@ fn process_ctr( if first_item { if let Some(f) = funcs.borrow().get(&tok) { if let Ctr::Seg(args) = rest { - match func_call(*f, args, vars.clone(), funcs.clone()) { + match func_call(f.clone(), args, vars.clone(), funcs.clone()) { Ok(a) => return Ok(a.clone()), Err(s) => return Err(s) } diff --git a/src/func.rs b/src/func.rs index 147b727..be1b7f4 100644 --- a/src/func.rs +++ b/src/func.rs @@ -152,7 +152,7 @@ pub fn func_call( Operation::Internal(f) => Ok((f)(n_args, vars, funcs)), Operation::External(f) => { for n in 0..f.arg_syms.len() { - vars.borrow().insert( + vars.borrow_mut().insert( f.arg_syms[n].clone(), Rc::new(list_idx(n_args.clone(), n as u128)) ); @@ -160,11 +160,11 @@ pub fn func_call( let result = eval(f.ast.clone(), vars.clone(), funcs, called_func.loose_syms); for n in 0..f.arg_syms.len() { - vars.borrow().remove(&f.arg_syms[n].clone()); + vars.borrow_mut().remove(&f.arg_syms[n].clone()); } match result { - Ok(r) => Ok(r.borrow().car), + Ok(r) => Ok(r.borrow().clone().car), Err(e) => Err(e) } } diff --git a/tests/test_func.rs b/tests/test_func.rs index 39a3470..e03b91e 100644 --- a/tests/test_func.rs +++ b/tests/test_func.rs @@ -13,7 +13,7 @@ mod func_tests { eval_lazy: true, args: Args::Strict(vec![Type::Bool]), function: Operation::Internal( - |a: Ast, _b: Rc>, _c: Rc>| -> Ast { + |a: Ast, _b: Rc>, _c: Rc>| -> Ctr { let inner = a.borrow(); let mut is_bool = false; if let Ctr::Bool(_) = &inner.car {