raiseException("ERROR: Incompatible types. Left of {} type can't be used with right of {} type on operation {}".format(self.left.myType.name,self.right.myType.name,self.op))
raiseException("ERROR: Incompatible types. Left of {} type can't be used with right of {} type on operation {}".format(self.left.myType.name,self.right.myType.name,self.op))
defcodeGen(self):
res=""
# Unary:
ifnotself.left:
returnres
res+=self.left.codeGen()# get left output
res+=p("push","eax",None,None)
res+=self.right.codeGen()# get right output
res+=p("pop","ebx",None,None)
ifself.opin['+','-','*','/','%']:
# operation -> generated code
ops={
'+':"add",
'-':"sub"
}
res+=p(ops[self.op],"ebx","eax",""+ops[self.op]+" left + right")
res+=p("mov","eax","ebx"," move result to eax")
returnres
# returns True, False, Int or None (for non-constant expr)
# returns True, False, Int or None (for non-constant expr)
# children of exprNode is either exprNode or literalNode
# children of exprNode is either exprNode or literalNode