add echo function
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
914bf1303f
commit
eed16964e6
3 changed files with 30 additions and 10 deletions
20
src/stl.rs
20
src/stl.rs
|
|
@ -49,6 +49,16 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"echo".to_string(),
|
||||
Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Infinite,
|
||||
conditional_branches: false,
|
||||
value: ValueType::Internal(Rc::new(_echo_callback)),
|
||||
},
|
||||
);
|
||||
|
||||
syms.insert(
|
||||
"if".to_string(),
|
||||
Symbol {
|
||||
|
|
@ -90,6 +100,16 @@ pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn _echo_callback(ast: &Seg, _syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
if ast.len() == 1 {
|
||||
println!("{}", ast.car);
|
||||
} else {
|
||||
ast.circuit(&mut |arg: &Ctr| print!("{}", arg) == ());
|
||||
}
|
||||
|
||||
Ok(Ctr::None)
|
||||
}
|
||||
|
||||
fn _store_callback(ast: &Seg, syms: &mut SymTable, env_cfg: bool) -> Result<Ctr, String> {
|
||||
let is_var = ast.len() == 2;
|
||||
if let Ctr::Symbol(ref identifier) = *ast.car {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue