From bf0f9a9348c60565722610c930d0081a28214760 Mon Sep 17 00:00:00 2001 From: SpookyDervish <78246495+SpookyDervish@users.noreply.github.com> Date: Tue, 14 Oct 2025 21:30:56 +1100 Subject: [PATCH] =?UTF-8?q?forgot=20about=20the=20not=20operator=20?= =?UTF-8?q?=F0=9F=A5=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler.py | 6 ++++ debug/ast.json | 90 -------------------------------------------------- debug/ir.ll | 17 ++++------ tests/test.pla | 10 +----- 4 files changed, 14 insertions(+), 109 deletions(-) delete mode 100644 debug/ast.json diff --git a/compiler.py b/compiler.py index 8492bb2..38ec926 100644 --- a/compiler.py +++ b/compiler.py @@ -218,6 +218,9 @@ class Compiler: case "==": value = self.builder.icmp_signed('==', left_value, right_value) Type = ir.IntType(1) + case "!=": + value = self.builder.icmp_signed('!=', left_value, right_value) + Type = ir.IntType(1) elif isinstance(right_type, ir.FloatType) and isinstance(left_type, ir.FloatType): Type = self.type_map["Float"] match operator: @@ -249,6 +252,9 @@ class Compiler: case "==": value = self.builder.fcmp_ordered('==', left_value, right_value) Type = ir.IntType(1) + case "!=": + value = self.builder.fcmp_ordered('!=', left_value, right_value) + Type = ir.IntType(1) return value, Type # endregion diff --git a/debug/ast.json b/debug/ast.json deleted file mode 100644 index 98f9c22..0000000 --- a/debug/ast.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "type": "Program", - "statements": [ - { - "FunctionStatement": { - "type": "FunctionStatement", - "name": { - "type": "IdentifierLiteral", - "value": "main" - }, - "return_type": "Int", - "parameters": [], - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "AssignmentStatement", - "name": { - "type": "IdentifierLiteral", - "value": "x" - }, - "value": { - "type": "IntegerLiteral", - "value": 123 - }, - "value_type": "Int" - }, - { - "type": "ExpressionStatement", - "expr": { - "type": "IfStatement", - "condition": { - "type": "InfixExpression", - "left_node": { - "type": "IdentifierLiteral", - "value": "x" - }, - "operator": "==", - "right_node": { - "type": "IntegerLiteral", - "value": 123 - } - }, - "consequence": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReassignStatement", - "ident": { - "type": "IdentifierLiteral", - "value": "x" - }, - "right_value": { - "type": "IntegerLiteral", - "value": 0 - } - } - ] - }, - "alternative": { - "type": "BlockStatement", - "statements": [ - { - "type": "ReassignStatement", - "ident": { - "type": "IdentifierLiteral", - "value": "x" - }, - "right_value": { - "type": "IntegerLiteral", - "value": 1 - } - } - ] - } - } - }, - { - "type": "ReturnStatement", - "return_value": { - "type": "IdentifierLiteral", - "value": "x" - } - } - ] - } - } - } - ] -} \ No newline at end of file diff --git a/debug/ir.ll b/debug/ir.ll index 9426d61..7e40bfa 100644 --- a/debug/ir.ll +++ b/debug/ir.ll @@ -7,18 +7,15 @@ target datalayout = "" define i32 @"main"() { main_entry: - %".2" = alloca i32 - store i32 6, i32* %".2" - %".4" = load i32, i32* %".2" - %".5" = icmp eq i32 %".4", 5 + %".2" = alloca float + store float 0x4014000000000000, float* %".2" + %".4" = load float, float* %".2" + %".5" = fcmp oeq float %".4", 0x4014000000000000 br i1 %".5", label %"main_entry.if", label %"main_entry.else" main_entry.if: - store i32 0, i32* %".2" - br label %"main_entry.endif" + ret i32 1 main_entry.else: - store i32 1, i32* %".2" - br label %"main_entry.endif" + ret i32 0 main_entry.endif: - %".11" = load i32, i32* %".2" - ret i32 %".11" + ret i32 0 } diff --git a/tests/test.pla b/tests/test.pla index 33bcbb7..f9a059e 100644 --- a/tests/test.pla +++ b/tests/test.pla @@ -1,11 +1,3 @@ main = Func(): Int { - x: Int = 123; - - if x == 123 { - x = 0; - } unless { - x = 1; - } - - return x; + } \ No newline at end of file