1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 03:41:28 +00:00

Constraints for vector come immediately after the type expression.

This commit is contained in:
Chris Pressey 2018-02-02 17:16:31 +00:00
parent 4abedc0442
commit b29716fccf
6 changed files with 46 additions and 31 deletions

View File

@ -6,6 +6,7 @@ History of SixtyPical
* Each table has a specified size now (although, bounds checking is not performed.)
* Initialized `byte table` values need not have all 256 bytes initialized.
* Constraints for `vector` type come immediately after the type, not the variable.
0.10
----

View File

@ -81,12 +81,6 @@ class Parser(object):
name = self.scanner.token
self.scanner.scan()
(inputs, outputs, trashes) = self.constraints()
if type_ == 'vector':
type_ = VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
elif inputs or outputs or trashes:
raise SyntaxError("Cannot apply constraints to non-vector type")
initial = None
if self.scanner.consume(':'):
if isinstance(type_, TableType) and self.scanner.on_type('string literal'):
@ -129,7 +123,8 @@ class Parser(object):
return TableType(TYPE_WORD, size)
return TYPE_WORD
elif self.scanner.consume('vector'):
return 'vector' # will be resolved to a Type by caller
(inputs, outputs, trashes) = self.constraints()
return VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
elif self.scanner.consume('buffer'):
size = self.defn_size()
return BufferType(size)

View File

@ -1554,10 +1554,11 @@ Read through a pointer.
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.
| vector vec
| vector
| inputs x
| outputs x
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1576,10 +1577,11 @@ as an input to, an output of, or as a trashed value of a routine.
| }
? ConstantConstraintError: foo in main
| vector vec
| vector
| inputs x
| outputs x
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1597,10 +1599,11 @@ as an input to, an output of, or as a trashed value of a routine.
| }
? ConstantConstraintError: foo in main
| vector vec
| vector
| inputs x
| outputs x
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1621,10 +1624,11 @@ 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
declared appropriately.
| vector vec
| vector
| inputs x
| outputs x
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1644,10 +1648,11 @@ declared appropriately.
But not if the vector is declared inappropriately.
| vector vec
| vector
| inputs y
| outputs y
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1668,10 +1673,11 @@ But not if the vector is declared inappropriately.
"Appropriately" means, if the routine affects no more than what is named
in the input/output sets of the vector.
| vector vec
| vector
| inputs a, x
| outputs x
| trashes a, z, n
| vec
|
| routine foo
| inputs x
@ -1691,10 +1697,11 @@ in the input/output sets of the vector.
Routines are read-only.
| vector vec
| vector
| inputs x
| outputs x
| trashes z, n
| vec
|
| routine foo
| inputs x
@ -1714,7 +1721,7 @@ Routines are read-only.
Indirect call.
| vector foo outputs x trashes z, n
| vector outputs x trashes z, n foo
|
| routine bar outputs x trashes z, n {
| ld x, 200
@ -1728,7 +1735,7 @@ Indirect call.
Calling the vector does indeed trash the things the vector says it does.
| vector foo trashes x, z, n
| vector trashes x, z, n foo
|
| routine bar trashes x, z, n {
| ld x, 200
@ -1828,7 +1835,7 @@ Can `goto` a routine that outputs or trashes less than the current routine.
Indirect goto.
| vector foo outputs x trashes a, z, n
| vector outputs x trashes a, z, n foo
|
| routine bar outputs x trashes a, z, n {
| ld x, 200
@ -1843,8 +1850,9 @@ Indirect goto.
Jumping through the vector does indeed trash, or output, the things the
vector says it does.
| vector foo
| vector
| trashes a, x, z, n
| foo
|
| routine bar
| trashes a, x, z, n {
@ -1866,9 +1874,10 @@ vector says it does.
| }
? UnmeaningfulReadError: x in main
| vector foo
| vector
| outputs x
| trashes a, z, n
| foo
|
| routine bar
| outputs x

View File

@ -568,7 +568,9 @@ Copy word to word table and back, with both `x` and `y` as indexes.
Indirect call.
| vector foo outputs x trashes z, n
| vector outputs x
| trashes z, n
| foo
|
| routine bar outputs x trashes z, n {
| ld x, 200

View File

@ -453,7 +453,7 @@ Copy literal word to word.
Indirect call.
| vector foo outputs x trashes z, n
| vector outputs x trashes z, n foo
|
| routine bar outputs x trashes z, n {
| ld x, 200

View File

@ -313,11 +313,11 @@ Declaring byte and word table memory location.
Declaring and calling a vector.
| vector cinv
| vector
| inputs a
| outputs x
| trashes a, x, z, n
| @ 788
| cinv @ 788
|
| routine foo {
| ld a, 0
@ -332,11 +332,11 @@ Declaring and calling a vector.
Only vectors can be decorated with constraints like that.
| byte cinv
| byte
| inputs a
| outputs x
| trashes a, x, z, n
| @ 788
| cinv @ 788
|
| routine main {
| }
@ -344,11 +344,11 @@ Only vectors can be decorated with constraints like that.
Constraints set may only contain labels.
| vector cinv
| vector
| inputs a
| outputs 200
| trashes a, x, z, n
| @ 788
| cinv @ 788
|
| routine foo {
| ld a, 0
@ -363,11 +363,11 @@ Constraints set may only contain labels.
A vector can name itself in its inputs, outputs, and trashes.
| vector cinv
| vector
| inputs cinv, a
| outputs cinv, x
| trashes a, x, z, n
| @ 788
| cinv @ 788
|
| routine foo {
| ld a, 0
@ -383,7 +383,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,
*however*, it must be marked as such with the keyword `forward`.
| vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
| vector
| inputs cinv, a
| outputs cinv, x
| trashes a, x, z, n
| cinv @ 788
| routine main {
| with interrupts off {
| copy foo, cinv
@ -395,7 +399,11 @@ A routine can be copied into a vector before the routine appears in the program,
| }
? SyntaxError: Undefined symbol
| vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
| vector
| inputs cinv, a
| outputs cinv, x
| trashes a, x, z, n
| cinv @ 788
| routine main {
| with interrupts off {
| copy forward foo, cinv