From c07717041a1dc0544af9c10a13d7902adbc70027 Mon Sep 17 00:00:00 2001 From: A404M Date: Fri, 30 May 2025 18:00:20 +0330 Subject: fix bug in pointer access --- code/main.felan | 15 ++++++++------- src/runner/runner.c | 2 +- 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]; -- cgit v1.2.3