export vars fixed. tests pass

This commit is contained in:
Aidan Hahn 2021-11-08 00:45:09 -08:00
parent 307101327c
commit 1b1ac3cd2b
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 17 additions and 7 deletions

View file

@ -46,19 +46,19 @@ pub fn eval(
// another check to detect if we may have a function call // another check to detect if we may have a function call
if let Ctr::Symbol(ref tok) = car { if let Ctr::Symbol(ref tok) = car {
match cdr { match cdr.clone() {
Ctr::Seg(ast) => { Ctr::Seg(ast) => {
if let Some(func) = funcs.borrow().get(tok) { if let Some(func) = funcs.borrow().get(tok) {
return func_call(func.clone(), ast.clone(), vars.clone(), funcs.clone()) return func_call(func.clone(), ast.clone(), vars.clone(), funcs.clone())
} else { } else if !sym_loose {
return Err(format!("Couldnt find function: {}.", tok)) return Err(format!("Couldnt find definition of {}.", tok))
} }
}, },
Ctr::None => { Ctr::None => {
if let Some(func) = funcs.borrow().get(tok) { if let Some(func) = funcs.borrow().get(tok) {
return func_call(func.clone(), new_ast(Ctr::None, Ctr::None), vars.clone(), funcs.clone()) return func_call(func.clone(), new_ast(Ctr::None, Ctr::None), vars.clone(), funcs.clone())
} else { } else if !sym_loose {
return Err(format!("Couldnt find function: {}.", tok)) return Err(format!("Couldnt find definition of {}.", tok))
} }
}, },
_ => return Err(format!("Arguments to function not a list!")) _ => return Err(format!("Arguments to function not a list!"))

View file

@ -49,7 +49,16 @@ pub fn get_export(env_cfg: bool) -> Function {
let inner = a.borrow_mut(); let inner = a.borrow_mut();
match &inner.car { match &inner.car {
Ctr::Symbol(identifier) => { Ctr::Symbol(identifier) => {
define(b, identifier.to_string(), Rc::new(inner.cdr.clone())); match inner.cdr.clone() {
Ctr::Seg(val) => {
let val_tmp = val.borrow().clone();
define(b, identifier.to_string(), Rc::new(val_tmp.car));
},
_ => {
eprintln!("impossible args to export");
}
}
return Ctr::None; return Ctr::None;
}, },
_ => { _ => {

View file

@ -7,7 +7,7 @@ mod var_lib_tests {
#[test] #[test]
fn test_variable_export_and_lookup() { fn test_variable_export_and_lookup() {
let doc1 = "(export test 1)"; let doc1 = "(export test 1)";
let doc2 = "(echo test)"; let doc2 = "(concat test)";
let result = "1"; let result = "1";
let vt = Rc::new(RefCell::new(VTable::new())); let vt = Rc::new(RefCell::new(VTable::new()));
let ft: Rc<RefCell<FTable>>; let ft: Rc<RefCell<FTable>>;
@ -34,6 +34,7 @@ mod var_lib_tests {
}, },
Ok(ctr) => { Ok(ctr) => {
println!("{:#?}", vt);
match ctr { match ctr {
Ctr::None => assert!(true), Ctr::None => assert!(true),
_ => assert!(false) _ => assert!(false)