aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-30 18:00:20 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-30 18:00:20 +0330
commitc07717041a1dc0544af9c10a13d7902adbc70027 (patch)
tree54b02e1e399531aad16ca41825f553f926bf1d77
parent15fce202de10352d60c1853e7c8940b3eeca13c9 (diff)
fix bug in pointer access
-rw-r--r--code/main.felan15
-rw-r--r--src/runner/runner.c2
2 files changed, 9 insertions, 8 deletions
diff --git a/code/main.felan b/code/main.felan
index 8e096e0..d14013e 100644
--- a/code/main.felan
+++ b/code/main.felan
@@ -17,23 +17,24 @@ __sub__ :: (left:*anytype,right:i64) -> (@type_of(left)) {
};
__get_item__ :: (left:*anytype,index:i64) -> (@type_of(left.*)) {
- left += index;
- return left.*;
+ return (left + index).*;
};
__set_item__ :: (left:*anytype,index:i64,item:@type_of(left.*)) -> (@type_of(left.*)) {
- left += index;
- return left.* = item;
+ return (left + index).* = item;
};
__get_item_address__ :: (left:*anytype,index:i64,item:@type_of(left.*)) -> (@type_of(left)) {
- left += index;
- return left;
+ return (left + index);
};
main :: ()->void{
p := @stack_alloc(i64,10);
- __set_item__(p,1,0);
+ i := 0;
+ while i < 10 {
+ __set_item__(p,i,0);
+ i += 1;
+ }
print(__get_item__(p,1));
};
diff --git a/src/runner/runner.c b/src/runner/runner.c
index 30fd555..611d55f 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -1238,7 +1238,7 @@ AstTree *runAstTreeBuiltin(AstTree *tree, AstTreeScope *scope,
const size_t sizeOfType = getSizeOfType(type);
const size_t size = *(u64 *)count->metadata * sizeOfType;
scope->stackAllocation[scope->stackAllocation_size] = a404m_malloc(size);
- memset(scope->stackAllocation[scope->stackAllocation_size], 0, size);
+ // memset(scope->stackAllocation[scope->stackAllocation_size], 0, size);
AstTreeRawValue *value = a404m_malloc(sizeof(void *));
*(void **)value = scope->stackAllocation[scope->stackAllocation_size];