finally figure out how to hold closures

This commit is contained in:
Aidan Hahn 2022-01-16 22:01:42 -08:00
parent 69f31db23b
commit f805290a4b
No known key found for this signature in database
GPG key ID: 327711E983899316
8 changed files with 98 additions and 89 deletions

View file

@ -26,7 +26,7 @@ use crate::eval::eval;
pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
// Standardized function signature for stdlib functions
pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
//pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
pub struct ExternalOperation {
// Un-evaluated abstract syntax tree
// TODO: Intermediate evaluation to simplify branches with no argument in them
@ -41,7 +41,7 @@ pub struct ExternalOperation {
* or a syntax tree to eval with the arguments
*/
pub enum Operation {
Internal(InternalOperation),
Internal(Box<dyn Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>)->Ctr>),
External(ExternalOperation)
}
@ -160,9 +160,10 @@ pub fn func_call(
}
match &called_func.function {
Operation::Internal(f) => Ok((f)(n_args, vars, funcs)),
Operation::Internal(f) => {
return 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);