git @ Cat's Eye Technologies SixtyPical / 93e2dad
Check for table size (in parser, thus tests are for syntax.) Chris Pressey 3 years ago
3 changed file(s) with 41 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
145145
146146 if self.scanner.consume('table'):
147147 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")
148150 type_ = TableType(type_, size)
149151
150152 return type_
531531 = ok
532532
533533 #### 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
562534
563535 If a table has fewer than 256 entries, it cannot be read or written
564536 beyond the maximum number of entries it has.
152152 | }
153153 = ok
154154
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
155194 Typedefs of different types.
156195
157196 | typedef byte octet