diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-28 00:48:10 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-01-28 00:48:10 +0330 |
commit | 12219a3af22fe4f17027dff43cfb459fef62eaa2 (patch) | |
tree | c70858a6ff43615e97344d880af72edd3dc09ab4 /src/compiler/code-generator.c | |
parent | 7a8b8ff4bee2373e1e0f3b2b1837dc25041e1a1d (diff) |
added constant values
Diffstat (limited to 'src/compiler/code-generator.c')
-rw-r--r-- | src/compiler/code-generator.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c index abe65f8..61d0092 100644 --- a/src/compiler/code-generator.c +++ b/src/compiler/code-generator.c @@ -80,9 +80,11 @@ CodeGeneratorCodes *codeGenerator(AstTreeRoot *astTreeRoot) { case AST_TREE_TOKEN_TYPE_FUNCTION: case AST_TREE_TOKEN_TYPE_VOID: case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_IDENTIFIER: + case AST_TREE_TOKEN_VARIABLE: case AST_TREE_TOKEN_KEYWORD_PRINT_U64: case AST_TREE_TOKEN_FUNCTION_CALL: + case AST_TREE_TOKEN_TYPE_U64: + case AST_TREE_TOKEN_VARIABLE_DEFINE: case AST_TREE_TOKEN_NONE: break; } @@ -108,11 +110,11 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, printLog("Not implemented"); exit(0); } - if (function->token != AST_TREE_TOKEN_IDENTIFIER) { + if (function->token != AST_TREE_TOKEN_VARIABLE) { printLog("Not implemented"); exit(0); } - AstTreeIdentifier *function_metadata = function->metadata; + AstTreeVariable *function_metadata = function->metadata; CodeGeneratorCall *callMetadata = a404m_malloc(sizeof(*callMetadata)); callMetadata->label_begin = function_metadata->name_begin; callMetadata->label_end = function_metadata->name_end; @@ -130,6 +132,13 @@ 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_VARIABLE) { + AstTreeVariable *variable = metadata->metadata; + CodeGeneratorOperandU64 value = (AstTreeU64)variable->value->metadata; + generateCodePushCode( + codes, createGenerateCode(label_begin, label_end, + CODE_GENERATOR_INSTRUCTION_PRINT_U64, + (void *)value)); } else { printLog("Not implemented yet"); exit(1); @@ -137,10 +146,12 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, } goto OK; case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_IDENTIFIER: + case AST_TREE_TOKEN_VARIABLE: case AST_TREE_TOKEN_FUNCTION: case AST_TREE_TOKEN_TYPE_FUNCTION: case AST_TREE_TOKEN_TYPE_VOID: + case AST_TREE_TOKEN_TYPE_U64: + case AST_TREE_TOKEN_VARIABLE_DEFINE: case AST_TREE_TOKEN_NONE: } printLog("Bad token %d", tree.token); |