add echo function

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-01 12:27:45 -08:00
parent 914bf1303f
commit eed16964e6
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
3 changed files with 30 additions and 10 deletions

View file

@ -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 {