From 20ff73d84b85db77aecb2171ce4d0e13253cccfd Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 7 May 2025 14:32:53 +0330 Subject: add lazy to variables --- src/runner/runner.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/runner/runner.c') diff --git a/src/runner/runner.c b/src/runner/runner.c index abbd05c..6199244 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -3,7 +3,6 @@ #include "utils/log.h" #include "utils/memory.h" #include "utils/string.h" -#include #include #include @@ -1186,9 +1185,14 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet, } case AST_TREE_TOKEN_VARIABLE_DEFINE: { AstTreeVariable *variable = expr->metadata; - runnerVariableSetValue(variable, - runExpression(variable->initValue, scope, shouldRet, - false, isComptime)); + AstTree *value; + if (variable->isLazy) { + value = copyAstTree(variable->initValue); + } else { + value = runExpression(variable->initValue, scope, shouldRet, false, + isComptime); + } + runnerVariableSetValue(variable, value); return &AST_TREE_VOID_VALUE; } case AST_TREE_TOKEN_KEYWORD_IF: { @@ -1378,7 +1382,12 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet, if (variable->value == NULL) { UNREACHABLE; } - return copyAstTree(variable->value); + if (variable->isLazy) { + return runExpression(variable->value, scope, shouldRet, false, + isComptime); + } else { + return copyAstTree(variable->value); + } } } case AST_TREE_TOKEN_OPERATOR_ACCESS: { -- cgit v1.2.3