From 6bd439f35c1184f04488ee4f0db21632e1301b51 Mon Sep 17 00:00:00 2001 From: A404M Date: Fri, 7 Feb 2025 21:14:11 +0330 Subject: add plus trying to add return --- src/compiler/code-generator.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/compiler/code-generator.c') 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; } -- cgit v1.2.3