diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-03-27 07:35:58 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-03-27 07:35:58 +0330 |
commit | 8ed01c4ca2d2356f008b40d8498173009f71d295 (patch) | |
tree | 931cd58461da6a137d7e6615657d7c7eb5bf1ed3 | |
parent | 4c7d3c1d1e71823efc47a78ef8a608ee1656b035 (diff) |
fix bug in multiple dereference
-rw-r--r-- | code/main.felan | 20 | ||||
-rw-r--r-- | src/compiler/parser.c | 5 | ||||
-rw-r--r-- | src/runner/runner.c | 3 |
3 files changed, 23 insertions, 5 deletions
diff --git a/code/main.felan b/code/main.felan index c994d63..08da789 100644 --- a/code/main.felan +++ b/code/main.felan @@ -1,12 +1,28 @@ main :: () -> void { a :u64= 1; b :*u64 = &a; + c :**u64 = &b; print_u64 b.*; print_u64 a; - b.* = 2; + a = 2; print_u64 b.*; print_u64 a; - a = 3; + b.* = 3; print_u64 b.*; print_u64 a; + foo(a); + print_u64 b.*; + print_u64 a; + bar(b); + print_u64 b.*; + print_u64 a; + print_u64 c.*.*; +}; + +foo :: (a:u64)->void{ + a = 4; +}; + +bar :: (a:*u64)->void{ + a.* = 5; }; diff --git a/src/compiler/parser.c b/src/compiler/parser.c index 17d596b..2ab8860 100644 --- a/src/compiler/parser.c +++ b/src/compiler/parser.c @@ -105,7 +105,8 @@ static constexpr ParserOrder PARSER_ORDER[] = { }, { .ltr = false, - ORDER_ARRAY(LEXER_TOKEN_SYMBOL_FUNCTION_ARROW, ), + ORDER_ARRAY(LEXER_TOKEN_SYMBOL_FUNCTION_ARROW, + LEXER_TOKEN_SYMBOL_POINTER, ), }, { .ltr = true, @@ -114,7 +115,7 @@ static constexpr ParserOrder PARSER_ORDER[] = { { .ltr = true, ORDER_ARRAY(LEXER_TOKEN_SYMBOL_PLUS, LEXER_TOKEN_SYMBOL_MINUS, - LEXER_TOKEN_SYMBOL_POINTER, LEXER_TOKEN_SYMBOL_ADDRESS, ), + LEXER_TOKEN_SYMBOL_ADDRESS, ), }, { .ltr = true, diff --git a/src/runner/runner.c b/src/runner/runner.c index efb91ee..4966893 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -868,7 +868,8 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet) { case AST_TREE_TOKEN_OPERATOR_DEREFERENCE: { AstTreeSingleChild *metadata = expr->metadata; AstTree *operand = runExpression(metadata, shouldRet); - if (metadata->token != AST_TREE_TOKEN_VARIABLE) { + if (operand->token != AST_TREE_TOKEN_VARIABLE) { + printLog("%s", AST_TREE_TOKEN_STRINGS[operand->token]); UNREACHABLE; } AstTreeVariable *variable = operand->metadata; |