1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-08 10:30:55 +00:00

Centralize helper, use it elsewhere.

This commit is contained in:
Chris Pressey 2018-02-02 17:05:15 +00:00
parent 548905dce4
commit 4abedc0442
3 changed files with 12 additions and 12 deletions

View File

@ -232,7 +232,7 @@ class Analyzer(object):
if opcode == 'ld':
if instr.index:
if isinstance(src.type, TableType) and src.type.of_type == TYPE_BYTE and dest.type == TYPE_BYTE:
if TableType.is_a_table_type(src.type, TYPE_BYTE) and dest.type == TYPE_BYTE:
pass
else:
raise TypeMismatchError('%s and %s in %s' %
@ -246,7 +246,7 @@ class Analyzer(object):
context.set_written(dest, FLAG_Z, FLAG_N)
elif opcode == 'st':
if instr.index:
if src.type == TYPE_BYTE and isinstance(dest.type, TableType) and dest.type.of_type == TYPE_BYTE:
if src.type == TYPE_BYTE and TableType.is_a_table_type(dest.type, TYPE_BYTE):
pass
else:
raise TypeMismatchError((src, dest))
@ -362,13 +362,13 @@ class Analyzer(object):
raise TypeMismatchError((src, dest))
elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and isinstance(dest.ref.type, TableType) and dest.ref.type.of_type == TYPE_WORD:
if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
pass
else:
raise TypeMismatchError((src, dest))
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
if isinstance(src.ref.type, TableType) and src.ref.type.of_type == TYPE_WORD and dest.type == TYPE_WORD:
if TableType.is_a_table_type(src.ref.type, TYPE_WORD) and dest.type == TYPE_WORD:
pass
else:
raise TypeMismatchError((src, dest))

View File

@ -25,10 +25,6 @@ class UnsupportedOpcodeError(KeyError):
pass
def is_a_table_type(x, of_type):
return isinstance(x, TableType) and x.of_type == of_type
class Compiler(object):
def __init__(self, emitter):
self.emitter = emitter
@ -93,7 +89,7 @@ class Compiler(object):
initial_data = Byte(defn.initial)
elif type_ == TYPE_WORD:
initial_data = Word(defn.initial)
elif is_a_table_type(type_, TYPE_BYTE):
elif TableType.is_a_table_type(type_, TYPE_BYTE):
initial_data = Table(defn.initial, type_.size)
else:
raise NotImplementedError(type_)
@ -407,7 +403,7 @@ class Compiler(object):
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and is_a_table_type(dest.ref.type, TYPE_WORD):
if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
src_label = self.labels[src.name]
dest_label = self.labels[dest.ref.name]
self.emitter.emit(LDA(Absolute(src_label)))
@ -417,7 +413,7 @@ class Compiler(object):
else:
raise NotImplementedError
elif isinstance(src, ConstantRef) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and is_a_table_type(dest.ref.type, TYPE_WORD):
if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
dest_label = self.labels[dest.ref.name]
self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
@ -426,7 +422,7 @@ class Compiler(object):
else:
raise NotImplementedError
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
if is_a_table_type(src.ref.type, TYPE_WORD) and dest.type == TYPE_WORD:
if TableType.is_a_table_type(src.ref.type, TYPE_WORD) and dest.type == TYPE_WORD:
src_label = self.labels[src.ref.name]
dest_label = self.labels[dest.name]
self.emitter.emit(LDA(self.addressing_mode_for_index(src.index)(src_label)))

View File

@ -66,6 +66,10 @@ class TableType(Type):
self.size = size
self.name = '{} table[{}]'.format(self.of_type.name, self.size)
@classmethod
def is_a_table_type(cls_, x, of_type):
return isinstance(x, TableType) and x.of_type == of_type
class BufferType(Type):
def __init__(self, size):