git @ Cat's Eye Technologies SixtyPical / 70ecd52
Retain some syntax compatibility: make `table` a postfix operator. Chris Pressey 3 years ago
4 changed file(s) with 66 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
129129 return size
130130
131131 def defn_type(self):
132 type_ = None
133
134 if self.scanner.consume('('):
135 type_ = self.defn_type()
136 self.scanner.expect(')')
137 return type_
138
132139 if self.scanner.consume('byte'):
133 return TYPE_BYTE
140 type_ = TYPE_BYTE
134141 elif self.scanner.consume('word'):
135 return TYPE_WORD
136 elif self.scanner.consume('table'):
137 size = self.defn_size()
138 type_ = self.defn_type()
139 return TableType(type_, size)
142 type_ = TYPE_WORD
140143 elif self.scanner.consume('vector'):
141144 type_ = self.defn_type()
142 # TODO: assert that it's a routine type
143 return VectorType(type_)
145 if not isinstance(type_, RoutineType):
146 raise SyntaxError("Vectors can only be of a routine, not %r" % type_)
147 type_ = VectorType(type_)
144148 elif self.scanner.consume('routine'):
145149 (inputs, outputs, trashes) = self.constraints()
146 return RoutineType(inputs=inputs, outputs=outputs, trashes=trashes)
150 type_ = RoutineType(inputs=inputs, outputs=outputs, trashes=trashes)
147151 elif self.scanner.consume('buffer'):
148152 size = self.defn_size()
149 return BufferType(size)
153 type_ = BufferType(size)
150154 elif self.scanner.consume('pointer'):
151 return PointerType()
155 type_ = PointerType()
152156 else:
153157 type_name = self.scanner.token
154158 self.scanner.scan()
155159 if type_name not in self.typedefs:
156160 raise SyntaxError("Undefined type '%s'" % type_name)
157 return self.typedefs[type_name]
161 type_ = self.typedefs[type_name]
162
163 if self.scanner.consume('table'):
164 size = self.defn_size()
165 type_ = TableType(type_, size)
166
167 return type_
158168
159169 def defn_name(self):
160170 self.scanner.check_type('identifier')
242242 Storing to a table, you must use an index.
243243
244244 | byte one
245 | table[256] byte many
245 | byte table[256] many
246246 |
247247 | routine main
248248 | outputs one
255255 = ok
256256
257257 | byte one
258 | table[256] byte many
258 | byte table[256] many
259259 |
260260 | routine main
261261 | outputs many
268268 ? TypeMismatchError
269269
270270 | byte one
271 | table[256] byte many
271 | byte table[256] many
272272 |
273273 | routine main
274274 | outputs one
281281 ? TypeMismatchError
282282
283283 | byte one
284 | table[256] byte many
284 | byte table[256] many
285285 |
286286 | routine main
287287 | outputs many
296296 The index must be initialized.
297297
298298 | byte one
299 | table[256] byte many
299 | byte table[256] many
300300 |
301301 | routine main
302302 | outputs many
333333 | }
334334 ? TypeMismatchError
335335
336 | table[256] byte many
336 | byte table[256] many
337337 |
338338 | routine main
339339 | outputs many
346346 | }
347347 ? TypeMismatchError
348348
349 | table[256] byte many
349 | byte table[256] many
350350 |
351351 | routine main
352352 | outputs many
359359 | }
360360 = ok
361361
362 | table[256] byte many
362 | byte table[256] many
363363 |
364364 | routine main
365365 | inputs many
373373
374374 The index must be initialized.
375375
376 | table[256] byte many
376 | byte table[256] many
377377 |
378378 | routine main
379379 | inputs many
387387 Copying to and from a word table.
388388
389389 | word one
390 | table[256] word many
390 | word table[256] many
391391 |
392392 | routine main
393393 | inputs one, many
401401 = ok
402402
403403 | word one
404 | table[256] word many
404 | byte table[256] many
405405 |
406406 | routine main
407407 | inputs one, many
414414 ? TypeMismatchError
415415
416416 | word one
417 | table[256] word many
417 | byte table[256] many
418418 |
419419 | routine main
420420 | inputs one, many
428428
429429 You can also copy a literal word to a word table.
430430
431 | table[256] word many
431 | word table[256] many
432432 |
433433 | routine main
434434 | inputs many
19481948 | outputs x
19491949 | trashes a, z, n
19501950 | one
1951 | table[256] vector routine
1952 | outputs x
1953 | trashes a, z, n
1954 | many
1951 | vector (routine
1952 | outputs x
1953 | trashes a, z, n)
1954 | table[256] many
19551955 |
19561956 | routine bar outputs x trashes a, z, n {
19571957 | ld x, 200
19741974 | outputs x
19751975 | trashes a, z, n
19761976 | one
1977 | table[256] vector routine
1978 | outputs x
1979 | trashes a, z, n
1980 | many
1977 | vector (routine
1978 | outputs x
1979 | trashes a, z, n)
1980 | table[256] many
19811981 |
19821982 | routine bar outputs x trashes a, z, n {
19831983 | ld x, 200
19961996
19971997 A routine can be copied into a vector table.
19981998
1999 | table[256] vector routine
1999 | vector (routine
20002000 | outputs x
2001 | trashes a, z, n
2002 | many
2001 | trashes a, z, n)
2002 | table[256] many
20032003 |
20042004 | routine bar outputs x trashes a, z, n {
20052005 | ld x, 200
20172017
20182018 A vector in a vector table cannot be directly called.
20192019
2020 | table[256] vector routine
2020 | vector (routine
20212021 | outputs x
2022 | trashes a, z, n
2023 | many
2022 | trashes a, z, n)
2023 | table[256] many
20242024 |
20252025 | routine bar outputs x trashes a, z, n {
20262026 | ld x, 200
138138
139139 Initialized byte table. Bytes allocated, but beyond the string, are 0's.
140140
141 | table[8] byte message : "WHAT?"
141 | byte table[8] message : "WHAT?"
142142 |
143143 | routine main
144144 | inputs message
351351 Indexed access.
352352
353353 | byte one
354 | table[256] byte many
354 | byte table[256] many
355355 |
356356 | routine main
357357 | outputs many
370370
371371 Byte tables take up 256 bytes in memory.
372372
373 | table[256] byte tab1
374 | table[256] byte tab2
373 | byte table[256] tab1
374 | byte table[256] tab2
375375 |
376376 | routine main
377377 | inputs tab1
457457
458458 You can also copy a literal word to a word table.
459459
460 | table[256] word many
460 | word table[256] many
461461 |
462462 | routine main
463463 | inputs many
526526 Copy word to word table and back, with both `x` and `y` as indexes.
527527
528528 | word one
529 | table[256] word many
529 | word table[256] many
530530 |
531531 | routine main
532532 | inputs one, many
611611 | outputs x
612612 | trashes a, z, n
613613 | one
614 | table[256] vector routine
614 | vector (routine
615615 | outputs x
616 | trashes a, z, n
617 | many
616 | trashes a, z, n)
617 | table[256] many
618618 |
619619 | routine bar outputs x trashes a, z, n {
620620 | ld x, 200
144144
145145 Tables of different types.
146146
147 | table[256] byte tab
148 | table[256] word wtab
149 | table[256] vector routine trashes a vtab
147 | byte table[256] tab
148 | word table[256] wtab
149 | vector (routine trashes a) table[256] vtab
150150 |
151151 | routine main {
152152 | }
155155 Typedefs of different types.
156156
157157 | typedef byte octet
158 | typedef table[256] octet twokay
158 | typedef octet table[256] twokay
159159 | typedef routine trashes a game_routine
160160 | vector game_routine start_game
161161 |
204204
205205 User-defined locations of other types.
206206
207 | table[256] byte screen @ 1024
207 | byte table[256] screen @ 1024
208208 | word r1
209209 | word r2 @ 60000
210210 | word r3 : 2000
215215
216216 Initialized byte table.
217217
218 | table[28] byte message : "WHAT DO YOU WANT TO DO NEXT?"
218 | byte table[32] message : "WHAT DO YOU WANT TO DO NEXT?"
219219 |
220220 | routine main {
221221 | }
317317
318318 Declaring byte and word table memory location.
319319
320 | table[256] byte tab
320 | byte table[256] tab
321321 |
322322 | routine main {
323323 | ld x, 0
328328 = ok
329329
330330 | word one
331 | table[256] word many
331 | word table[256] many
332332 |
333333 | routine main {
334334 | ld x, 0