forgot about the not operator 🥀
This commit is contained in:
@@ -218,6 +218,9 @@ class Compiler:
|
|||||||
case "==":
|
case "==":
|
||||||
value = self.builder.icmp_signed('==', left_value, right_value)
|
value = self.builder.icmp_signed('==', left_value, right_value)
|
||||||
Type = ir.IntType(1)
|
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):
|
elif isinstance(right_type, ir.FloatType) and isinstance(left_type, ir.FloatType):
|
||||||
Type = self.type_map["Float"]
|
Type = self.type_map["Float"]
|
||||||
match operator:
|
match operator:
|
||||||
@@ -249,6 +252,9 @@ class Compiler:
|
|||||||
case "==":
|
case "==":
|
||||||
value = self.builder.fcmp_ordered('==', left_value, right_value)
|
value = self.builder.fcmp_ordered('==', left_value, right_value)
|
||||||
Type = ir.IntType(1)
|
Type = ir.IntType(1)
|
||||||
|
case "!=":
|
||||||
|
value = self.builder.fcmp_ordered('!=', left_value, right_value)
|
||||||
|
Type = ir.IntType(1)
|
||||||
|
|
||||||
return value, Type
|
return value, Type
|
||||||
# endregion
|
# 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"()
|
define i32 @"main"()
|
||||||
{
|
{
|
||||||
main_entry:
|
main_entry:
|
||||||
%".2" = alloca i32
|
%".2" = alloca float
|
||||||
store i32 6, i32* %".2"
|
store float 0x4014000000000000, float* %".2"
|
||||||
%".4" = load i32, i32* %".2"
|
%".4" = load float, float* %".2"
|
||||||
%".5" = icmp eq i32 %".4", 5
|
%".5" = fcmp oeq float %".4", 0x4014000000000000
|
||||||
br i1 %".5", label %"main_entry.if", label %"main_entry.else"
|
br i1 %".5", label %"main_entry.if", label %"main_entry.else"
|
||||||
main_entry.if:
|
main_entry.if:
|
||||||
store i32 0, i32* %".2"
|
ret i32 1
|
||||||
br label %"main_entry.endif"
|
|
||||||
main_entry.else:
|
main_entry.else:
|
||||||
store i32 1, i32* %".2"
|
ret i32 0
|
||||||
br label %"main_entry.endif"
|
|
||||||
main_entry.endif:
|
main_entry.endif:
|
||||||
%".11" = load i32, i32* %".2"
|
ret i32 0
|
||||||
ret i32 %".11"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
main = Func(): Int {
|
main = Func(): Int {
|
||||||
x: Int = 123;
|
|
||||||
|
|
||||||
if x == 123 {
|
|
||||||
x = 0;
|
|
||||||
} unless {
|
|
||||||
x = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user