mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-29 18:49:22 +00:00
Retain silly 'name inside the type' syntax (a la C) for now.
This commit is contained in:
parent
7dba93ae88
commit
bbd3a84c00
@ -75,11 +75,7 @@ class Parser(object):
|
|||||||
return Program(defns=defns, routines=routines)
|
return Program(defns=defns, routines=routines)
|
||||||
|
|
||||||
def defn(self):
|
def defn(self):
|
||||||
type_ = self.defn_type()
|
type_, name = self.defn_type_and_name()
|
||||||
|
|
||||||
self.scanner.check_type('identifier')
|
|
||||||
name = self.scanner.token
|
|
||||||
self.scanner.scan()
|
|
||||||
|
|
||||||
initial = None
|
initial = None
|
||||||
if self.scanner.consume(':'):
|
if self.scanner.consume(':'):
|
||||||
@ -111,30 +107,45 @@ class Parser(object):
|
|||||||
self.scanner.expect(']')
|
self.scanner.expect(']')
|
||||||
return size
|
return size
|
||||||
|
|
||||||
def defn_type(self):
|
def defn_type_and_name(self):
|
||||||
if self.scanner.consume('byte'):
|
if self.scanner.consume('byte'):
|
||||||
if self.scanner.consume('table'):
|
type_ = TYPE_BYTE
|
||||||
size = self.defn_size()
|
|
||||||
return TableType(TYPE_BYTE, size)
|
|
||||||
return TYPE_BYTE
|
|
||||||
elif self.scanner.consume('word'):
|
|
||||||
if self.scanner.consume('table'):
|
|
||||||
size = self.defn_size()
|
|
||||||
return TableType(TYPE_WORD, size)
|
|
||||||
return TYPE_WORD
|
|
||||||
elif self.scanner.consume('vector'):
|
|
||||||
(inputs, outputs, trashes) = self.constraints()
|
|
||||||
type_ = VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
|
|
||||||
if self.scanner.consume('table'):
|
if self.scanner.consume('table'):
|
||||||
size = self.defn_size()
|
size = self.defn_size()
|
||||||
type_ = TableType(type_, size)
|
type_ = TableType(type_, size)
|
||||||
return type_
|
name = self.defn_name()
|
||||||
|
return type_, name
|
||||||
|
elif self.scanner.consume('word'):
|
||||||
|
type_ = TYPE_WORD
|
||||||
|
if self.scanner.consume('table'):
|
||||||
|
size = self.defn_size()
|
||||||
|
type_ = TableType(type_, size)
|
||||||
|
name = self.defn_name()
|
||||||
|
return type_, name
|
||||||
|
elif self.scanner.consume('vector'):
|
||||||
|
size = None
|
||||||
|
if self.scanner.consume('table'):
|
||||||
|
size = self.defn_size()
|
||||||
|
name = self.defn_name()
|
||||||
|
(inputs, outputs, trashes) = self.constraints()
|
||||||
|
type_ = VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
|
||||||
|
if size is not None:
|
||||||
|
type_ = TableType(type_, size)
|
||||||
|
return type_, name
|
||||||
elif self.scanner.consume('buffer'):
|
elif self.scanner.consume('buffer'):
|
||||||
size = self.defn_size()
|
size = self.defn_size()
|
||||||
return BufferType(size)
|
name = self.defn_name()
|
||||||
|
return BufferType(size), name
|
||||||
else:
|
else:
|
||||||
self.scanner.expect('pointer')
|
self.scanner.expect('pointer')
|
||||||
return PointerType()
|
name = self.defn_name()
|
||||||
|
return PointerType(), name
|
||||||
|
|
||||||
|
def defn_name(self):
|
||||||
|
self.scanner.check_type('identifier')
|
||||||
|
name = self.scanner.token
|
||||||
|
self.scanner.scan()
|
||||||
|
return name
|
||||||
|
|
||||||
def constraints(self):
|
def constraints(self):
|
||||||
inputs = set()
|
inputs = set()
|
||||||
|
@ -1554,11 +1554,10 @@ Read through a pointer.
|
|||||||
Routines are constants. You need not, and in fact cannot, specify a constant
|
Routines are constants. You need not, and in fact cannot, specify a constant
|
||||||
as an input to, an output of, or as a trashed value of a routine.
|
as an input to, an output of, or as a trashed value of a routine.
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs x
|
| inputs x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1577,11 +1576,10 @@ as an input to, an output of, or as a trashed value of a routine.
|
|||||||
| }
|
| }
|
||||||
? ConstantConstraintError: foo in main
|
? ConstantConstraintError: foo in main
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs x
|
| inputs x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1599,11 +1597,10 @@ as an input to, an output of, or as a trashed value of a routine.
|
|||||||
| }
|
| }
|
||||||
? ConstantConstraintError: foo in main
|
? ConstantConstraintError: foo in main
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs x
|
| inputs x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1624,11 +1621,10 @@ as an input to, an output of, or as a trashed value of a routine.
|
|||||||
You can copy the address of a routine into a vector, if that vector is
|
You can copy the address of a routine into a vector, if that vector is
|
||||||
declared appropriately.
|
declared appropriately.
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs x
|
| inputs x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1648,11 +1644,10 @@ declared appropriately.
|
|||||||
|
|
||||||
But not if the vector is declared inappropriately.
|
But not if the vector is declared inappropriately.
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs y
|
| inputs y
|
||||||
| outputs y
|
| outputs y
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1673,11 +1668,10 @@ But not if the vector is declared inappropriately.
|
|||||||
"Appropriately" means, if the routine affects no more than what is named
|
"Appropriately" means, if the routine affects no more than what is named
|
||||||
in the input/output sets of the vector.
|
in the input/output sets of the vector.
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs a, x
|
| inputs a, x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1697,11 +1691,10 @@ in the input/output sets of the vector.
|
|||||||
|
|
||||||
Routines are read-only.
|
Routines are read-only.
|
||||||
|
|
||||||
| vector
|
| vector vec
|
||||||
| inputs x
|
| inputs x
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes z, n
|
| trashes z, n
|
||||||
| vec
|
|
||||||
|
|
|
|
||||||
| routine foo
|
| routine foo
|
||||||
| inputs x
|
| inputs x
|
||||||
@ -1721,7 +1714,7 @@ Routines are read-only.
|
|||||||
|
|
||||||
Indirect call.
|
Indirect call.
|
||||||
|
|
||||||
| vector outputs x trashes z, n foo
|
| vector foo outputs x trashes z, n
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes z, n {
|
| routine bar outputs x trashes z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
@ -1735,7 +1728,7 @@ Indirect call.
|
|||||||
|
|
||||||
Calling the vector does indeed trash the things the vector says it does.
|
Calling the vector does indeed trash the things the vector says it does.
|
||||||
|
|
||||||
| vector trashes x, z, n foo
|
| vector foo trashes x, z, n
|
||||||
|
|
|
|
||||||
| routine bar trashes x, z, n {
|
| routine bar trashes x, z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
@ -1835,7 +1828,7 @@ Can `goto` a routine that outputs or trashes less than the current routine.
|
|||||||
|
|
||||||
Indirect goto.
|
Indirect goto.
|
||||||
|
|
||||||
| vector outputs x trashes a, z, n foo
|
| vector foo outputs x trashes a, z, n
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes a, z, n {
|
| routine bar outputs x trashes a, z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
@ -1850,9 +1843,8 @@ Indirect goto.
|
|||||||
Jumping through the vector does indeed trash, or output, the things the
|
Jumping through the vector does indeed trash, or output, the things the
|
||||||
vector says it does.
|
vector says it does.
|
||||||
|
|
||||||
| vector
|
| vector foo
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| foo
|
|
||||||
|
|
|
|
||||||
| routine bar
|
| routine bar
|
||||||
| trashes a, x, z, n {
|
| trashes a, x, z, n {
|
||||||
@ -1874,10 +1866,9 @@ vector says it does.
|
|||||||
| }
|
| }
|
||||||
? UnmeaningfulReadError: x in main
|
? UnmeaningfulReadError: x in main
|
||||||
|
|
||||||
| vector
|
| vector foo
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| foo
|
|
||||||
|
|
|
|
||||||
| routine bar
|
| routine bar
|
||||||
| outputs x
|
| outputs x
|
||||||
@ -1905,14 +1896,12 @@ vector says it does.
|
|||||||
|
|
||||||
Copying to and from a vector table.
|
Copying to and from a vector table.
|
||||||
|
|
||||||
| vector
|
| vector one
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| one
|
| vector table[256] many
|
||||||
| vector
|
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| table[256] many
|
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes a, z, n {
|
| routine bar outputs x trashes a, z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
|
@ -568,9 +568,7 @@ Copy word to word table and back, with both `x` and `y` as indexes.
|
|||||||
|
|
||||||
Indirect call.
|
Indirect call.
|
||||||
|
|
||||||
| vector outputs x
|
| vector foo outputs x trashes z, n
|
||||||
| trashes z, n
|
|
||||||
| foo
|
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes z, n {
|
| routine bar outputs x trashes z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
@ -610,14 +608,12 @@ goto.
|
|||||||
|
|
||||||
Copying to and from a vector table.
|
Copying to and from a vector table.
|
||||||
|
|
||||||
| vector
|
| vector one
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| one
|
| vector table[256] many
|
||||||
| vector
|
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, z, n
|
| trashes a, z, n
|
||||||
| table[256] many
|
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes a, z, n {
|
| routine bar outputs x trashes a, z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
|
@ -453,7 +453,7 @@ Copy literal word to word.
|
|||||||
|
|
||||||
Indirect call.
|
Indirect call.
|
||||||
|
|
||||||
| vector outputs x trashes z, n foo
|
| vector foo outputs x trashes z, n
|
||||||
|
|
|
|
||||||
| routine bar outputs x trashes z, n {
|
| routine bar outputs x trashes z, n {
|
||||||
| ld x, 200
|
| ld x, 200
|
||||||
|
@ -135,10 +135,10 @@ User-defined memory addresses of different types.
|
|||||||
|
|
||||||
| byte byt
|
| byte byt
|
||||||
| word wor
|
| word wor
|
||||||
| vector trashes a vec
|
| vector vec trashes a
|
||||||
| byte table[256] tab
|
| byte table[256] tab
|
||||||
| word table[256] wtab
|
| word table[256] wtab
|
||||||
| vector trashes a table[256] vtab
|
| vector table[256] vtab trashes a
|
||||||
| buffer[2048] buf
|
| buffer[2048] buf
|
||||||
| pointer ptr
|
| pointer ptr
|
||||||
|
|
|
|
||||||
@ -314,11 +314,11 @@ Declaring byte and word table memory location.
|
|||||||
|
|
||||||
Declaring and calling a vector.
|
Declaring and calling a vector.
|
||||||
|
|
||||||
| vector
|
| vector cinv
|
||||||
| inputs a
|
| inputs a
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
|
|
|
|
||||||
| routine foo {
|
| routine foo {
|
||||||
| ld a, 0
|
| ld a, 0
|
||||||
@ -333,11 +333,11 @@ Declaring and calling a vector.
|
|||||||
|
|
||||||
Only vectors can be decorated with constraints like that.
|
Only vectors can be decorated with constraints like that.
|
||||||
|
|
||||||
| byte
|
| byte cinv
|
||||||
| inputs a
|
| inputs a
|
||||||
| outputs x
|
| outputs x
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
|
|
|
|
||||||
| routine main {
|
| routine main {
|
||||||
| }
|
| }
|
||||||
@ -345,11 +345,11 @@ Only vectors can be decorated with constraints like that.
|
|||||||
|
|
||||||
Constraints set may only contain labels.
|
Constraints set may only contain labels.
|
||||||
|
|
||||||
| vector
|
| vector cinv
|
||||||
| inputs a
|
| inputs a
|
||||||
| outputs 200
|
| outputs 200
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
|
|
|
|
||||||
| routine foo {
|
| routine foo {
|
||||||
| ld a, 0
|
| ld a, 0
|
||||||
@ -364,11 +364,11 @@ Constraints set may only contain labels.
|
|||||||
|
|
||||||
A vector can name itself in its inputs, outputs, and trashes.
|
A vector can name itself in its inputs, outputs, and trashes.
|
||||||
|
|
||||||
| vector
|
| vector cinv
|
||||||
| inputs cinv, a
|
| inputs cinv, a
|
||||||
| outputs cinv, x
|
| outputs cinv, x
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
|
|
|
|
||||||
| routine foo {
|
| routine foo {
|
||||||
| ld a, 0
|
| ld a, 0
|
||||||
@ -384,11 +384,11 @@ A vector can name itself in its inputs, outputs, and trashes.
|
|||||||
A routine can be copied into a vector before the routine appears in the program,
|
A routine can be copied into a vector before the routine appears in the program,
|
||||||
*however*, it must be marked as such with the keyword `forward`.
|
*however*, it must be marked as such with the keyword `forward`.
|
||||||
|
|
||||||
| vector
|
| vector cinv
|
||||||
| inputs cinv, a
|
| inputs cinv, a
|
||||||
| outputs cinv, x
|
| outputs cinv, x
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
| routine main {
|
| routine main {
|
||||||
| with interrupts off {
|
| with interrupts off {
|
||||||
| copy foo, cinv
|
| copy foo, cinv
|
||||||
@ -400,11 +400,11 @@ A routine can be copied into a vector before the routine appears in the program,
|
|||||||
| }
|
| }
|
||||||
? SyntaxError: Undefined symbol
|
? SyntaxError: Undefined symbol
|
||||||
|
|
||||||
| vector
|
| vector cinv
|
||||||
| inputs cinv, a
|
| inputs cinv, a
|
||||||
| outputs cinv, x
|
| outputs cinv, x
|
||||||
| trashes a, x, z, n
|
| trashes a, x, z, n
|
||||||
| cinv @ 788
|
| @ 788
|
||||||
| routine main {
|
| routine main {
|
||||||
| with interrupts off {
|
| with interrupts off {
|
||||||
| copy forward foo, cinv
|
| copy forward foo, cinv
|
||||||
|
Loading…
Reference in New Issue
Block a user