From 40881a903e00939b647cd85beeacfb8a68b31e6a Mon Sep 17 00:00:00 2001 From: A404M Date: Sun, 15 Jun 2025 06:18:41 +0330 Subject: fix the issue in variable scopes --- README.md | 2 +- code/main.felan | 26 +++++++++++++------------- src/compiler/ast-tree.c | 19 +++++++++++++++++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 3d6edc3..f1f4dbb 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ main :: () -> void { * ~Overloading [] operator~ * ~Add code injection~ * ~Add macro~ -* Fix scope bug in shape shifters +* ~Fix scope bug in shape shifters~ * Add \u and \x to char * Add vararg * Add enum diff --git a/code/main.felan b/code/main.felan index e284423..b8b41ec 100644 --- a/code/main.felan +++ b/code/main.felan @@ -31,20 +31,20 @@ TITLE :: 1; GAMEPLAY :: 2; ENDING :: 3; -main :: () -> void { - SCREEN_WIDTH :: 800i32; - SCREEN_HEIGHT :: 450i32; - - RAYWHITE :: color(245u8,245u8,245u8,255u8); - LIGHTGRAY :: color(200u8,200u8,200u8,255u8); - GRAY :: color(130u8,130u8,130u8,255u8); - GREEN :: color(0u8,228u8,48u8,255u8); - DARKGREEN :: color(0u8,117u8,44u8,255u8); - BLUE :: color(0u8,121u8,241u8,255u8); - DARKBLUE :: color(0u8,82u8,172u8,255u8); - PURPLE :: color(200u8,122u8,255u8,255u8); - MAROON :: color(100u8,33u8,55u8,255u8); +SCREEN_WIDTH :: 800i32; +SCREEN_HEIGHT :: 450i32; + +RAYWHITE :: color(245u8,245u8,245u8,255u8); +LIGHTGRAY :: color(200u8,200u8,200u8,255u8); +GRAY :: color(130u8,130u8,130u8,255u8); +GREEN :: color(0u8,228u8,48u8,255u8); +DARKGREEN :: color(0u8,117u8,44u8,255u8); +BLUE :: color(0u8,121u8,241u8,255u8); +DARKBLUE :: color(0u8,82u8,172u8,255u8); +PURPLE :: color(200u8,122u8,255u8,255u8); +MAROON :: color(100u8,33u8,55u8,255u8); +main :: () -> void { title := "Hello\0"; InitWindow(SCREEN_WIDTH,SCREEN_HEIGHT,title.ptr); diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index 6596245..057e96d 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -6359,6 +6359,23 @@ bool setTypesVariableDefine(AstTree *tree, AstTreeSetTypesHelper helper) { bool setTypesAstVariable(AstTreeVariable *variable, AstTreeSetTypesHelper _helper) { + for (size_t i = 0; i < _helper.variables[0].size; ++i) { // TODO: change this + if (variable == _helper.variables[0].data[i]) { + _helper = (AstTreeSetTypesHelper){ + .root = _helper.root, + .variables = _helper.variables, + .variables_size = 1, + .dependencies = _helper.dependencies, + .lookingType = _helper.lookingType, + .loops = _helper.loops, + .loops_size = _helper.loops_size, + .scope = _helper.scope, + .isInScope = false, + }; + break; + } + } + AstTreeVariable *deps[_helper.dependencies.size + 1]; for (size_t i = 0; i < _helper.dependencies.size; ++i) { @@ -7382,7 +7399,6 @@ bool setTypesBuiltinBinaryAlsoPointer(AstTree *tree, } else if (left->type->token == AST_TREE_TOKEN_OPERATOR_POINTER && !typeIsEqual(right->type, &AST_TREE_I64_TYPE, helper.scope) && !typeIsEqual(right->type, &AST_TREE_U64_TYPE, helper.scope)) { - *(u8 *)0 = 0; printError(tree->str_begin, tree->str_end, "Pointer can only have right hand as u64 or i64"); return false; @@ -8208,7 +8224,6 @@ AstTreeVariable *setTypesFindVariable(const char *name_begin, for (size_t i = 0; i < helper.variables_size; ++i) { printLog("is %ld", helper.variables[i].size); } - *(u8 *)0 = 0; printError(name_begin, name_end, "No candidates found for %.*s", (int)(name_end - name_begin), name_begin); return NULL; -- cgit v1.2.3