diff options
-rw-r--r-- | code/lib/memory.felan | 7 | ||||
-rw-r--r-- | code/main.felan | 4 | ||||
-rw-r--r-- | src/compiler/lexer.h | 2 | ||||
-rw-r--r-- | src/runner/runner.c | 1 |
4 files changed, 12 insertions, 2 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)); }; diff --git a/src/compiler/lexer.h b/src/compiler/lexer.h index f3292ae..8d62b14 100644 --- a/src/compiler/lexer.h +++ b/src/compiler/lexer.h @@ -74,7 +74,6 @@ typedef enum LexerToken { LEXER_TOKEN_SYMBOL_FUNCTION_ARROW, LEXER_TOKEN_ORDER2 = LEXER_TOKEN_SYMBOL_FUNCTION_ARROW, - LEXER_TOKEN_SYMBOL_POINTER, LEXER_TOKEN_KEYWORD_STRUCT, LEXER_TOKEN_SYMBOL_CLOSE_BRACKET_LEFT, @@ -85,6 +84,7 @@ typedef enum LexerToken { LEXER_TOKEN_SYMBOL_PLUS, LEXER_TOKEN_ORDER4 = LEXER_TOKEN_SYMBOL_PLUS, + LEXER_TOKEN_SYMBOL_POINTER, LEXER_TOKEN_SYMBOL_MINUS, LEXER_TOKEN_SYMBOL_ADDRESS, LEXER_TOKEN_SYMBOL_LOGICAL_NOT, diff --git a/src/runner/runner.c b/src/runner/runner.c index 611d55f..52be448 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -2409,6 +2409,7 @@ AstTree *castTo(AstTree *tree, AstTree *to) { case AST_TREE_TOKEN_TYPE_C_LIBRARY: case AST_TREE_TOKEN_TYPE_C_FUNCTION: } + printLog("%s", AST_TREE_TOKEN_STRINGS[tree->token]); UNREACHABLE; } |