diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-29 06:26:49 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-29 06:26:49 +0330 |
commit | 258ad19e6e03e1f1a93e16972cac1096a2d93e04 (patch) | |
tree | 4294fe5a39f4d148a0a616884036284de6dbc590 /src/compiler/code-generator.c | |
parent | f8019d33f61807de5369d78de6216427c56500dd (diff) |
add global variables
fix shadowing in different levels
better type checking
Diffstat (limited to 'src/compiler/code-generator.c')
-rw-r--r-- | src/compiler/code-generator.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c index 27a0fdc..1969016 100644 --- a/src/compiler/code-generator.c +++ b/src/compiler/code-generator.c @@ -77,11 +77,18 @@ CodeGeneratorCodes *codeGenerator(AstTreeRoot *astTreeRoot) { return NULL; } continue; + case AST_TREE_TOKEN_VALUE_U64: { + CodeGeneratorOperandU64 value = (AstTreeU64)variable->value->metadata; + generateCodePushCode( + codes, createGenerateCode(variable->name_begin, variable->name_end, + CODE_GENERATOR_INSTRUCTION_PRINT_U64, + (void *)value)); + } + continue; case AST_TREE_TOKEN_TYPE_TYPE: case AST_TREE_TOKEN_TYPE_FUNCTION: case AST_TREE_TOKEN_TYPE_VOID: - case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_CONSTANT: + case AST_TREE_TOKEN_VARIABLE: case AST_TREE_TOKEN_KEYWORD_PRINT_U64: case AST_TREE_TOKEN_FUNCTION_CALL: case AST_TREE_TOKEN_TYPE_U64: @@ -110,7 +117,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, printLog("Not implemented"); exit(0); } - if (function->token != AST_TREE_TOKEN_CONSTANT) { + if (function->token != AST_TREE_TOKEN_VARIABLE) { printLog("Not implemented"); exit(0); } @@ -132,7 +139,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, codes, createGenerateCode(label_begin, label_end, CODE_GENERATOR_INSTRUCTION_PRINT_U64, (void *)value)); - } else if (metadata->token == AST_TREE_TOKEN_CONSTANT) { + } else if (metadata->token == AST_TREE_TOKEN_VARIABLE) { AstTreeVariable *variable = metadata->metadata; CodeGeneratorOperandU64 value = (AstTreeU64)variable->value->metadata; generateCodePushCode( @@ -146,7 +153,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, } goto OK; case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_CONSTANT: + case AST_TREE_TOKEN_VARIABLE: case AST_TREE_TOKEN_FUNCTION: case AST_TREE_TOKEN_TYPE_TYPE: case AST_TREE_TOKEN_TYPE_FUNCTION: @@ -168,8 +175,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, return true; } -static const char TEMPLATE[] = - "include 'stdlib/main.asm'\n"; +static const char TEMPLATE[] = "include 'stdlib/main.asm'\n"; static const size_t TEMPLATE_LEN = sizeof(TEMPLATE) / sizeof(*TEMPLATE) - sizeof(*TEMPLATE); |