From 306ec6af0968c8cde4d115d6a24a60ab82c66a34 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 16 Mar 2021 22:43:46 -0700 Subject: [PATCH] skele of eval function --- src/eval.rs | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/eval.rs b/src/eval.rs index 8769087..f758659 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}; +use crate::segment::{Ast, Ctr}; use crate::func::FTable; use crate::vars::VTable; @@ -26,10 +26,45 @@ use crate::vars::VTable; * representing the simplest possible form of the input */ pub fn eval( - _ast: Ast, - _vars: Rc>, - _funcs: Rc>, - _sym_loose: bool + ast: Ast, + vars: Rc>, + funcs: Rc>, + sym_loose: bool ) -> Result { - Err("Unimplemented".to_string()) + eval_inner(ast, vars, funcs, sym_loose, true) +} + +fn eval_inner( + ast: Ast, + vars: Rc>, + funcs: Rc>, + sym_loose: bool, + first_item: bool +) -> Result { + /* TODO: + * 1. make new ast + * 2. call process_ctr on ast.car + * 3. set new.car to result + * 3. if cdr is an AST + * - set first_item to false + * - set new.cdr to recur of this + * 4. else call process_ctr on cdr + * (and set new.cdr to result) + * 5. return new ast + */ +} + +fn process_ctr( + ctr: Ctr, + vars: Rc>, + funcs: Rc>, + sym_loose: bool, + first_item: bool +) -> Result { + /* TODO: + * 1. if symbol, unwrap (DEEP COPY) + * 2. if first_item and symbol, call function? + * (else: return var copy) + * 3. if list return result of eval() + * 4. finally, return a clone (shallow copy) of datum }