Fully fledged lambdas, along with efficiency tweaks across the ast

This commit is contained in:
Ava Apples Affine 2023-03-13 15:02:19 -07:00
parent b0bd369c1d
commit 8efa1dbaad
Signed by: affine
GPG key ID: 3A4645B8CF806069
10 changed files with 264 additions and 70 deletions

View file

@ -16,13 +16,14 @@
*/
use crate::segment::{Ctr, Seg};
use crate::sym::SymTable;
use crate::sym::{SymTable, call_lambda};
/* iterates over a syntax tree
* returns a NEW LIST of values
* representing the simplest possible form of the input
*/
pub fn eval(ast: &Seg, syms: &mut SymTable) -> Result<Box<Ctr>, String> {
println!("E: {}", ast);
// data to return
let mut ret = Box::from(Ctr::None);
let mut first = true;
@ -39,7 +40,17 @@ pub fn eval(ast: &Seg, syms: &mut SymTable) -> Result<Box<Ctr>, String> {
let mut none = false;
while !none {
match &**arg_car {
Ctr::Seg(ref inner) => car = eval(inner, syms)?,
Ctr::Seg(ref inner) => {
let interm = eval(inner, syms)?;
if let Ctr::Lambda(ref l) = *interm {
match call_lambda(l, arg_cdr, syms) {
Ok(s) => return Ok(s.clone()),
Err(s) => return Err(format!("err in call to lambda: {}", s)),
}
} else {
car = interm;
}
},
Ctr::Symbol(ref tok) => {
let outer_scope_seg_holder: Seg;