mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-09 01:30:50 +00:00
Centralize helper, use it elsewhere.
This commit is contained in:
parent
548905dce4
commit
4abedc0442
@ -232,7 +232,7 @@ class Analyzer(object):
|
|||||||
|
|
||||||
if opcode == 'ld':
|
if opcode == 'ld':
|
||||||
if instr.index:
|
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
|
pass
|
||||||
else:
|
else:
|
||||||
raise TypeMismatchError('%s and %s in %s' %
|
raise TypeMismatchError('%s and %s in %s' %
|
||||||
@ -246,7 +246,7 @@ class Analyzer(object):
|
|||||||
context.set_written(dest, FLAG_Z, FLAG_N)
|
context.set_written(dest, FLAG_Z, FLAG_N)
|
||||||
elif opcode == 'st':
|
elif opcode == 'st':
|
||||||
if instr.index:
|
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
|
pass
|
||||||
else:
|
else:
|
||||||
raise TypeMismatchError((src, dest))
|
raise TypeMismatchError((src, dest))
|
||||||
@ -362,13 +362,13 @@ class Analyzer(object):
|
|||||||
raise TypeMismatchError((src, dest))
|
raise TypeMismatchError((src, dest))
|
||||||
|
|
||||||
elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
|
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
|
pass
|
||||||
else:
|
else:
|
||||||
raise TypeMismatchError((src, dest))
|
raise TypeMismatchError((src, dest))
|
||||||
|
|
||||||
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
|
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
|
pass
|
||||||
else:
|
else:
|
||||||
raise TypeMismatchError((src, dest))
|
raise TypeMismatchError((src, dest))
|
||||||
|
@ -25,10 +25,6 @@ class UnsupportedOpcodeError(KeyError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def is_a_table_type(x, of_type):
|
|
||||||
return isinstance(x, TableType) and x.of_type == of_type
|
|
||||||
|
|
||||||
|
|
||||||
class Compiler(object):
|
class Compiler(object):
|
||||||
def __init__(self, emitter):
|
def __init__(self, emitter):
|
||||||
self.emitter = emitter
|
self.emitter = emitter
|
||||||
@ -93,7 +89,7 @@ class Compiler(object):
|
|||||||
initial_data = Byte(defn.initial)
|
initial_data = Byte(defn.initial)
|
||||||
elif type_ == TYPE_WORD:
|
elif type_ == TYPE_WORD:
|
||||||
initial_data = Word(defn.initial)
|
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)
|
initial_data = Table(defn.initial, type_.size)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(type_)
|
raise NotImplementedError(type_)
|
||||||
@ -407,7 +403,7 @@ class Compiler(object):
|
|||||||
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
|
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
|
||||||
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
||||||
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
|
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]
|
src_label = self.labels[src.name]
|
||||||
dest_label = self.labels[dest.ref.name]
|
dest_label = self.labels[dest.ref.name]
|
||||||
self.emitter.emit(LDA(Absolute(src_label)))
|
self.emitter.emit(LDA(Absolute(src_label)))
|
||||||
@ -417,7 +413,7 @@ class Compiler(object):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
elif isinstance(src, ConstantRef) and isinstance(dest, IndexedRef):
|
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]
|
dest_label = self.labels[dest.ref.name]
|
||||||
self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
|
self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
|
||||||
self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
|
self.emitter.emit(STA(self.addressing_mode_for_index(dest.index)(dest_label)))
|
||||||
@ -426,7 +422,7 @@ class Compiler(object):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
|
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]
|
src_label = self.labels[src.ref.name]
|
||||||
dest_label = self.labels[dest.name]
|
dest_label = self.labels[dest.name]
|
||||||
self.emitter.emit(LDA(self.addressing_mode_for_index(src.index)(src_label)))
|
self.emitter.emit(LDA(self.addressing_mode_for_index(src.index)(src_label)))
|
||||||
|
@ -66,6 +66,10 @@ class TableType(Type):
|
|||||||
self.size = size
|
self.size = size
|
||||||
self.name = '{} table[{}]'.format(self.of_type.name, self.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):
|
class BufferType(Type):
|
||||||
def __init__(self, size):
|
def __init__(self, size):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user