(un)finished env integration logic
This commit is contained in:
parent
5aa2b27343
commit
a967ac5c3e
2 changed files with 32 additions and 27 deletions
|
|
@ -26,7 +26,7 @@ use crate::eval::eval;
|
||||||
pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
|
pub type FTable = HashMap<String, Rc<RefCell<Function>>>;
|
||||||
|
|
||||||
// Standardized function signature for stdlib functions
|
// 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 {
|
pub struct ExternalOperation {
|
||||||
// Un-evaluated abstract syntax tree
|
// Un-evaluated abstract syntax tree
|
||||||
// TODO: Intermediate evaluation to simplify branches with no argument in them
|
// TODO: Intermediate evaluation to simplify branches with no argument in them
|
||||||
|
|
|
||||||
39
src/vars.rs
39
src/vars.rs
|
|
@ -19,7 +19,7 @@ use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use crate::segment::{Ctr, Ast};
|
use crate::segment::{Ctr, Ast, ast_to_string};
|
||||||
use crate::eval::eval;
|
use crate::eval::eval;
|
||||||
use crate::func::{Function, Operation, Args, FTable};
|
use crate::func::{Function, Operation, Args, FTable};
|
||||||
/* Mapping between a string token and a tree of Segments
|
/* 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) => {
|
Ctr::Symbol(identifier) => {
|
||||||
match &inner.cdr {
|
match &inner.cdr {
|
||||||
Ctr::Seg(tree) => {
|
Ctr::Seg(tree) => {
|
||||||
if let Ok(seg) = eval(tree.clone(), b.clone(), c.clone(), false) {
|
match eval(tree.clone(), b.clone(), c.clone(), false) {
|
||||||
|
Ok(seg) => {
|
||||||
match seg {
|
match seg {
|
||||||
Ctr::Seg(val) => {
|
Ctr::Seg(val) => {
|
||||||
let val_tmp = val.borrow().clone();
|
let val_tmp = val.borrow().clone();
|
||||||
define(b, identifier.to_string(), Rc::new(val_tmp.car));
|
define(b, identifier.to_string(), Rc::new(val_tmp.car));
|
||||||
if env_cfg {
|
if env_cfg {
|
||||||
// set var in env
|
match val_tmp.car {
|
||||||
// gotta distill value
|
Ctr::Symbol(s) => env::set_var(identifier, s),
|
||||||
// env::set_var(identifier, VALUE)
|
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");
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Err(e) => eprintln!("couldnt eval symbol: {}", e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Ctr::None => {
|
Ctr::None => {
|
||||||
// UNSET VAR LOGIC
|
(*b).borrow_mut().remove(identifier);
|
||||||
|
},
|
||||||
|
|
||||||
|
_ => eprintln!("args not in standard form")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => eprintln!("first argument to export must be a symbol")
|
||||||
eprintln!("args not in standard form");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ctr::None;
|
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