diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-05-31 06:26:48 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-05-31 06:26:48 +0330 |
commit | 3c53293e9b2c2f9106da805d26b5eab9dff56225 (patch) | |
tree | d88cff685789812698e16711bb61e35e2918b110 /code | |
parent | faf462fe49bf642866175d842a98d721f8f66208 (diff) |
function with exact types are prefered to shape shifters
Diffstat (limited to 'code')
-rw-r--r-- | code/lib/memory.felan | 4 | ||||
-rw-r--r-- | code/main.felan | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/code/lib/memory.felan b/code/lib/memory.felan index adb9cf2..f1f9898 100644 --- a/code/lib/memory.felan +++ b/code/lib/memory.felan @@ -5,3 +5,7 @@ free :: @c_function(libc,"free",(*void)->void); malloc :: (size:i64,comptime t:type) -> (*t) { return @cast(malloc(size*@cast(@size_of(t),i64)),*t); }; + +free :: (a:*anytype) -> void { + free(@cast(a,*void)); +}; diff --git a/code/main.felan b/code/main.felan index 5b0c634..b1a55b9 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,5 +1,5 @@ // @import("basic.felan"); -// @import("lib/memory.felan"); +@import("lib/memory.felan"); @import("lib/operator.felan"); print :: (value:**anytype)->void{ @@ -11,11 +11,12 @@ print :: (value:**anytype)->void{ }; main :: () -> void { - a := @stack_alloc(10,u8); + a := malloc(10,u8); a[0] = '1'; b := &a[2]; b.* = '9'; @putc(a[0]); @putc(b.*); + free(a); }; |