mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-10 23:30:32 +00:00
Simplify and improve Emitter abstraction.
This commit is contained in:
parent
44d97c33a2
commit
78a1f2910c
@ -9,7 +9,7 @@ from sixtypical.model import (
|
||||
TableType, PointerType, RoutineType, VectorType,
|
||||
REG_A, REG_X, REG_Y, FLAG_C
|
||||
)
|
||||
from sixtypical.emitter import Byte, Word, Table, Label, Offset, LowAddressByte, HighAddressByte, Emitter
|
||||
from sixtypical.emitter import Byte, Word, Table, Label, Offset, LowAddressByte, HighAddressByte
|
||||
from sixtypical.gen6502 import (
|
||||
Immediate, Absolute, AbsoluteX, AbsoluteY, ZeroPage, Indirect, IndirectY, Relative,
|
||||
LDA, LDX, LDY, STA, STX, STY,
|
||||
@ -160,27 +160,23 @@ class Compiler(object):
|
||||
assert isinstance(routine, Routine)
|
||||
|
||||
self.current_routine = routine
|
||||
saved_emitter = self.emitter
|
||||
self.emitter = Emitter(saved_emitter.addr)
|
||||
|
||||
if routine.block:
|
||||
self.emitter.resolve_label(self.get_label(routine.name))
|
||||
self.compile_block(routine.block)
|
||||
|
||||
needs_rts = True
|
||||
if self.emitter.accum:
|
||||
last_op = self.emitter.accum[-1]
|
||||
if isinstance(last_op, JMP):
|
||||
needs_rts = False
|
||||
if isinstance(last_op.operand, Absolute):
|
||||
if isinstance(last_op.operand.value, Label):
|
||||
if next_routine and last_op.operand.value.name == next_routine.name:
|
||||
self.emitter.retract()
|
||||
last_op = self.emitter.get_tail()
|
||||
if isinstance(last_op, JMP):
|
||||
needs_rts = False
|
||||
if isinstance(last_op.operand, Absolute):
|
||||
if isinstance(last_op.operand.value, Label):
|
||||
if next_routine and last_op.operand.value.name == next_routine.name:
|
||||
self.emitter.retract()
|
||||
|
||||
if needs_rts:
|
||||
self.emitter.emit(RTS())
|
||||
|
||||
saved_emitter.emit(*self.emitter.accum)
|
||||
self.emitter = saved_emitter
|
||||
self.current_routine = None
|
||||
|
||||
def compile_block(self, block):
|
||||
|
@ -171,6 +171,12 @@ class Emitter(object):
|
||||
self.accum.append(thing)
|
||||
self.addr += thing.size()
|
||||
|
||||
def get_tail(self):
|
||||
if self.accum:
|
||||
return self.accum[-1]
|
||||
else:
|
||||
return None
|
||||
|
||||
def retract(self):
|
||||
thing = self.accum.pop()
|
||||
self.addr -= thing.size()
|
||||
|
Loading…
x
Reference in New Issue
Block a user