diff options
Diffstat (limited to 'code')
-rw-r--r-- | code/lib/io.felan | 8 | ||||
-rw-r--r-- | code/lib/operator.felan | 14 | ||||
-rw-r--r-- | code/main.felan | 11 |
3 files changed, 21 insertions, 12 deletions
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); +}; diff --git a/code/main.felan b/code/main.felan index b1a55b9..def8750 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,6 +1,7 @@ // @import("basic.felan"); -@import("lib/memory.felan"); +// @import("lib/memory.felan"); @import("lib/operator.felan"); +@import("lib/types.felan"); print :: (value:**anytype)->void{ if comptime @type_of(value.*) == u8 { @@ -11,12 +12,8 @@ print :: (value:**anytype)->void{ }; main :: () -> void { - a := malloc(10,u8); - a[0] = '1'; - b := &a[2]; - b.* = '9'; + a : [23]u8 = undefined; + a[0] = '2'; @putc(a[0]); - @putc(b.*); - free(a); }; |