added env function and test
This commit is contained in:
parent
79184b18ef
commit
f22d807b57
5 changed files with 55 additions and 1 deletions
|
|
@ -36,10 +36,13 @@ https://matrix.to/#/#vomitorium:matrix.sunnypup.io
|
||||||
*** TODO Easy patterns
|
*** TODO Easy patterns
|
||||||
**** TODO while-let combo
|
**** TODO while-let combo
|
||||||
**** TODO main loop application
|
**** TODO main loop application
|
||||||
|
**** TODO let destructuring
|
||||||
|
**** TODO if-set?
|
||||||
*** TODO Builtin functions
|
*** TODO Builtin functions
|
||||||
*** TODO Documentation
|
*** TODO Documentation
|
||||||
**** TODO Tests
|
**** TODO Tests
|
||||||
**** TODO Help function
|
**** TODO Help function
|
||||||
|
**** TODO Env function
|
||||||
**** TODO Snippets directory
|
**** TODO Snippets directory
|
||||||
|
|
||||||
** Configuration
|
** Configuration
|
||||||
|
|
@ -136,7 +139,6 @@ This contains any executable target of this project. Notably the main shell file
|
||||||
Note: this section will not show the status of each item unless you are viewing it with a proper orgmode viewer.
|
Note: this section will not show the status of each item unless you are viewing it with a proper orgmode viewer.
|
||||||
Note: this section only tracks the state of incomplete TODO items. Having everything on here would be cluttered.
|
Note: this section only tracks the state of incomplete TODO items. Having everything on here would be cluttered.
|
||||||
|
|
||||||
*** TODO Eval function
|
|
||||||
*** TODO Input function
|
*** TODO Input function
|
||||||
*** TODO Env function
|
*** TODO Env function
|
||||||
*** TODO Load (load a script) function
|
*** TODO Load (load a script) function
|
||||||
|
|
|
||||||
11
src/stl.rs
11
src/stl.rs
|
|
@ -172,6 +172,17 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
syms.insert(
|
||||||
|
"env".to_string(),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("env"),
|
||||||
|
args: Args::None,
|
||||||
|
conditional_branches: false,
|
||||||
|
docs: decl::ENV_DOCSTRING.to_string(),
|
||||||
|
value: ValueType::Internal(Rc::new(decl::env_callback)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,3 +189,24 @@ pub fn isset_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const ENV_DOCSTRING: &str = "takes no arguments
|
||||||
|
prints out all available symbols and their associated values";
|
||||||
|
|
||||||
|
pub fn env_callback(_ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
|
let mut functions = vec![];
|
||||||
|
println!("VARIABLES:");
|
||||||
|
for (name, val) in syms.iter() {
|
||||||
|
match val.value {
|
||||||
|
ValueType::VarForm(_) => {
|
||||||
|
println!(" {}: {}", &name, val.value);
|
||||||
|
},
|
||||||
|
_ => functions.push(name.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("FUNCTIONS:");
|
||||||
|
for func in functions {
|
||||||
|
println!(" {}", func);
|
||||||
|
}
|
||||||
|
Ok(Ctr::None)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,10 @@ impl SymTable {
|
||||||
self.0.remove(arg)
|
self.0.remove(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn iter(&self) -> std::collections::hash_map::Iter<'_, String, Symbol> {
|
||||||
|
self.0.iter()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn call_symbol(
|
pub fn call_symbol(
|
||||||
&mut self,
|
&mut self,
|
||||||
name: &String,
|
name: &String,
|
||||||
|
|
|
||||||
|
|
@ -249,4 +249,20 @@ mod var_lib_tests {
|
||||||
assert!(!b);
|
assert!(!b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_env_doesnt_lose_elements() {
|
||||||
|
let doc1 = "(def t '' 1)";
|
||||||
|
let doc2 = "(env)";
|
||||||
|
let doc3 = "t";
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms).unwrap();
|
||||||
|
let set_tree = lex(&doc1.to_string()).unwrap();
|
||||||
|
let env_tree = lex(&doc2.to_string()).unwrap();
|
||||||
|
let tst_tree = lex(&doc3.to_string()).unwrap();
|
||||||
|
eval(&set_tree, &mut syms).unwrap();
|
||||||
|
eval(&env_tree, &mut syms).unwrap();
|
||||||
|
eval(&tst_tree, &mut syms).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue