From c91d3a8893b9c53c5c8e4c5cff72d7caf44cfee4 Mon Sep 17 00:00:00 2001 From: A404M Date: Fri, 30 May 2025 22:01:19 +0330 Subject: fixing some minor issues --- code/lib/operator.felan | 12 ++++++++++++ code/lib/types.felan | 4 ++-- code/main.felan | 17 +++++------------ 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'code') diff --git a/code/lib/operator.felan b/code/lib/operator.felan index d8121c2..2112c57 100644 --- a/code/lib/operator.felan +++ b/code/lib/operator.felan @@ -790,3 +790,15 @@ __shift_right__ :: (left:i64,right:i64) -> i64 { return @shift_right(left,right); }; + +//---------------------- Pointers ------------------------ + +__sum__ :: (left:*anytype,right:i64) -> (@type_of(left)) { + return @add(left,right); +}; + +__sub__ :: (left:*anytype,right:i64) -> (@type_of(left)) { + return @sub(left,right); +}; + + diff --git a/code/lib/types.felan b/code/lib/types.felan index 8c0cbf1..df7f5c3 100644 --- a/code/lib/types.felan +++ b/code/lib/types.felan @@ -2,7 +2,7 @@ string :: []u8; array :: (comptime size:u64, comptime t:type) -> type { return struct { - ptr : t; - size : i32 : size; + ptr : *t; + size : @type_of(size) : size; }; }; diff --git a/code/main.felan b/code/main.felan index c17b965..239a201 100644 --- a/code/main.felan +++ b/code/main.felan @@ -9,14 +9,6 @@ print :: (value:**anytype)->void{ } }; -__sum__ :: (left:*anytype,right:i64) -> (@type_of(left)) { - return @add(left,right); -}; - -__sub__ :: (left:*anytype,right:i64) -> (@type_of(left)) { - return @sub(left,right); -}; - __get_item__ :: (left:*anytype,index:i64) -> (@type_of(left.*)) { return (left + index).*; }; @@ -30,13 +22,14 @@ __get_item_address__ :: (left:*anytype,index:i64,item:@type_of(left.*)) -> (@typ }; main :: ()->void{ - p := malloc(10,u64); + arr :array(@cast(10,u64),i64) = undefined; + arr.ptr = @stack_alloc(10,i64); i := 0; while i < 10 { - __set_item__(p,i,0); + __set_item__(arr.ptr,i,0); i += 1; } - print(__get_item__(p,1)); - free(@cast(p,*void)); + print(__get_item__(arr.ptr,1)); + free(@cast(arr.ptr,*void)); }; -- cgit v1.2.3