aboutsummaryrefslogtreecommitdiff
path: root/src/runner/runner.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-28 14:58:08 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-28 14:58:08 +0330
commit4b03901a1ebbe24b1c8c6c9fac6dc036bc3567f8 (patch)
treebc0d1d8102efcc0dc39cb75da76a66c501b4e89d /src/runner/runner.c
parentfd03f34bc31c3764e8533e4fae9550d79a245301 (diff)
fix length getting in array
Diffstat (limited to 'src/runner/runner.c')
-rw-r--r--src/runner/runner.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/runner/runner.c b/src/runner/runner.c
index a952c0b..e114749 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -1796,6 +1796,24 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
}
UNREACHABLE;
} else if (tree->token == AST_TREE_TOKEN_RAW_VALUE_NOT_OWNED) {
+ if (tree->type->token == AST_TREE_TOKEN_TYPE_ARRAY) {
+ AstTreeBracket *array_metadata = tree->type->metadata;
+ if (metadata->member.index != 0) {
+ UNREACHABLE;
+ } else {
+ if (array_metadata->parameters.size == 1) {
+ AstTree *sizeTree = runExpression(
+ array_metadata->parameters.data[0], scope, shouldRet, false,
+ isComptime, breakCount, shouldContinue, false);
+ return sizeTree;
+ } else {
+ u64 *value = a404m_malloc(sizeof(*value));
+ *value = a404m_malloc_usable_size(tree->metadata);
+ return newAstTree(AST_TREE_TOKEN_RAW_VALUE, value,
+ &AST_TREE_U64_TYPE, NULL, NULL);
+ }
+ }
+ }
size_t index = 0;
AstTreeStruct *type = tree->type->metadata;
for (size_t i = 0; i < metadata->member.index; ++i) {
@@ -1858,7 +1876,8 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
return array_indexNode;
}
- if (!typeIsEqual(array_indexNode->type, &AST_TREE_I64_TYPE)) {
+ if (!typeIsEqual(array_indexNode->type, &AST_TREE_I64_TYPE) &&
+ !typeIsEqual(array_indexNode->type, &AST_TREE_U64_TYPE)) {
UNREACHABLE;
}