Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mostly correctness fixes, bug in xor assembler

  • Loading branch information...
commit 9f1ea0f8786b0424fccdb549c6244e61171006c6 1 parent 923b359
@evilpie authored
View
18 compiler.py
@@ -230,11 +230,7 @@ def op_unary_minus(self, node):
self.frame.push_double(-0)
elif lhs.is_undefined():
self.frame.push_double(float('nan'))
-
- return
-
-
- if lhs.is_int():
+ elif lhs.is_int():
reg = lhs.to_reg()
self.frame.pop()
@@ -249,6 +245,8 @@ def unary_minus(lhs):
result = self.frame.alloc_reg()
self.assembler.mov(result, eax)
+
+ self.frame.pop()
self.frame.push('unknown', result)
def op_unary_plus(self, node):
@@ -319,7 +317,8 @@ def op_not(self, node):
raise NotImplementedError('op not')
self.frame.pop()
- self.assembler.push('bool', reg)
+ self.frame.take_reg(reg)
+ self.frame.push('bool', reg)
def op_void(self, node):
self.compile_node(node[0])
@@ -440,7 +439,6 @@ def op_eq(self, node):
@function(c_int, BoxedInt, BoxedInt)
def eq(lhs, rhs):
- print 'stub eq'
return 1 if self.rt.equality(lhs, rhs) else 0
self.call(eq, lhs, rhs)
@@ -464,6 +462,8 @@ def conditional(self, cond_node, if_node, else_node, else_jump=None):
cond = self.frame.peek(-1)
if cond.is_constant():
boolean = self.rt.toBoolean(cond.to_boxed_int())
+ self.frame.spill_all(forget=True)
+
if boolean.toBool() == True:
self.compile_node(if_node)
else:
@@ -472,7 +472,7 @@ def conditional(self, cond_node, if_node, else_node, else_jump=None):
elif else_node:
self.assembler.compile_node(else_node)
else:
- self.frame.spill_all()
+ self.frame.spill_all(forget=True)
@function(c_int, BoxedInt)
def stub_conditional(condition):
@@ -560,7 +560,7 @@ def op_decrement(self, node):
def increment_identifier(self, node, amount):
self.op_identifier(node[0])
if hasattr(node, 'postfix'):
- self.op_identifier(node[0])
+ self.op_identifier(node[0]) # todo this should be self.frame.duplicate or simliar
self.frame.push_int(amount)
View
14 frame.py
@@ -54,11 +54,23 @@ def spill(self, forget=False):
index = self.frame.spill_index
if self.in_reg():
+ if forget:
+ if self.type == 'unknown':
+ pass
+ elif self.type == 'int':
+ self.frame.assembler.shl(self.reg, 1)
+ else:
+ self.frame.assembler.shl(self.reg, 1)
+ self.frame.assembler.add(self.reg, 1)
self.frame.assembler.mov(esi.addr + index * 4, self.reg)
self.frame.free_reg(self.reg)
+
else:
assert self.is_constant()
- self.frame.assembler.mov(esi.addr + index * 4, self.to_boxed_int().value)
+ if forget:
+ self.frame.assembler.mov(esi.addr + index * 4, self.to_boxed_int().value)
+ else:
+ self.frame.assembler.mov(esi.addr + index * 4, self.to_boxed_int().value >> 1)
self.reg = None
self.constant = False
View
7 pyasm/instructions/math.py
@@ -176,7 +176,7 @@ def sar(inst, target, source):
@Instruction.producer
def xor(inst, target, source):
if isinstance(target, Register):
- if target is eax:
+ if target is eax and isinstance(source, int):
inst.chr(0x35)
inst.pack('i', source)
@@ -184,4 +184,9 @@ def xor(inst, target, source):
inst.chr(0x31)
inst.modrm(3, target, source)
+ if isinstance(source, int):
+ inst.chr(0x81)
+ inst.modrm(3, 6, target)
+ inst.pack('i', source)
+
View
BIN  pyasm/instructions/math.pyc
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.