diff --git a/src/sym.rs b/src/sym.rs index e29ffac..fa0ae62 100644 --- a/src/sym.rs +++ b/src/sym.rs @@ -68,7 +68,7 @@ pub struct Symbol { impl SymTable { pub fn new() -> SymTable { - SymTable{0: HashMap::::new()} + SymTable(HashMap::::new()) } pub fn get(&self, arg: &String) -> Option<&Symbol> { @@ -84,7 +84,7 @@ impl SymTable { } pub fn call_symbol(&mut self, name: &String, args: &Seg, call_func: bool) -> Result, String> { - let symbol = match self.get(name) { + let symbol = match self.remove(name) { Some(s) => s, None => return Err(format!("undefined symbol: {}", name)), }; @@ -100,7 +100,16 @@ impl SymTable { cond_args = &outer_scope_seg_holder; } - symbol.call(cond_args, self) + let res = symbol.call(cond_args, self); + self.insert(name.to_string(), symbol); + + res + } +} + +impl Default for SymTable { + fn default() -> Self { + Self::new() } } @@ -194,6 +203,7 @@ impl Symbol { let outer_scope_eval: Box; if self.conditional_branches { let outer_scope_eval_result = eval(args, syms); + // dont listen to clippy. using ? will move the value. if let Err(s) = outer_scope_eval_result { return Err(s); }