1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-01 12:41:30 +00:00

Check for table size (in parser, thus tests are for syntax.)

This commit is contained in:
Chris Pressey 2018-02-14 13:53:22 +00:00
parent aa5b06980c
commit 93e2dada16
3 changed files with 41 additions and 28 deletions

View File

@ -146,6 +146,8 @@ class Parser(object):
if self.scanner.consume('table'):
size = self.defn_size()
if size not in (1, 2, 4, 8, 16, 32, 64, 129, 256):
raise SyntaxError("Table size must be a power of two, 0 < size <= 256")
type_ = TableType(type_, size)
return type_

View File

@ -533,34 +533,6 @@ You can also copy a literal word to a word table.
#### tables: range checking ####
A table may not have more than 256 entries.
| word table[512] many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
? zzzzz
The number of entries in a table must be a power of two.
| word table[48] many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
? zzzz
If a table has fewer than 256 entries, it cannot be read or written
beyond the maximum number of entries it has.

View File

@ -153,6 +153,45 @@ Tables of different types.
| }
= ok
The number of entries in a table must be a power of two
which is greater than 0 and less than or equal to 256.
| word table[512] many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
? SyntaxError
| word table[48] many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
? SyntaxError
| word table[0] many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
? SyntaxError
Typedefs of different types.
| typedef byte octet