diff options
-rw-r--r-- | code/lib/operator.felan | 12 | ||||
-rw-r--r-- | code/lib/types.felan | 4 | ||||
-rw-r--r-- | code/main.felan | 17 | ||||
-rw-r--r-- | src/compiler/ast-tree.c | 20 | ||||
-rw-r--r-- | src/runner/runner.c | 4 |
5 files changed, 31 insertions, 26 deletions
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)); }; diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index 5d2048b..c778571 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -6611,8 +6611,8 @@ bool setTypesBuiltinStackAlloc(AstTree *tree, AstTreeSetTypesHelper helper, AstTreeFunctionCall *functionCall) { (void)helper; if (functionCall->parameters_size == 2) { - AstTree *type = NULL; AstTree *count = NULL; + AstTree *type = NULL; static const char TYPE_STR[] = "type"; static const size_t TYPE_STR_SIZE = @@ -6626,10 +6626,10 @@ bool setTypesBuiltinStackAlloc(AstTree *tree, AstTreeSetTypesHelper helper, const size_t param_name_size = param.nameEnd - param.nameBegin; if (param_name_size == 0) { - if (type == NULL) { - type = param.value; - } else if (count == NULL) { + if (count == NULL) { count = param.value; + } else if (type == NULL) { + type = param.value; } else { printError(param.value->str_begin, param.value->str_end, "Bad paramter"); @@ -6673,18 +6673,18 @@ bool setTypesBuiltinStackAlloc(AstTree *tree, AstTreeSetTypesHelper helper, &AST_TREE_TYPE_TYPE, NULL, NULL); type_metadata->arguments[0] = (AstTreeTypeFunctionArgument){ - .type = copyAstTree(type->type), - .name_begin = COUNT_STR, - .name_end = COUNT_STR + COUNT_STR_SIZE, + .type = copyAstTree(count->type), + .name_begin = TYPE_STR, + .name_end = TYPE_STR + TYPE_STR_SIZE, .str_begin = NULL, .str_end = NULL, .isComptime = false, }; type_metadata->arguments[1] = (AstTreeTypeFunctionArgument){ - .type = copyAstTree(count->type), - .name_begin = TYPE_STR, - .name_end = TYPE_STR + TYPE_STR_SIZE, + .type = copyAstTree(type->type), + .name_begin = COUNT_STR, + .name_end = COUNT_STR + COUNT_STR_SIZE, .str_begin = NULL, .str_end = NULL, .isComptime = false, diff --git a/src/runner/runner.c b/src/runner/runner.c index 52be448..40bcc75 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -1222,8 +1222,8 @@ AstTree *runAstTreeBuiltin(AstTree *tree, AstTreeScope *scope, copyAstTree(function->returnType), NULL, NULL); } case AST_TREE_TOKEN_BUILTIN_STACK_ALLOC: { - AstTree *type = arguments[0]; - AstTree *count = arguments[1]; + AstTree *count = arguments[0]; + AstTree *type = arguments[1]; size_t stackAllocation_capacity = a404m_malloc_usable_size(scope->stackAllocation) / |