Check for table size (in parser, thus tests are for syntax.)
Chris Pressey
4 years ago
145 | 145 |
|
146 | 146 |
if self.scanner.consume('table'):
|
147 | 147 |
size = self.defn_size()
|
|
148 |
if size not in (1, 2, 4, 8, 16, 32, 64, 129, 256):
|
|
149 |
raise SyntaxError("Table size must be a power of two, 0 < size <= 256")
|
148 | 150 |
type_ = TableType(type_, size)
|
149 | 151 |
|
150 | 152 |
return type_
|
531 | 531 |
= ok
|
532 | 532 |
|
533 | 533 |
#### tables: range checking ####
|
534 | |
|
535 | |
A table may not have more than 256 entries.
|
536 | |
|
537 | |
| word table[512] many
|
538 | |
|
|
539 | |
| routine main
|
540 | |
| inputs many
|
541 | |
| outputs many
|
542 | |
| trashes a, x, n, z
|
543 | |
| {
|
544 | |
| ld x, 0
|
545 | |
| copy 9999, many + x
|
546 | |
| }
|
547 | |
? zzzzz
|
548 | |
|
549 | |
The number of entries in a table must be a power of two.
|
550 | |
|
551 | |
| word table[48] many
|
552 | |
|
|
553 | |
| routine main
|
554 | |
| inputs many
|
555 | |
| outputs many
|
556 | |
| trashes a, x, n, z
|
557 | |
| {
|
558 | |
| ld x, 0
|
559 | |
| copy 9999, many + x
|
560 | |
| }
|
561 | |
? zzzz
|
562 | 534 |
|
563 | 535 |
If a table has fewer than 256 entries, it cannot be read or written
|
564 | 536 |
beyond the maximum number of entries it has.
|
152 | 152 |
| }
|
153 | 153 |
= ok
|
154 | 154 |
|
|
155 |
The number of entries in a table must be a power of two
|
|
156 |
which is greater than 0 and less than or equal to 256.
|
|
157 |
|
|
158 |
| word table[512] many
|
|
159 |
|
|
|
160 |
| routine main
|
|
161 |
| inputs many
|
|
162 |
| outputs many
|
|
163 |
| trashes a, x, n, z
|
|
164 |
| {
|
|
165 |
| ld x, 0
|
|
166 |
| copy 9999, many + x
|
|
167 |
| }
|
|
168 |
? SyntaxError
|
|
169 |
|
|
170 |
| word table[48] many
|
|
171 |
|
|
|
172 |
| routine main
|
|
173 |
| inputs many
|
|
174 |
| outputs many
|
|
175 |
| trashes a, x, n, z
|
|
176 |
| {
|
|
177 |
| ld x, 0
|
|
178 |
| copy 9999, many + x
|
|
179 |
| }
|
|
180 |
? SyntaxError
|
|
181 |
|
|
182 |
| word table[0] many
|
|
183 |
|
|
|
184 |
| routine main
|
|
185 |
| inputs many
|
|
186 |
| outputs many
|
|
187 |
| trashes a, x, n, z
|
|
188 |
| {
|
|
189 |
| ld x, 0
|
|
190 |
| copy 9999, many + x
|
|
191 |
| }
|
|
192 |
? SyntaxError
|
|
193 |
|
155 | 194 |
Typedefs of different types.
|
156 | 195 |
|
157 | 196 |
| typedef byte octet
|