aboutsummaryrefslogtreecommitdiff
path: root/src/runner
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-07 14:32:53 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-07 14:32:53 +0330
commit20ff73d84b85db77aecb2171ce4d0e13253cccfd (patch)
tree2cc8b7f8816bc12ad97fe4a979ffccd29d347059 /src/runner
parentd7c31e44861b4d98fbddc177002e0a311a6d26af (diff)
add lazy to variables
Diffstat (limited to 'src/runner')
-rw-r--r--src/runner/runner.c19
-rw-r--r--src/runner/runner.h7
2 files changed, 18 insertions, 8 deletions
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 <math.h>
#include <stdatomic.h>
#include <stdio.h>
@@ -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: {
diff --git a/src/runner/runner.h b/src/runner/runner.h
index 93b250a..343f6c2 100644
--- a/src/runner/runner.h
+++ b/src/runner/runner.h
@@ -5,15 +5,16 @@
void runnerVariableSetValue(AstTreeVariable *variable, AstTree *value);
void runnerVariableSetValueWihtoutConstCheck(AstTreeVariable *variable,
AstTree *value);
+AstTree *runnerVariableGetValue(AstTreeVariable *variable);
bool runAstTree(AstTreeRoots roots);
AstTree *runAstTreeFunction(AstTree *tree, AstTreeFunctionCallParam *arguments,
- size_t arguments_size,bool isComptime);
+ size_t arguments_size, bool isComptime);
AstTree *runAstTreeBuiltin(AstTree *tree, AstTreeScope *scope,
AstTreeFunctionCallParam *arguments,
- size_t arguments_size,bool isComptime);
+ size_t arguments_size, bool isComptime);
AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
- bool isLeft,bool isComptime);
+ bool isLeft, bool isComptime);