git @ Cat's Eye Technologies SixtyPical / 7c9f76c
Removing support for it is one thing, updating all tests another. Chris Pressey 4 years ago
2 changed file(s) with 97 addition(s) and 101 deletion(s). Raw diff Collapse all Expand all
8282 defn = self.defn()
8383 self.declare(defn.name, SymEntry(defn, defn.location))
8484 defns.append(defn)
85 while self.scanner.on('define', 'routine'):
86 if self.scanner.consume('define'):
87 name = self.scanner.token
88 self.scanner.scan()
89 routine = self.routine(name)
90 else:
91 routine = self.legacy_routine()
92 name = routine.name
85 while self.scanner.consume('define'):
86 name = self.scanner.token
87 self.scanner.scan()
88 routine = self.routine(name)
9389 self.declare(name, SymEntry(routine, routine.location))
9490 routines.append(routine)
9591 self.scanner.check_type('EOF')
256252 if self.scanner.consume('trashes'):
257253 trashes = set(self.labels())
258254 return (inputs, outputs, trashes)
259
260 def legacy_routine(self):
261 self.scanner.expect('routine')
262 name = self.scanner.token
263 self.scanner.scan()
264 (inputs, outputs, trashes) = self.constraints()
265 type_ = RoutineType(inputs=inputs, outputs=outputs, trashes=trashes)
266 if self.scanner.consume('@'):
267 self.scanner.check_type('integer literal')
268 block = None
269 addr = int(self.scanner.token)
270 self.scanner.scan()
271 else:
272 block = self.block()
273 addr = None
274 location = LocationRef(type_, name)
275 return Routine(
276 self.scanner.line_number,
277 name=name, block=block, addr=addr,
278 location=location
279 )
280255
281256 def routine(self, name):
282257 type_ = self.defn_type()
1515
1616 Rudimentary program.
1717
18 | routine main {
18 | define main routine {
1919 | ld a, 0
2020 | add a, 1
2121 | }
2525
2626 | // Welcome to my program.
2727 |
28 | routine main {
28 | define main routine {
2929 | ld a, 0
3030 | add a, 1 // We are adding the thing.
3131 | sub a, 1
3939
4040 Hex literals.
4141
42 | routine main {
42 | define main routine {
4343 | ld a, $ff
4444 | add a, $01
4545 | }
4747
4848 Syntax error.
4949
50 | routine foo (
50 | define foo routine (
5151 | ld a, 0
5252 | add a, 1
5353 | )
6464
6565 Extern routines
6666
67 | routine chrout
67 | define chrout routine
6868 | inputs a
6969 | trashes a
7070 | @ 65490
7171 |
72 | routine chrin
72 | define chrin routine
7373 | outputs a
7474 | trashes x
7575 | @ 65487
7777
7878 Trash.
7979
80 | routine main {
80 | define main routine {
8181 | trash a
8282 | trash n
8383 | }
8585
8686 `nop`.
8787
88 | routine main
88 | define main routine
8989 | {
9090 | nop
9191 | }
9393
9494 If with not
9595
96 | routine foo {
96 | define foo routine {
9797 | ld y, 0
9898 | cmp y, 10
9999 | if not z {
105105
106106 Repeat loop
107107
108 | routine foo {
108 | define foo routine {
109109 | ld y, 0
110110 | repeat {
111111 | inc y
116116
117117 "While" loop
118118
119 | routine foo inputs y {
119 | define foo routine inputs y {
120120 | repeat {
121121 | cmp y, 10
122122 | if not z {
128128
129129 Repeat forever
130130
131 | routine foo inputs y {
131 | define foo routine inputs y {
132132 | repeat {
133133 | inc y
134134 | } forever
137137
138138 Repeat with not
139139
140 | routine foo inputs y {
140 | define foo routine inputs y {
141141 | repeat {
142142 | inc y
143143 | } until not z
148148
149149 | byte table[256] tab
150150 |
151 | routine foo trashes a, x, c, z, v {
151 | define foo routine trashes a, x, c, z, v {
152152 | ld x, 0
153153 | for x up to 15 {
154154 | ld a, tab + x
162162
163163 Other blocks.
164164
165 | routine main trashes a, x, c, z, v {
165 | define main routine trashes a, x, c, z, v {
166166 | with interrupts off {
167167 | save a, x, c {
168168 | ld a, 0
182182 | buffer[2048] buf
183183 | pointer ptr
184184 |
185 | routine main {
185 | define main routine {
186186 | }
187187 = ok
188188
192192 | word table[256] wmany
193193 | vector (routine trashes a) table[256] vmany
194194 |
195 | routine main {
195 | define main routine {
196196 | ld x, 0
197197 | ld a, 0
198198 | st off, c
214214
215215 | word table[512] many
216216 |
217 | routine main
217 | define main routine
218218 | inputs many
219219 | outputs many
220220 | trashes a, x, n, z
226226
227227 | word table[0] many
228228 |
229 | routine main
229 | define main routine
230230 | inputs many
231231 | outputs many
232232 | trashes a, x, n, z
238238
239239 | word table[48] many
240240 |
241 | routine main
241 | define main routine
242242 | inputs many
243243 | outputs many
244244 | trashes a, x, n, z
255255 | typedef routine trashes a game_routine
256256 | vector game_routine start_game
257257 |
258 | routine main {
258 | define main routine {
259259 | }
260260 = ok
261261
264264 | typedef byte frank
265265 | typedef word frank
266266 |
267 | routine main {
267 | define main routine {
268268 | }
269269 ? SyntaxError
270270
279279 |
280280 | byte lark: lives
281281 |
282 | routine main {
282 | define main routine {
283283 | ld a, lives
284284 | }
285285 = ok
289289 | const w1 1000
290290 | const w1 word 0
291291 |
292 | routine main {
292 | define main routine {
293293 | }
294294 ? SyntaxError
295295
297297
298298 | byte screen @ 1024
299299 |
300 | routine main {
300 | define main routine {
301301 | ld a, 100
302302 | st a, screen
303303 | shl screen
309309
310310 | byte lives : 3
311311 |
312 | routine main {
312 | define main routine {
313313 | ld a, lives
314314 | st a, lives
315315 | }
319319
320320 | byte screen : 3 @ 1024
321321 |
322 | routine main {
322 | define main routine {
323323 | ld a, lives
324324 | st a, lives
325325 | }
332332 | word r2 @ 60000
333333 | word r3 : 2000
334334 |
335 | routine main {
335 | define main routine {
336336 | }
337337 = ok
338338
340340
341341 | byte table[32] message : "WHAT DO YOU WANT TO DO NEXT?"
342342 |
343 | routine main {
343 | define main routine {
344344 | }
345345 = ok
346346
347347 Can't initialize anything but a byte table with a string.
348348
349 | word message : "WHAT DO YOU WANT TO DO NEXT?"
350 |
351 | routine main {
349 | word message : "OUCH! WHAT DO YOU DO?"
350 |
351 | define main routine {
352352 | }
353353 ? SyntaxError
354354
356356
357357 | byte table[8] charmap : 0, 255, 129, 192, 0, 1, 2, 4
358358 |
359 | routine main {
359 | define main routine {
360360 | }
361361 = ok
362362
363363 Can't access an undeclared memory location.
364364
365 | routine main {
365 | define main routine {
366366 | ld a, 0
367367 | st a, lives
368368 | }
373373 | byte lives
374374 | byte lives
375375 |
376 | routine main {
376 | define main routine {
377377 | ld a, 0
378378 | st a, lives
379379 | }
383383
384384 | byte a
385385 |
386 | routine main {
386 | define main routine {
387387 | }
388388 ? SyntaxError
389389
390390 | byte z
391391 |
392 | routine main {
392 | define main routine {
393393 | }
394394 ? SyntaxError
395395
396396 Can't call routine that hasn't been defined.
397397
398 | routine main {
398 | define main routine {
399399 | ld x, 0
400400 | ld y, 1
401401 | call up
407407
408408 | byte up
409409 |
410 | routine main {
410 | define main routine {
411411 | ld x, 0
412412 | ld y, 1
413413 | call up
414414 | }
415415 ? SyntaxError
416416
417 | routine main {
417 | define main routine {
418418 | ld x, 0
419419 | ld y, 1
420420 | call x
423423
424424 But you can call a routine that is yet to be defined, further on.
425425
426 | routine main {
426 | define main routine {
427427 | ld x, 0
428428 | ld y, 1
429429 | call up
430430 | call up
431431 | }
432 | routine up {
432 | define up routine {
433433 | ld a, 0
434434 | }
435435 = ok
436436
437437 Can't define two routines with the same name.
438438
439 | routine main {
439 | define main routine {
440440 | inc x
441441 | inc y
442442 | }
443 | routine main {
443 | define main routine {
444444 | ld x, 0
445445 | ld y, 1
446446 | }
450450
451451 | byte table[256] tab
452452 |
453 | routine main {
453 | define main routine {
454454 | ld x, 0
455455 | ld y, 0
456456 | ld a, tab + x
461461 | word one
462462 | word table[256] many
463463 |
464 | routine main {
464 | define main routine {
465465 | ld x, 0
466466 | copy one, many + x
467467 | copy word 0, many + x
477477 | trashes a, x, z, n
478478 | cinv @ 788
479479 |
480 | routine foo {
481 | ld a, 0
482 | }
483 | routine main {
480 | define foo routine {
481 | ld a, 0
482 | }
483 | define main routine {
484484 | with interrupts off {
485485 | copy foo, cinv
486486 | }
496496 | trashes a, x, z, n
497497 | @ 788
498498 |
499 | routine main {
499 | define main routine {
500500 | }
501501 ? SyntaxError
502502
508508 | trashes a, x, z, n
509509 | cinv @ 788
510510 |
511 | routine foo {
512 | ld a, 0
513 | }
514 | routine main {
511 | define foo routine {
512 | ld a, 0
513 | }
514 | define main routine {
515515 | with interrupts off {
516516 | copy foo, cinv
517517 | }
527527 | trashes a, x, z, n
528528 | cinv @ 788
529529 |
530 | routine foo {
531 | ld a, 0
532 | }
533 | routine main {
530 | define foo routine {
531 | ld a, 0
532 | }
533 | define main routine {
534534 | with interrupts off {
535535 | copy foo, cinv
536536 | }
547547 | outputs cinv, x
548548 | trashes a, x, z, n
549549 | cinv @ 788
550 | routine main {
550 | define main routine {
551551 | with interrupts off {
552552 | copy foo, cinv
553553 | }
554554 | call cinv
555555 | }
556 | routine foo {
556 | define foo routine {
557557 | ld a, 0
558558 | }
559559 = ok
560560
561561 goto.
562562
563 | routine foo {
564 | ld a, 0
565 | }
566 | routine main {
563 | define foo routine {
564 | ld a, 0
565 | }
566 | define main routine {
567567 | goto foo
568568 | }
569569 = ok
570570
571 | routine main {
571 | define main routine {
572572 | goto foo
573573 | }
574 | routine foo {
574 | define foo routine {
575575 | ld a, 0
576576 | }
577577 = ok
578578
579579 | vector routine foo
580580 |
581 | routine main {
581 | define main routine {
582582 | goto foo
583583 | }
584584 = ok
585585
586 | routine main {
586 | define main routine {
587587 | goto foo
588588 | }
589589 ? SyntaxError
590590
591591 | byte foo
592592 |
593 | routine main {
593 | define main routine {
594594 | goto foo
595595 | }
596596 ? SyntaxError
602602 | pointer ptrb
603603 | byte foo
604604 |
605 | routine main {
605 | define main routine {
606606 | copy ^buf, ptr
607607 | copy 123, [ptr] + y
608608 | copy [ptr] + y, foo
628628 | inc x
629629 | }
630630 |
631 | routine main
631 | define main routine
632 | outputs vec
633 | trashes a, z, n
634 | {
635 | copy foo, vec
636 | }
637 = ok
638
639 | typedef routine
640 | inputs x
641 | outputs x
642 | trashes z, n
643 | routine_type
644 |
645 | vector routine_type vec
646 |
647 | define foo routine_type
648 | {
649 | inc x
650 | }
651 |
652 | define main routine
632653 | outputs vec
633654 | trashes a, z, n
634655 | {