in progress commit

This commit is contained in:
Aidan 2021-05-25 09:37:23 -07:00
parent 33f2e1eb16
commit 4fa8d84cec
No known key found for this signature in database
GPG key ID: 327711E983899316

View file

@ -18,7 +18,7 @@
use std::rc::Rc;
use std::cell::RefCell;
use crate::segment::{Ast, Ctr};
use crate::func::FTable;
use crate::func::{FTable, func_call};
use crate::vars::VTable;
/* iterates over a syntax tree
@ -87,7 +87,8 @@ fn process_ctr(
vars: Rc<RefCell<VTable>>,
funcs: Rc<RefCell<FTable>>,
sym_loose: bool,
first_item: bool
first_item: bool,
rest: Ast
) -> Result<Ctr, String> {
/* LOGIC:
* 1. if symbol, unwrap (DEEP COPY)
@ -101,12 +102,15 @@ fn process_ctr(
Symbol(token) => {
let mut tok = token;
if let Some(s) = vt.borrow().get(token) {
// perhaps allow variable expansion here
// as a primitive stand in for function aliasing
if first_item && let String(t) = s {
// is function, or variable alias?
if first_item && let Symbol(t) = s {
if let Some(f) = ft.borrow().get(t) {
tok = t;
// is a basic value.
} else {
// TODO: DEEP COPY. return
return Ok((*s).clone())
}
// else call function
@ -115,7 +119,10 @@ fn process_ctr(
}
if first_item && let Some(f) = ft.borrow().get(tok) {
// TODO: call function. set return
match func_call(f, rest, vars.clone(), funcs.clone()) {
Ok(a) => Ok(Ctr::Seg(a.borrow().clone())),
Err(s) => Err(s)
}
}
},
Seg(tree) => eval_inner(tree, vars, funcs, sym_loose, first_item),