diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index 1ff131bb618bc0b7b9937891039e3d8c16e0aa00..da0eca1b286a4bcec3ace7274b5e971996a23bb9 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: