From ce253ec2ae45879b331d9b9f77f786b78fbfcf2e Mon Sep 17 00:00:00 2001 From: A404M Date: Thu, 30 Jan 2025 09:20:48 +0330 Subject: fix bugs --- src/compiler/ast-tree.c | 23 ++++++++++++++--------- src/compiler/ast-tree.h | 2 +- src/compiler/code-generator.c | 4 ++-- test/main.felan | 16 +++++++++++----- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index c38a4b8..097e45b 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -919,18 +919,22 @@ ERROR: exit(1); } -bool isFunction(AstTree *value) { +AstTreeFunction *getFunction(AstTree *value) { switch (value->token) { case AST_TREE_TOKEN_FUNCTION: - return true; + return value->metadata; case AST_TREE_TOKEN_FUNCTION_CALL: { AstTreeFunctionCall *metadata = value->metadata; AstTreeFunction *function = metadata->function->metadata; - return isFunction(function->returnType); + return getFunction(function->returnType); } case AST_TREE_TOKEN_VARIABLE: { AstTreeVariable *metadata = value->metadata; - return metadata->type->token == AST_TREE_TOKEN_TYPE_FUNCTION; + if (metadata->type->token == AST_TREE_TOKEN_TYPE_FUNCTION) { + return metadata->value->metadata; + } else { + return NULL; + } } case AST_TREE_TOKEN_KEYWORD_PRINT_U64: case AST_TREE_TOKEN_TYPE_TYPE: @@ -939,7 +943,7 @@ bool isFunction(AstTree *value) { case AST_TREE_TOKEN_TYPE_U64: case AST_TREE_TOKEN_VALUE_U64: case AST_TREE_TOKEN_VARIABLE_DEFINE: - return false; + return NULL; case AST_TREE_TOKEN_NONE: } printLog("Bad token '%d'", value->token); @@ -1147,14 +1151,15 @@ bool setTypesFunctionCall(AstTree *tree) { return false; } - if (isFunction(metadata->function)) { + if (!setAllTypes(metadata->function)) { printLog("Type mismatch"); return false; } - AstTreeFunction *function = metadata->function->metadata; - if (function->arguments.size != metadata->parameters_size) { - printLog("Not yet supported"); + AstTreeFunction *function = getFunction(metadata->function); + if (function == NULL || function->arguments.size != metadata->parameters_size) { + printLog("Arguments doesn't match %ld != %ld", function->arguments.size, + metadata->parameters_size); return false; } diff --git a/src/compiler/ast-tree.h b/src/compiler/ast-tree.h index 2e43973..645ef5f 100644 --- a/src/compiler/ast-tree.h +++ b/src/compiler/ast-tree.h @@ -140,7 +140,7 @@ AstTree *astTreeParseVariable(ParserNode *parserNode, size_t variables_size); bool hasTypeOf(AstTree *value, const AstTree *type); -bool isFunction(AstTree *value); +AstTreeFunction* getFunction(AstTree *value); bool isConst(AstTree *value); AstTree *makeTypeOf(AstTree *value); bool typeIsEqual(const AstTree *type0, const AstTree *type1); diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c index 4ddfe94..24f0699 100644 --- a/src/compiler/code-generator.c +++ b/src/compiler/code-generator.c @@ -348,9 +348,9 @@ char *codeGeneratorToFlatASM(const CodeGeneratorCodes *codes) { CodeGeneratorOperand *metadata = code.metadata; char *inst; if (metadata->isReference) { - asprintf(&inst, "db [%s]\n", metadata->value); + asprintf(&inst, "dq [%s]\n", metadata->value); } else { - asprintf(&inst, "db %s\n", metadata->value); + asprintf(&inst, "dq %s\n", metadata->value); } codeGeneratorAppendFlatASMCommand(&fasm, &fasm_size, &fasm_inserted, inst, strlen(inst)); diff --git a/test/main.felan b/test/main.felan index cbbc0ef..ef82130 100644 --- a/test/main.felan +++ b/test/main.felan @@ -1,9 +1,15 @@ main :: () -> void { - print_u64 b; - b = 3; - print_u64 b; - b = 7; - print_u64 b; + fun(); + a = 2; + fun(); + a = b; + fun(); }; +a := 1; b := 124; + +fun :: ()->void { + print_u64 a; +}; + -- cgit v1.2.3