mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-26 22:29:03 +00:00
Beginnings of implementing word tables. One test still fails.
This commit is contained in:
parent
ad8e0647a4
commit
689ed37f2e
@ -2,8 +2,8 @@
|
||||
|
||||
from sixtypical.ast import Program, Routine, Block, Instr
|
||||
from sixtypical.model import (
|
||||
TYPE_BYTE, TYPE_WORD, TYPE_BYTE_TABLE, BufferType, PointerType, VectorType, ExecutableType,
|
||||
ConstantRef, LocationRef, IndirectRef, AddressRef,
|
||||
TYPE_BYTE, TYPE_WORD, TYPE_BYTE_TABLE, TYPE_WORD_TABLE, BufferType, PointerType, VectorType, ExecutableType,
|
||||
ConstantRef, LocationRef, IndirectRef, IndexedRef, AddressRef,
|
||||
REG_A, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
|
||||
)
|
||||
|
||||
@ -348,6 +348,13 @@ class Analyzer(object):
|
||||
pass
|
||||
else:
|
||||
raise TypeMismatchError((src, dest))
|
||||
|
||||
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
|
||||
if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE:
|
||||
pass
|
||||
else:
|
||||
raise TypeMismatchError((src, dest))
|
||||
|
||||
elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, LocationRef):
|
||||
if src.type == dest.type:
|
||||
pass
|
||||
|
@ -106,7 +106,7 @@ class IndirectRef(Ref):
|
||||
self.ref = ref
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.ref == other.ref
|
||||
return isinstance(other, self.__class__) and self.ref == other.ref
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__class__.name) ^ hash(self.ref)
|
||||
@ -122,6 +122,28 @@ class IndirectRef(Ref):
|
||||
return False
|
||||
|
||||
|
||||
class IndexedRef(Ref):
|
||||
def __init__(self, ref, index):
|
||||
self.ref = ref
|
||||
self.index = index
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, self.__class__) and self.ref == other.ref and self.index == other.index
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__class__.name) ^ hash(self.ref) ^ hash(self.index)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%r, %r)' % (self.__class__.__name__, self.ref, self.index)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return '{}+{}'.format(self.ref.name, self.index.name)
|
||||
|
||||
def is_constant(self):
|
||||
return False
|
||||
|
||||
|
||||
class AddressRef(Ref):
|
||||
def __init__(self, ref):
|
||||
self.ref = ref
|
||||
|
@ -4,7 +4,7 @@ from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
||||
from sixtypical.model import (
|
||||
TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE, TYPE_WORD, TYPE_WORD_TABLE,
|
||||
RoutineType, VectorType, ExecutableType, BufferType, PointerType,
|
||||
LocationRef, ConstantRef, IndirectRef, AddressRef,
|
||||
LocationRef, ConstantRef, IndirectRef, IndexedRef, AddressRef,
|
||||
)
|
||||
from sixtypical.scanner import Scanner
|
||||
|
||||
@ -175,7 +175,12 @@ class Parser(object):
|
||||
loc = self.locexpr()
|
||||
return AddressRef(loc)
|
||||
else:
|
||||
return self.locexpr()
|
||||
loc = self.locexpr()
|
||||
index = None
|
||||
if self.scanner.consume('+'):
|
||||
index = self.locexpr()
|
||||
loc = IndexedRef(loc, index)
|
||||
return loc
|
||||
|
||||
def block(self):
|
||||
instrs = []
|
||||
|
@ -207,6 +207,21 @@ Can't `st` to a memory location that doesn't appear in (outputs ∪ trashes).
|
||||
| }
|
||||
? ForbiddenWriteError: lives in main
|
||||
|
||||
Can't `st` a `word` type.
|
||||
|
||||
| word foo
|
||||
|
|
||||
| routine main
|
||||
| outputs foo
|
||||
| trashes a, n, z
|
||||
| {
|
||||
| ld a, 0
|
||||
| st a, foo
|
||||
| }
|
||||
? TypeMismatchError: a and foo in main
|
||||
|
||||
### tables ###
|
||||
|
||||
Storing to a table, you must use an index, and vice-versa.
|
||||
|
||||
| byte one
|
||||
@ -313,18 +328,47 @@ Reading from a table, you must use an index, and vice-versa.
|
||||
| }
|
||||
= ok
|
||||
|
||||
Can't `st` a `word` type.
|
||||
Copying to and from a word table.
|
||||
|
||||
| word foo
|
||||
| word one
|
||||
| word table many
|
||||
|
|
||||
| routine main
|
||||
| outputs foo
|
||||
| trashes a, n, z
|
||||
| inputs one, many
|
||||
| outputs one, many
|
||||
| trashes a, x, n, z
|
||||
| {
|
||||
| ld a, 0
|
||||
| st a, foo
|
||||
| ld x, 0
|
||||
| copy one, many + x
|
||||
| copy many + x, one
|
||||
| }
|
||||
? TypeMismatchError: a and foo in main
|
||||
= ok
|
||||
|
||||
| word one
|
||||
| word table many
|
||||
|
|
||||
| routine main
|
||||
| inputs one, many
|
||||
| outputs one, many
|
||||
| trashes a, x, n, z
|
||||
| {
|
||||
| ld x, 0
|
||||
| copy one, many
|
||||
| }
|
||||
? TypeMismatchError
|
||||
|
||||
| word one
|
||||
| word table many
|
||||
|
|
||||
| routine main
|
||||
| inputs one, many
|
||||
| outputs one, many
|
||||
| trashes a, x, n, z
|
||||
| {
|
||||
| ld x, 0
|
||||
| copy one + x, many
|
||||
| }
|
||||
? TypeMismatchError
|
||||
|
||||
### add ###
|
||||
|
||||
|
@ -129,6 +129,7 @@ User-defined memory addresses of different types.
|
||||
| word wor
|
||||
| vector vec
|
||||
| byte table tab
|
||||
| word table wtab
|
||||
| buffer[2048] buf
|
||||
| pointer ptr
|
||||
|
|
||||
@ -250,7 +251,7 @@ Can't define two routines with the same name.
|
||||
| }
|
||||
? SyntaxError
|
||||
|
||||
Declaring a byte table memory location.
|
||||
Declaring byte and word table memory location.
|
||||
|
||||
| byte table tab
|
||||
|
|
||||
@ -262,6 +263,17 @@ Declaring a byte table memory location.
|
||||
| }
|
||||
= ok
|
||||
|
||||
| word one
|
||||
| word table many
|
||||
|
|
||||
| routine main {
|
||||
| ld x, 0
|
||||
| copy one, many + x
|
||||
| copy word 0, many + x
|
||||
| copy many + x, one
|
||||
| }
|
||||
= ok
|
||||
|
||||
Declaring and calling a vector.
|
||||
|
||||
| vector cinv
|
||||
|
Loading…
x
Reference in New Issue
Block a user