about summary refs log tree commit diff
path: root/src/bootstrap/codegen.pry
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-07-09 22:15:36 +0200
committerBaitinq <[email protected]>2025-07-09 22:15:36 +0200
commite17c3c2e297168aa3268b70cbd3a3d692bdde951 (patch)
tree6641768f70486c5387d7cf1614e6aaf6d9a9f4b8 /src/bootstrap/codegen.pry
parentBootstrap: Support if statement (diff)
downloadpry-lang-e17c3c2e297168aa3268b70cbd3a3d692bdde951.tar.gz
pry-lang-e17c3c2e297168aa3268b70cbd3a3d692bdde951.tar.bz2
pry-lang-e17c3c2e297168aa3268b70cbd3a3d692bdde951.zip
Bootstrap: Support equality expressions
Diffstat (limited to 'src/bootstrap/codegen.pry')
-rw-r--r--src/bootstrap/codegen.pry49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/bootstrap/codegen.pry b/src/bootstrap/codegen.pry
index 8b95451..c115da9 100644
--- a/src/bootstrap/codegen.pry
+++ b/src/bootstrap/codegen.pry
@@ -474,6 +474,55 @@ let codegen_generate_expression_value = (c: *codegen, expression: *Node, name: *
 		return codegen_create_variable(c, v);
 	};
 	
+	if ((*expression).type == NODE_EQUALITY_EXPRESSION) {
+		let exp = (*(cast(*NODE_EQUALITY_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 op = -1;
+
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_EQ {
+			op = LLVMIntEQ;
+		};
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_NE {
+			op = LLVMIntNE;
+		};
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_GE {
+			op = LLVMIntSGE;
+		};
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_LE {
+			op = LLVMIntSLE;
+		};
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_LT {
+			op = LLVMIntSLT;
+		};
+		if exp.typ == EQUALITY_EXPRESSION_TYPE_GT {
+			op = LLVMIntSGT;
+		};
+
+		assert(op != -1);
+
+		let cmp = LLVMBuildICmp((*c).builder, cast(LLVMIntPredicate, op), (*lhs_value).value, (*rhs_value).value, "");
+
+
+		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 = "bool";
+		(*d).underlying_type = cast(*Node, null);
+		node_type.data = cast(*void, d);
+
+		return codegen_generate_literal(c, cmp, name, expression, create_node(c, node_type));
+	};
+	
 	if ((*expression).type == NODE_TYPE_FUNCTION_TYPE) {
 		let e = *((*c).environment);
 		printf("LLEL\n");