From 636e6cbb161d0580702c4cab35ae548b2d176228 Mon Sep 17 00:00:00 2001 From: Nicholas Wesley Robinson <nwrobinson@uwaterloo.ca> Date: Mon, 13 Apr 2020 00:22:47 -0400 Subject: [PATCH] |& fix --- ExprPrimaryNodes.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index 1ff131b..da0eca1 100644 --- a/ExprPrimaryNodes.py +++ b/ExprPrimaryNodes.py @@ -660,12 +660,21 @@ class ExprNode(ASTNode): # eax = right result # so, basically do "eax = ebx op eax" - # Comparisons: - if self.op == '&': - self.code += p("and", "eax", "ebx", " right:eax " + self.op + " left:ebx") - return - if self.op == '|': - self.code += p("por", "eax", "ebx", " right:eax " + self.op + " left:ebx") + # Comparisons that don't short-circuit: + if self.op in ['|', '&']: + n = getCFlowLabel() + endLabel = "_end" + n + + if self.op == '|': + # if right = False, then we output left's result + self.code += p("cmp", "eax", "1") + elif self.op == '&': + # if right = True, then we output left's result + self.code += p("cmp", "eax", "0") + + self.code += p("je", endLabel) + self.code += p("mov", "eax", "ebx") + self.code += p(endLabel + ":", "") return # Binary operations: -- GitLab