aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/lib/memory.felan7
-rw-r--r--code/main.felan4
2 files changed, 10 insertions, 1 deletions
diff --git a/code/lib/memory.felan b/code/lib/memory.felan
new file mode 100644
index 0000000..adb9cf2
--- /dev/null
+++ b/code/lib/memory.felan
@@ -0,0 +1,7 @@
+libc :: @c_library("/usr/lib/libc.so.6");
+malloc :: @c_function(libc,"malloc",(i64)->(*void));
+free :: @c_function(libc,"free",(*void)->void);
+
+malloc :: (size:i64,comptime t:type) -> (*t) {
+ return @cast(malloc(size*@cast(@size_of(t),i64)),*t);
+};
diff --git a/code/main.felan b/code/main.felan
index d14013e..c17b965 100644
--- a/code/main.felan
+++ b/code/main.felan
@@ -1,4 +1,5 @@
@import("basic.felan");
+@import("lib/memory.felan");
print :: (value:**anytype)->void{
if comptime @type_of(value.*) == u8 {
@@ -29,12 +30,13 @@ __get_item_address__ :: (left:*anytype,index:i64,item:@type_of(left.*)) -> (@typ
};
main :: ()->void{
- p := @stack_alloc(i64,10);
+ p := malloc(10,u64);
i := 0;
while i < 10 {
__set_item__(p,i,0);
i += 1;
}
print(__get_item__(p,1));
+ free(@cast(p,*void));
};