diff --git a/src/executor.rs b/src/executor.rs index 7a7815a..415ea5c 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -353,6 +353,24 @@ where } } ParseTree::LambdaDefinition(func) => Ok(Value::Function(func)), + ParseTree::NonCall(name) => { + let locals = locals.to_mut(); + + let func = locals.get(&name).ok_or(RuntimeError::FunctionUndefined(name.clone())).cloned()?; + + match func { + Object::Function(func) => Ok(Value::Function(func.clone())), + Object::Variable(var) => match var { + Evaluation::Computed(value) => Ok(value.clone()), + Evaluation::Uncomputed(tree) => { + let v = self.exec(tree, &mut Cow::Borrowed(&locals))?; + locals.insert(name, Object::Variable(Evaluation::Computed(v.clone()))); + + Ok(v) + } + } + } + } } } } diff --git a/src/parser.rs b/src/parser.rs index cd9899d..6189376 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -79,6 +79,7 @@ pub(crate) enum ParseTree { FunctionCall(String, Vec), Variable(String), Constant(Value), + NonCall(String), // Type Casts IntCast(Box), @@ -257,7 +258,10 @@ impl ParseTree { Ok(ParseTree::LambdaDefinition(f)) } - Op::NonCall => todo!(), + Op::NonCall => { + let name = Self::get_identifier(tokens.next())?; + Ok(ParseTree::NonCall(name)) + }, op => Err(ParseError::UnwantedToken(Token::Operator(op))), } } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index e24b6bf..db5f24c 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -328,7 +328,6 @@ impl Tokenizer { return; } }; - println!("{n} + {count}"); Op::FunctionDefine(n + count) }