From 524b201282d917f6c33e26fd202bec5c323e44a7 Mon Sep 17 00:00:00 2001 From: Mattias Ajander <mattias@ajander.se> Date: Mon, 7 Apr 2025 16:07:40 +0200 Subject: [PATCH] Buggy but functional var arethetic operations. leng of args work, but not print on empty args. Co-authored-by: Snoodelz <Snoodelz@users.noreply.github.com> --- source/ast/declaration/VariableNode.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/ast/declaration/VariableNode.cc b/source/ast/declaration/VariableNode.cc index dbff58a..2e079a5 100644 --- a/source/ast/declaration/VariableNode.cc +++ b/source/ast/declaration/VariableNode.cc @@ -27,7 +27,8 @@ Node* VariableNode::evaluate() const if (result == nullptr) { throw RuntimeError(get_location(), "Undefined variable '" + identifier + "'"); } return result; } - return new VariableNode(get_location(), identifier, is_mutable, type, value); + + return value->evaluate(); } String VariableNode::to_s() const @@ -38,12 +39,10 @@ String VariableNode::to_s() const NodeValue VariableNode::get_value() const { - if (value) - { - NodeValue val = value->get_value(); - return val; - } - return NodeValue{}; + ExpressionNode* result{dynamic_cast<ExpressionNode*>(evaluate())}; + if (!result) { throw RuntimeError(location, "Variable did not evaluate to an expression."); } + + return result->get_value(); } bool VariableNode::get_mutable() const -- GitLab