summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-02-23 20:06:47 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-02-23 20:07:04 +0330
commit4a39184dfcf0af72e2a28ffed2e3b342202fcba1 (patch)
tree804e466b54f6c3e99ec0caab9e8a1e1b31b052ba
parent1d13c72fb9fb40e35c64713a9176d263ad5fe09d (diff)
fix some bugs
-rw-r--r--src/compiler/ast-tree.c5
-rw-r--r--src/compiler/parser.c4
-rw-r--r--src/runner/runner.c20
-rw-r--r--test/main.felan9
4 files changed, 22 insertions, 16 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 97e06dc..1b56220 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -2084,7 +2084,8 @@ bool typeIsEqual(const AstTree *type0, const AstTree *type1) {
AstTree *getValue(AstTree *tree, AstTreeSetTypesHelper helper) {
if (!isConst(tree, helper.treeHelper)) {
- printLog("Can't get value at compile time because it is not const");
+ printError(tree->str_begin, tree->str_end,
+ "Can't get value at compile time because it is not const");
return NULL;
}
switch (tree->token) {
@@ -2446,7 +2447,7 @@ bool setTypesValueFloat(AstTree *tree, AstTreeSetTypesHelper helper) {
printWarning(tree->str_begin, tree->str_end, "Value is overflowing");
}
tree->type = &AST_TREE_F32_TYPE;
- } else if (helper.lookingType == &AST_TREE_F64_TYPE) {
+ } else if (helper.lookingType == &AST_TREE_F64_TYPE || helper.lookingType == NULL) {
tree->token = AST_TREE_TOKEN_VALUE_FLOAT;
AstTreeFloat value = *(AstTreeFloat *)tree->metadata;
f64 newValue = value;
diff --git a/src/compiler/parser.c b/src/compiler/parser.c
index 578d626..a25f549 100644
--- a/src/compiler/parser.c
+++ b/src/compiler/parser.c
@@ -992,7 +992,7 @@ ParserNode *parserParenthesis(LexerNode *closing, LexerNode *begin,
ParserNode *pNode =
getUntilCommonParents(iter->parserNode, parent, parserNode);
if (pNode == NULL) {
- printLog("Bad node", pNode->str_begin, pNode->str_end);
+ printLog(pNode->str_begin, pNode->str_end, "Bad node");
return NULL;
} else {
pNode->parent = parserNode;
@@ -1063,7 +1063,7 @@ ParserNode *parserCurlyBrackets(LexerNode *closing, LexerNode *begin,
ParserNode *pNode =
getUntilCommonParents(iter->parserNode, parent, parserNode);
if (pNode == NULL) {
- printLog(iter->str_begin, iter->str_end, "Bad node");
+ printError(iter->str_begin, iter->str_end, "Bad node");
return NULL;
} else {
pNode->parent = parserNode;
diff --git a/src/runner/runner.c b/src/runner/runner.c
index b5f0cb3..756d333 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -22,8 +22,9 @@
bool res = (bool)(((_type)(originalType)(op0)->metadata) operator( \
(_type)(originalType)(op1)->metadata)); \
astTreeDestroy(*(op0)); \
- (op0)->metadata = (void *)(u64)res; \
+ (op0)->metadata = (void *)(bool)res; \
(op0)->type = &AST_TREE_BOOL_TYPE; \
+ (op0)->token = AST_TREE_TOKEN_VALUE_BOOL; \
}
#define doLogicalOperationFloat(op0, op1, operator, originalType, _type) \
@@ -31,8 +32,9 @@
bool res = (bool)(((_type) * ((originalType *)(op0)->metadata)) operator( \
(_type) * ((originalType *)(op1)->metadata))); \
astTreeDestroy(*(op0)); \
- (op0)->metadata = (void *)(u64)res; \
+ (op0)->metadata = (void *)(bool)res; \
(op0)->type = &AST_TREE_BOOL_TYPE; \
+ (op0)->token = AST_TREE_TOKEN_VALUE_BOOL; \
}
#define doLeftOperation(op0, operator, originalType, type) \
@@ -164,7 +166,7 @@ void runnerVariableSetValue(RunnerVariablePages *pages,
}
}
- printError(variable->name_begin,variable->name_end,"Variable not found");
+ printError(variable->name_begin, variable->name_end, "Variable not found");
UNREACHABLE;
}
@@ -187,7 +189,7 @@ AstTree *runnerVariableGetValue(RunnerVariablePages *pages,
}
}
- printError(variable->name_begin,variable->name_end,"Variable not found");
+ printError(variable->name_begin, variable->name_end, "Variable not found");
UNREACHABLE;
}
@@ -343,14 +345,16 @@ AstTree *runExpression(AstTree *expr, RunnerVariablePages *pages) {
return NULL;
case AST_TREE_TOKEN_KEYWORD_IF: {
AstTreeIf *metadata = expr->metadata;
- AstTree *tree = runExpression(metadata->condition, pages);
+ AstTree *condition = runExpression(metadata->condition, pages);
AstTree *ret;
- if ((AstTreeBool)tree->metadata) {
+ if ((AstTreeBool)condition->metadata) {
ret = runExpression(metadata->ifBody, pages);
- } else {
+ } else if (metadata->elseBody != NULL) {
ret = runExpression(metadata->elseBody, pages);
+ } else {
+ ret = NULL;
}
- astTreeDelete(tree);
+ astTreeDelete(condition);
return ret;
}
case AST_TREE_TOKEN_KEYWORD_WHILE: {
diff --git a/test/main.felan b/test/main.felan
index 7d80a9c..5f19b06 100644
--- a/test/main.felan
+++ b/test/main.felan
@@ -1,6 +1,7 @@
main :: () -> void {
- a :u64= 2;
- a += (if a == 2 1 else 2);
- print_u64 a;
+ a := 2.3;
+ if a == 2.3
+ print_u64 1;
+ else
+ print_u64 2;
};
-