Fully fledged lambdas, along with efficiency tweaks across the ast
This commit is contained in:
parent
b0bd369c1d
commit
8efa1dbaad
10 changed files with 264 additions and 70 deletions
15
src/eval.rs
15
src/eval.rs
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue