(un)finished env integration logic

This commit is contained in:
Aidan Hahn 2021-11-25 21:24:04 -08:00
parent 5aa2b27343
commit a967ac5c3e
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 32 additions and 27 deletions

View file

@ -26,7 +26,7 @@ use crate::eval::eval;
pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
// Standardized function signature for stdlib functions
pub type InternalOperation = fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
pub type InternalOperation = impl Fn(Ast, Rc<RefCell<VTable>>, Rc<RefCell<FTable>>) -> Ctr;
pub struct ExternalOperation {
// Un-evaluated abstract syntax tree
// TODO: Intermediate evaluation to simplify branches with no argument in them

View file

@ -19,7 +19,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::collections::HashMap;
use std::env;
use crate::segment::{Ctr, Ast};
use crate::segment::{Ctr, Ast, ast_to_string};
use crate::eval::eval;
use crate::func::{Function, Operation, Args, FTable};
/* Mapping between a string token and a tree of Segments
@ -52,40 +52,45 @@ pub fn get_export(env_cfg: bool) -> Function {
Ctr::Symbol(identifier) => {
match &inner.cdr {
Ctr::Seg(tree) => {
if let Ok(seg) = eval(tree.clone(), b.clone(), c.clone(), false) {
match seg {
Ctr::Seg(val) => {
let val_tmp = val.borrow().clone();
define(b, identifier.to_string(), Rc::new(val_tmp.car));
if env_cfg {
// set var in env
// gotta distill value
// env::set_var(identifier, VALUE)
}
},
match eval(tree.clone(), b.clone(), c.clone(), false) {
Ok(seg) => {
match seg {
Ctr::Seg(val) => {
let val_tmp = val.borrow().clone();
define(b, identifier.to_string(), Rc::new(val_tmp.car));
if env_cfg {
match val_tmp.car {
Ctr::Symbol(s) => env::set_var(identifier, s),
Ctr::String(s) => env::set_var(identifier, s),
Ctr::Integer(i) => env::set_var(identifier, format!("{}", i)),
Ctr::Float(f) => env::set_var(identifier, format!("{}", f)),
Ctr::Bool(b) => env::set_var(identifier, format!("{}", b)),
Ctr::Seg(c) => env::set_var(identifier, ast_to_string(c)),
Ctr::None => ()
}
}
},
_ => {
eprintln!("impossible args to export");
_ => eprintln!("impossible args to export")
}
}
},
},
Ctr::None => {
// UNSET VAR LOGIC
Err(e) => eprintln!("couldnt eval symbol: {}", e)
}
},
_ => {
eprintln!("args not in standard form");
}
Ctr::None => {
(*b).borrow_mut().remove(identifier);
},
_ => eprintln!("args not in standard form")
}
return Ctr::None;
},
_ => {
eprintln!("first argument to export must be a symbol");
return Ctr::None;
}
_ => eprintln!("first argument to export must be a symbol")
}
return Ctr::None;
}
)
};