Skip to content
Snippets Groups Projects
Commit 0230e4ab authored by Xun Yang's avatar Xun Yang
Browse files

divide by 0 check

parent 5cd44205
No related branches found
No related tags found
2 merge requests!30New new string,!20Master
......@@ -619,7 +619,7 @@ class ExprNode(ASTNode):
leftArg = ArgsNode(self.parseTree, self.typeName, [self.left])
# 3. Put it all together
concatLeft = MethodInvNode(self.parseTree, self.typeName, valueOfNameNode, leftArg)
if self.right.myType.name != 'java.lang.String':
# 2. Make ArgsNode
rightArg = ArgsNode(self.parseTree, self.typeName, [self.right])
......@@ -773,7 +773,7 @@ class ExprNode(ASTNode):
return
# Binary operations:
# Number Add, Subtract, Multiply
if self.op in ['+', '-', '*']:
# operation -> generated code
......@@ -791,6 +791,11 @@ class ExprNode(ASTNode):
# switch eax and ebx, because "idiv ebx" -> eax = edx:eax / ebx
self.code += p('xchg', 'eax', 'ebx')
# divide by 0 check
if self.op == '/':
self.code += p("cmp", "ebx", "0")
self.code += p("je", "H__Throw_Exception")
self.code += p('push', 'edx') # save edx in case someone else was using it
self.code += p('cdq', '', None, " set edx to the sign of eax")
self.code += p("idiv", "ebx", "", " left:eax " + self.op + " right:ebx")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment