WIP commit to re-add and refactor config, repl, and library code

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-02-27 17:30:49 -08:00
parent 93a1e06a53
commit ae365ad63c
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
10 changed files with 758 additions and 67 deletions

View file

@ -19,31 +19,36 @@ use crate::segment::{Ctr, Seg, Type};
use crate::eval::eval;
use crate::sym::{SymTable, Symbol, ValueType, Args, UserFn};
use std::env;
use std::rc::Rc;
/*
// the stdlib var export function with env_sync on
static LIB_STORE_ENV: Symbol = Symbol {
name: String::from("export"),
args: Args::Lazy(2),
value: ValueType::Internal(Box::new( |ast: &Seg| -> Ctr {
_store_callback(ast, true)
},
)),
has_undefined_symbols: false,
};
fn store_stdlib(env: bool, syms: &mut SymTable) -> Result<(), String> {
syms.insert("def".to_string(), Symbol {
name: String::from("export"),
args: Args::Lazy(2),
conditional_branches: false,
value: ValueType::Internal(Rc::new( move |ast: &Seg, syms: &mut SymTable| -> Ctr {
_store_callback(ast, syms, env)
},
)),
});
// the stdlib var export function with env_sync off
pub static LIB_STORE_NO_ENV: Symbol = Symbol {
name: String::from("export"),
args: Args::Lazy(2),
value: ValueType::Internal(Box::new( |ast: &Seg| -> Ctr {
_store_callback(ast, false)
},
)),
has_undefined_symbols: false,
};*/
syms.insert("append".to_string(), Symbol {
name: String::from("append"),
args: Args::Infinite,
conditional_branches: false,
value: ValueType::Internal(Rc::new(_append_callback)),
});
Ok(())
}
fn _append_callback (_ast: &Seg, _syms: &mut SymTable) -> Ctr {
// if car is a list, append cdr
// otherwise create a list out of all arguments
todo!()
}
// TODO : declare function if arg list is long enough
fn _store_callback (ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Ctr {
let is_var = ast.len() == 2;
if let Ctr::Symbol(ref identifier) = *ast.car {