add variable export function
This commit is contained in:
parent
7ca42f18da
commit
0931fbdcf0
5 changed files with 102 additions and 6 deletions
28
src/vars.rs
28
src/vars.rs
|
|
@ -18,8 +18,8 @@
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::collections::HashMap;
|
||||
use crate::segment::{Ctr};
|
||||
|
||||
use crate::segment::{Ctr, Ast};
|
||||
use crate::func::{Function, Operation, Args, FTable};
|
||||
/* Mapping between a string token and a tree of Segments
|
||||
* The string token can be found in any Ctr::Symbol value
|
||||
* it is expected that the trees stored are already evaluated
|
||||
|
|
@ -36,3 +36,27 @@ pub fn define(
|
|||
drop(rc_segment);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_export() -> Function {
|
||||
return Function{
|
||||
name: String::from("export"),
|
||||
loose_syms: true,
|
||||
eval_lazy: false,
|
||||
args: Args::Lazy(2),
|
||||
function: Operation::Internal(
|
||||
|a: Ast, b: Rc<RefCell<VTable>>, _c: Rc<RefCell<FTable>>| -> Ctr {
|
||||
let inner = a.borrow_mut();
|
||||
match &inner.car {
|
||||
Ctr::Symbol(identifier) => {
|
||||
define(b, identifier.to_string(), Rc::new(inner.cdr.clone()));
|
||||
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