1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-22 17:32:01 +00:00

Make compilation tests pass.

This commit is contained in:
Chris Pressey 2018-03-14 16:27:33 +00:00
parent adb53f7a04
commit 96fbe03ce7
2 changed files with 17 additions and 1 deletions

View File

@ -556,9 +556,11 @@ class Compiler(object):
if instr.direction > 0: if instr.direction > 0:
self.compile_inc(instr, instr.dest) self.compile_inc(instr, instr.dest)
final = instr.final.succ()
elif instr.direction < 0: elif instr.direction < 0:
self.compile_dec(instr, instr.dest) self.compile_dec(instr, instr.dest)
self.compile_cmp(instr, instr.final, instr.dest) final = instr.final.pred()
self.compile_cmp(instr, final, instr.dest)
self.emitter.emit(BNE(Relative(top_label))) self.emitter.emit(BNE(Relative(top_label)))
def compile_with_interrupts_off(self, instr): def compile_with_interrupts_off(self, instr):

View File

@ -296,6 +296,20 @@ class ConstantRef(Ref):
def low_byte(self): def low_byte(self):
return self.value & 255 return self.value & 255
def pred(self):
assert self.type == TYPE_BYTE
value = self.value - 1
while value < 0:
value += 256
return ConstantRef(self.type, value)
def succ(self):
assert self.type == TYPE_BYTE
value = self.value + 1
while value > 255:
value -= 256
return ConstantRef(self.type, value)
REG_A = LocationRef(TYPE_BYTE, 'a') REG_A = LocationRef(TYPE_BYTE, 'a')
REG_X = LocationRef(TYPE_BYTE, 'x') REG_X = LocationRef(TYPE_BYTE, 'x')