forgot about the not operator 🥀
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
17
debug/ir.ll
17
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
|
||||
}
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
main = Func(): Int {
|
||||
x: Int = 123;
|
||||
|
||||
if x == 123 {
|
||||
x = 0;
|
||||
} unless {
|
||||
x = 1;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user