summaryrefslogtreecommitdiff
path: root/src/compiler/code-generator.c
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-02-07 21:14:11 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-02-07 21:14:11 +0330
commit6bd439f35c1184f04488ee4f0db21632e1301b51 (patch)
tree369766b11ef80c33dfca262deae0051e5343aaa5 /src/compiler/code-generator.c
parentb89bec88a56b81d3524ed082db9796ef3169b060 (diff)
add plus
trying to add return
Diffstat (limited to 'src/compiler/code-generator.c')
-rw-r--r--src/compiler/code-generator.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c
index 6ef6807..ab7583e 100644
--- a/src/compiler/code-generator.c
+++ b/src/compiler/code-generator.c
@@ -132,6 +132,7 @@ CodeGeneratorOperand *newCodeGeneratorOperandFromAstTree(AstTree tree) {
case AST_TREE_TOKEN_FUNCTION_CALL:
case AST_TREE_TOKEN_VARIABLE_DEFINE:
case AST_TREE_TOKEN_OPERATOR_ASSIGN:
+ case AST_TREE_TOKEN_OPERATOR_SUM:
case AST_TREE_TOKEN_NONE:
}
UNREACHABLE;
@@ -232,6 +233,7 @@ CodeGeneratorCodes *codeGenerator(AstTreeRoot *astTreeRoot) {
case AST_TREE_TOKEN_TYPE_U64:
case AST_TREE_TOKEN_VARIABLE_DEFINE:
case AST_TREE_TOKEN_OPERATOR_ASSIGN:
+ case AST_TREE_TOKEN_OPERATOR_SUM:
case AST_TREE_TOKEN_NONE:
break;
}
@@ -325,7 +327,7 @@ bool codeGeneratorAstTreeFunction(char *name_begin, char *name_end,
newCodeGeneratorOperandFromAstTree(infix->right);
operands->op0 = *op0;
operands->op1 = *op1;
- operands->bytes = astTreeTypeSize(infix->leftType);
+ operands->bytes = astTreeTypeSize(*infix->left.type);
free(op0);
free(op1);
@@ -334,6 +336,30 @@ bool codeGeneratorAstTreeFunction(char *name_begin, char *name_end,
operands));
}
goto OK;
+ case AST_TREE_TOKEN_OPERATOR_SUM: {
+ AstTreeInfix *infix = tree.metadata;
+
+ if (infix->left.token != AST_TREE_TOKEN_VARIABLE) {
+ printLog("Not implemented yet");
+ exit(1);
+ }
+
+ CodeGeneratorMov *operands = a404m_malloc(sizeof(*operands));
+ CodeGeneratorOperand *op0 =
+ newCodeGeneratorOperandFromAstTree(infix->left);
+ CodeGeneratorOperand *op1 =
+ newCodeGeneratorOperandFromAstTree(infix->right);
+ operands->op0 = *op0;
+ operands->op1 = *op1;
+ operands->bytes = astTreeTypeSize(*infix->left.type);
+ free(op0);
+ free(op1);
+
+ generateCodePushCode(
+ codes, createGenerateCode(NULL, NULL, CODE_GENERATOR_INSTRUCTION_ADD,
+ operands));
+ }
+ goto OK;
case AST_TREE_TOKEN_VARIABLE_DEFINE:
case AST_TREE_TOKEN_VALUE_U64:
case AST_TREE_TOKEN_VARIABLE:
@@ -488,6 +514,8 @@ char *codeGeneratorToFlatASM(const CodeGeneratorCodes *codes) {
free(inst);
}
continue;
+ case CODE_GENERATOR_INSTRUCTION_ADD: {
+ }
}
UNREACHABLE;
}