From 9e0005e248a26cb8f8ecc5138756a9157bf899b5 Mon Sep 17 00:00:00 2001 From: A404M Date: Sat, 14 Jun 2025 13:46:46 +0330 Subject: fix some bugs implemented another raylib example --- src/compiler/ast-tree.c | 32 +++++++++++++++++++++++++++++++- src/runner/runner.c | 3 ++- 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index 280b820..ad696f6 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -6255,6 +6255,36 @@ bool setTypesOperatorGeneral(AstTree *tree, AstTreeSetTypesHelper _helper, copyAstTree(variable->type), NULL, NULL); if (metadata->function->type->token == AST_TREE_TOKEN_TYPE_FUNCTION) { AstTreeTypeFunction *function = metadata->function->type->metadata; + tree->type = copyAstTree(function->returnType); + } else if (metadata->function->type->token == AST_TREE_TOKEN_TYPE_MACRO) { + metadata->function = getValue(metadata->function, false, helper.scope); + if (metadata->function->token != AST_TREE_TOKEN_VALUE_MACRO) { + UNREACHABLE; + } + AstTreeMacro *macro = metadata->function->metadata; + AstTreeFunction *function = + copyAstTreeFunction(macro->function, NULL, NULL, 0, true); + + if (!setTypesAstFunction(function, NULL, helper)) { + astTreeFunctionDestroy(*function); + free(function); + return false; + } + + AstTree *functionType = makeTypeOfFunction(function, NULL, NULL); + + if (!doesFunctionMatch(functionType->metadata, metadata, helper)) { + printError(tree->str_begin, tree->str_end, "Function call doesn't match"); + return NULL; + } + + const char *str_begin = metadata->function->str_begin; + const char *str_end = metadata->function->str_end; + astTreeDelete(metadata->function); + + metadata->function = newAstTree(AST_TREE_TOKEN_FUNCTION, function, + functionType, str_begin, str_end); + tree->type = copyAstTree(function->returnType); } else if (metadata->function->type->token == AST_TREE_TOKEN_TYPE_SHAPE_SHIFTER) { @@ -6266,6 +6296,7 @@ bool setTypesOperatorGeneral(AstTree *tree, AstTreeSetTypesHelper _helper, AstTreeTypeFunction *functionType = metadata->function->type->metadata; tree->type = copyAstTree(functionType->returnType); } else { + printLog("%s", AST_TREE_TOKEN_STRINGS[metadata->function->type->token]); UNREACHABLE; } @@ -8313,7 +8344,6 @@ AstTree *getShapeShifterElement(AstTreeFunctionCall *metadata, shapeShifter->generateds.functions = a404m_realloc( shapeShifter->generateds.functions, generateds_size * sizeof(*shapeShifter->generateds.functions)); - printLog("%ld", generateds_size); shapeShifter->generateds.calls = a404m_realloc( shapeShifter->generateds.calls, generateds_size * sizeof(*shapeShifter->generateds.calls)); diff --git a/src/runner/runner.c b/src/runner/runner.c index f376710..c9f2dd1 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -7,8 +7,8 @@ #include "utils/type.h" #include #include -#include #include +#include #define doOperation(op0, op1, operator, originalType, type) \ *((originalType *)(op0)->metadata) = \ @@ -1284,6 +1284,7 @@ AstTree *runAstTreeCFunction(AstTree *tree, AstTree **arguments, [((AstTreeSingleChild *)arguments[i]->type->metadata)->token]); UNREACHABLE; } else if (arguments[i]->token != AST_TREE_TOKEN_RAW_VALUE) { + printLog("%s", AST_TREE_TOKEN_STRINGS[arguments[i]->type->token]); UNREACHABLE; } values[i] = arguments[i]->metadata; -- cgit v1.2.3