skele of eval function

This commit is contained in:
Aidan 2021-03-16 22:43:46 -07:00
parent 3434a49cc1
commit 306ec6af09
No known key found for this signature in database
GPG key ID: 327711E983899316

View file

@ -17,7 +17,7 @@
use std::rc::Rc; use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use crate::segment::{Ast}; use crate::segment::{Ast, Ctr};
use crate::func::FTable; use crate::func::FTable;
use crate::vars::VTable; use crate::vars::VTable;
@ -26,10 +26,45 @@ use crate::vars::VTable;
* representing the simplest possible form of the input * representing the simplest possible form of the input
*/ */
pub fn eval( pub fn eval(
_ast: Ast, ast: Ast,
_vars: Rc<RefCell<VTable>>, vars: Rc<RefCell<VTable>>,
_funcs: Rc<RefCell<FTable>>, funcs: Rc<RefCell<FTable>>,
_sym_loose: bool sym_loose: bool
) -> Result<Ast, String> { ) -> Result<Ast, String> {
Err("Unimplemented".to_string()) eval_inner(ast, vars, funcs, sym_loose, true)
}
fn eval_inner(
ast: Ast,
vars: Rc<RefCell<VTable>>,
funcs: Rc<RefCell<FTable>>,
sym_loose: bool,
first_item: bool
) -> Result<Ast, String> {
/* 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<RefCell<VTable>>,
funcs: Rc<RefCell<FTable>>,
sym_loose: bool,
first_item: bool
) -> Result<Ctr, String> {
/* 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
} }