From ca6f2ec64941953f0111a64b7acf4cf6fb31929a Mon Sep 17 00:00:00 2001 From: A404M Date: Sat, 31 May 2025 15:09:23 +0330 Subject: add array access support to arrays --- code/lib/io.felan | 8 ++++---- code/lib/operator.felan | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'code/lib') diff --git a/code/lib/io.felan b/code/lib/io.felan index 3019092..ff697e2 100644 --- a/code/lib/io.felan +++ b/code/lib/io.felan @@ -6,10 +6,10 @@ puts :: @c_function(libc,"puts",(*u8)->i32); putchar :: @c_function(libc,"putchar",(i32)->void); print :: (value:string) -> void { - i :u64= 0; - while i < value.length { + i := 0; + while i < @cast(value.length,i64) { print_char(value[i]); - i += @cast(1,u64); + i += 1; } }; @@ -59,7 +59,7 @@ _print_signed :: (comptime t:type, value:t) -> i32 { _print_unsigned :: (comptime t:type, value:t) -> void { NUMBERS_SIZE :: 21; - numbers : [NUMBERS_SIZE]u8 = undefined; + numbers := @stack_alloc(NUMBERS_SIZE,u8); i := NUMBERS_SIZE - 1; numbers[i] = '\0'; diff --git a/code/lib/operator.felan b/code/lib/operator.felan index 3da070a..b7ac63a 100644 --- a/code/lib/operator.felan +++ b/code/lib/operator.felan @@ -790,7 +790,6 @@ __shift_right__ :: (left:i64,right:i64) -> i64 { return @shift_right(left,right); }; - //---------------------- Pointers ------------------------ __sum__ :: (left:*anytype,right:i64) -> (@type_of(left)) { @@ -813,3 +812,16 @@ __get_item_address__ :: (left:*anytype,index:i64) -> (@type_of(left)) { return (left + index); }; +//---------------------- Array ------------------------ + +__get_item__ :: (left:[]anytype,index:i64) -> (@type_of(left.ptr.*)) { + return (left.ptr + index).*; +}; + +__set_item__ :: (left:[]anytype,index:i64,item:@type_of(left.ptr.*)) -> (@type_of(left.ptr.*)) { + return (left.ptr + index).* = item; +}; + +__get_item_address__ :: (left:[]anytype,index:i64) -> (@type_of(left.ptr)) { + return (left.ptr + index); +}; -- cgit v1.2.3