a bit more cleanup, all boolean logic works except not
This commit is contained in:
@@ -354,8 +354,8 @@ class X86_64Generator(Generator):
|
||||
self.get_variable(node.arguments[0].var_name, "eax")
|
||||
self.lines.append(f"test eax, eax\n\t")
|
||||
self.lines.append(f"jnz .{node.arguments[1].name}\n\t")
|
||||
|
||||
elif node.instruction == "equal":
|
||||
|
||||
elif node.instruction in ["equal", "inequal", "greater", "lesser"]:
|
||||
if len(node.arguments) != 3: # example: "equal" or "equal $bool"
|
||||
traceback(self.code, "TypeError", "equal expects exactly 3 arguments.")
|
||||
elif not type(node.arguments[0]) in [VarRefNode,BoolNode,FloatNode,IntNode]:
|
||||
@@ -397,60 +397,17 @@ class X86_64Generator(Generator):
|
||||
arg2 = "rbx"
|
||||
|
||||
self.lines.append(f"cmp {arg1}, {arg2}\n\t")
|
||||
self.lines.append("sete al\n\t")
|
||||
|
||||
instructions = {
|
||||
"equal": "sete",
|
||||
"inequal": "setne",
|
||||
"greater": "setg",
|
||||
"lesser": "setl"
|
||||
}
|
||||
self.lines.append(f"{instructions[node.instruction]} al\n\t")
|
||||
self.lines.append("movzx rax, al\n\t")
|
||||
|
||||
var_name = node.arguments[2].var_name
|
||||
if self.variables.get(var_name, None) == None:
|
||||
self.create_variable(var_name, "rax", BoolNode)
|
||||
else:
|
||||
self.change_variable(var_name, "rax")
|
||||
|
||||
elif node.instruction == "inequal":
|
||||
if len(node.arguments) != 3: # example: "inequal" or "inequal $bool"
|
||||
traceback(self.code, "TypeError", "inequal expects exactly 3 arguments.")
|
||||
elif not type(node.arguments[0]) in [VarRefNode,BoolNode,FloatNode,IntNode]:
|
||||
traceback(self.code, "TypeError", f"inequal expects a value or variable refernce as the first argument, not \"{node.arguments[0].__repr__()}\"")
|
||||
elif not type(node.arguments[1]) in [VarRefNode,BoolNode,FloatNode,IntNode]:
|
||||
traceback(self.code, "TypeError", f"inequal expects a value or variable refernce as the second argument, not \"{node.arguments[1].__repr__()}\"")
|
||||
elif not isinstance(node.arguments[2], VarPointerNode):
|
||||
traceback(self.code, "TypeError", f"the third argument of inequal should be a variable pointer, not \"{node.arguments[2].__repr__()}\"")
|
||||
|
||||
arg1 = None
|
||||
arg2 = None
|
||||
|
||||
if isinstance(node.arguments[0], BoolNode):
|
||||
self.lines.append(f"mov rax, {int(node.arguments[0].value)}\n\t")
|
||||
arg1 = "rax"
|
||||
elif isinstance(node.arguments[0], IntNode):
|
||||
self.lines.append(f"mov rax, {node.arguments[0].value}\n\t")
|
||||
arg1 = "rax"
|
||||
elif isinstance(node.arguments[0], FloatNode):
|
||||
const_name = self.add_constant(node.arguments[0].value)
|
||||
self.lines.append(f"movsd xmm0, {const_name}\n\t")
|
||||
arg1 = "xmm0"
|
||||
elif isinstance(node.arguments[0], VarRefNode):
|
||||
self.get_variable(node.arguments[0].var_name, "rax")
|
||||
arg1 = "rax"
|
||||
|
||||
if isinstance(node.arguments[1], BoolNode):
|
||||
self.lines.append(f"mov rbx, {int(node.arguments[1].value)}\n\t")
|
||||
arg2 = "rbx"
|
||||
elif isinstance(node.arguments[1], IntNode):
|
||||
self.lines.append(f"mov rbx, {node.arguments[1].value}\n\t")
|
||||
arg2 = "rbx"
|
||||
elif isinstance(node.arguments[1], FloatNode):
|
||||
const_name = self.add_constant(node.arguments[1].value)
|
||||
self.lines.append(f"movsd xmm1, {const_name}\n\t")
|
||||
arg2 = "xmm1"
|
||||
elif isinstance(node.arguments[1], VarRefNode):
|
||||
self.get_variable(node.arguments[1].var_name, "rbx")
|
||||
arg2 = "rbx"
|
||||
|
||||
self.lines.append(f"cmp {arg1}, {arg2}\n\t")
|
||||
self.lines.append("setne al\n\t")
|
||||
self.lines.append("movzx rax, al\n\t")
|
||||
|
||||
var_name = node.arguments[2].var_name
|
||||
if self.variables.get(var_name, None) == None:
|
||||
self.create_variable(var_name, "rax", BoolNode)
|
||||
|
Reference in New Issue
Block a user