diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-07 14:44:16 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-07 14:44:16 +0330 |
commit | 62b7af496f2c694ff5361cf21042bbe14f969c64 (patch) | |
tree | 4c9b32af2d2baa49ad9941fc73a90133e1c27a77 | |
parent | 1f73f7e22c207fa72391253e21332e02d055bd72 (diff) |
add more type stuff
-rw-r--r-- | code/main.felan | 43 | ||||
-rw-r--r-- | src/compiler/ast-tree.c | 12 | ||||
-rw-r--r-- | src/runner/runner.c | 7 | ||||
-rw-r--r-- | src/runner/runner.h | 1 |
4 files changed, 46 insertions, 17 deletions
diff --git a/code/main.felan b/code/main.felan index ef93ea0..52c8933 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,20 +1,33 @@ -st :: struct { - a : u64; - b : f64; -}; +byte :: i8; +ubyte :: u8; -newSt :: (a : u64,b : f64) -> st { - value : st = undefined; - value.a = a; - value.b = b; - return value; -}; +short :: i16; +ushort :: u16; -main :: () -> void { - a := newSt(a = 2,b = 3); - print(a); +int :: i32; +uint :: u32; + +long :: i64; +ulong :: u64; + +short_float :: f16; +float :: f32; +double :: f64; +long_double :: f128; + +usize :: u64; + +array :: (t:type) -> type { + return struct { + ptr : *t; + length : usize; + }; }; -print :: (value:st) -> void { - print_u64 value.a; +array_int :: array(u64); + +main :: () -> void { + a : array_int = undefined; + b :u64 =2; + a.length = 1; }; diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index 0dc5424..55209c4 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -1555,7 +1555,7 @@ AstTree *astTreeParseFunction(ParserNode *parserNode, AstTreeHelper *p_helper) { argument->type = type; argument->name_begin = arg_metadata->name->str_begin; argument->name_end = arg_metadata->name->str_end; - argument->isConst = false; // all arguments are not constants + argument->isConst = true; // all arguments are constants if (!pushVariable(&helper, &function->arguments, argument)) { astTreeVariableDelete(argument); @@ -2532,6 +2532,10 @@ AstTree *makeTypeOf(AstTree *value) { bool typeIsEqual(AstTree *type0, AstTree *type1) { AstTree *left = getValue(type0); AstTree *right = getValue(type1); + if (left == NULL || right == NULL) { + printLog("Can't check types"); + UNREACHABLE; + } bool ret = typeIsEqualBack(left, right); @@ -3231,6 +3235,9 @@ bool setTypesReturn(AstTree *tree, AstTreeSetTypesHelper _helper, .lookingType = getValue(function->returnType), .treeHelper = _helper.treeHelper, }; + if (helper.lookingType == NULL) { + return false; + } if (!setAllTypes(metadata->value, helper, NULL)) { return false; } @@ -3628,6 +3635,9 @@ bool setTypesComptime(AstTree *tree, AstTreeSetTypesHelper helper) { } AstTree *newTree = getValue(operand); + if (newTree == NULL) { + return false; + } if (operand != newTree) { astTreeDelete(operand); diff --git a/src/runner/runner.c b/src/runner/runner.c index c6a8bf0..984af3f 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -30,6 +30,11 @@ void runnerVariableSetValue(AstTreeVariable *variable, AstTree *value) { if (variable->isConst) { UNREACHABLE; } + runnerVariableSetValueWihtoutConstCheck(variable, value); +} + +void runnerVariableSetValueWihtoutConstCheck(AstTreeVariable *variable, + AstTree *value) { if (variable->value != NULL) { astTreeDelete(variable->value); } @@ -71,7 +76,7 @@ AstTree *runAstTreeFunction(AstTree *tree, AstTreeFunctionCallParam *arguments, AstTreeFunctionCallParam param = arguments[i]; AstTreeVariable *arg = function->arguments.data[i]; AstTree *value = runExpression(param.value, &shouldRet, false); - runnerVariableSetValue(arg, value); + runnerVariableSetValueWihtoutConstCheck(arg, value); } shouldRet = false; diff --git a/src/runner/runner.h b/src/runner/runner.h index 10fd8dc..2ff2ec2 100644 --- a/src/runner/runner.h +++ b/src/runner/runner.h @@ -4,6 +4,7 @@ #include <stdint.h> void runnerVariableSetValue(AstTreeVariable *variable,AstTree *value); +void runnerVariableSetValueWihtoutConstCheck(AstTreeVariable *variable,AstTree *value); bool runAstTree(AstTreeRoot *root); |