about summary refs log tree commit diff
path: root/src/bootstrap/codegen.pry
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-07-11 00:30:28 +0200
committerBaitinq <[email protected]>2025-07-11 00:32:50 +0200
commit055fbcfb9db4087cde5f102c0753999f569b2f35 (patch)
tree5f2189b3dfc89d725f6f372c9ca3cb05424c9ae1 /src/bootstrap/codegen.pry
parentBootstrap: Support variable assignment (diff)
downloadpry-lang-055fbcfb9db4087cde5f102c0753999f569b2f35.tar.gz
pry-lang-055fbcfb9db4087cde5f102c0753999f569b2f35.tar.bz2
pry-lang-055fbcfb9db4087cde5f102c0753999f569b2f35.zip
Bootstrap: Support addition
Diffstat (limited to 'src/bootstrap/codegen.pry')
-rw-r--r--src/bootstrap/codegen.pry47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/bootstrap/codegen.pry b/src/bootstrap/codegen.pry
index 53453f1..1a81c42 100644
--- a/src/bootstrap/codegen.pry
+++ b/src/bootstrap/codegen.pry
@@ -525,6 +525,53 @@ let codegen_generate_expression_value = (c: *codegen, expression: *Node, name: *
 		return codegen_generate_literal(c, cmp, name, expression, create_node(c, node_type));
 	};
 	
+	if ((*expression).type == NODE_ADDITIVE_EXPRESSION) {
+		let exp = (*(cast(*NODE_ADDITIVE_EXPRESSION_DATA, (*expression).data)));
+		let lhs_value = codegen_generate_expression_value(c, exp.lhs, cast(*i8, null));
+		if lhs_value == cast(*Variable, null) {
+			return cast(*Variable, null);
+		};
+		let rhs_value = codegen_generate_expression_value(c, exp.rhs, cast(*i8, null));
+		if rhs_value == cast(*Variable, null) {
+			return cast(*Variable, null);
+		};
+
+		/* TODO: Compare types */
+
+		let result = cast(LLVMValueRef, null);
+		let node_type = Node{};
+		node_type.type = NODE_TYPE_SIMPLE_TYPE;
+
+		let d = cast(*NODE_TYPE_SIMPLE_TYPE_DATA, arena_alloc((*c).arena, sizeof(NODE_TYPE_SIMPLE_TYPE_DATA)));
+		(*d).name = "i64";
+		(*d).underlying_type = cast(*Node, null);
+		node_type.data = cast(*void, d);
+
+		let pnode_type = create_node(c, node_type);
+
+		if exp.addition {
+			let nt = (*lhs_value).node_type;
+			if (*nt).type == NODE_TYPE_POINTER_TYPE {
+				let ipt = cast(*NODE_TYPE_POINTER_TYPE_DATA, (*nt).data);
+				let llvmipt = codegen_get_llvm_type(c, (*ipt).type);
+				assert(llvmipt != cast(*LLVMTypeRef, null));
+				let arr = cast(*LLVMValueRef, arena_alloc((*c).arena, sizeof(LLVMValueRef) * 1));
+				(*(arr + cast(*LLVMValueRef, 0))) = (*rhs_value).value;
+				result = LLVMBuildGEP2((*c).builder, *llvmipt, (*lhs_value).value, arr, 1, "");
+				pnode_type = (*lhs_value).node_type;
+			};
+			if (*nt).type != NODE_TYPE_POINTER_TYPE {
+                        	result = LLVMBuildAdd((*c).builder, (*lhs_value).value, (*rhs_value).value, "");
+			};
+
+		};
+		if !exp.addition {
+			result = LLVMBuildSub((*c).builder, (*lhs_value).value, (*rhs_value).value, "");
+		};
+
+		return codegen_generate_literal(c, result, name, expression, pnode_type);
+	};
+	
 	if ((*expression).type == NODE_UNARY_EXPRESSION) {
 		let exp = (*(cast(*NODE_UNARY_EXPRESSION_DATA, (*expression).data)));
 		let k = codegen_generate_expression_value(c, exp.expression, cast(*i8, null));