(un)finished env integration logic
This commit is contained in:
parent
5aa2b27343
commit
a967ac5c3e
2 changed files with 32 additions and 27 deletions
57
src/vars.rs
57
src/vars.rs
|
|
@ -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;
|
||||
}
|
||||
)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue