Move test, add test, add assertion.
Chris Pressey
4 years ago
206 | 206 | |
207 | 207 | def routine(self, name): |
208 | 208 | type_ = self.defn_type() |
209 | # TODO assert that it's a routine | |
209 | if not isinstance(type_, RoutineType): | |
210 | raise SyntaxError("Can only define a routine, not %r" % type_) | |
210 | 211 | if self.scanner.consume('@'): |
211 | 212 | self.scanner.check_type('integer literal') |
212 | 213 | block = None |
401 | 401 | = ok |
402 | 402 | |
403 | 403 | | word one |
404 | | byte table[256] many | |
404 | | word table[256] many | |
405 | 405 | | |
406 | 406 | | routine main |
407 | 407 | | inputs one, many |
414 | 414 | ? TypeMismatchError |
415 | 415 | |
416 | 416 | | word one |
417 | | byte table[256] many | |
417 | | word table[256] many | |
418 | 418 | | |
419 | 419 | | routine main |
420 | 420 | | inputs one, many |
2066 | 2066 | | } |
2067 | 2067 | = ok |
2068 | 2068 | |
2069 | Routines can be defined in a new style. | |
2069 | The new style routine definitions support typedefs. | |
2070 | 2070 | |
2071 | 2071 | | typedef routine |
2072 | 2072 | | inputs x |
2076 | 2076 | | |
2077 | 2077 | | vector routine_type vec |
2078 | 2078 | | |
2079 | | define foo routine | |
2080 | | inputs x | |
2081 | | outputs x | |
2082 | | trashes z, n | |
2079 | | define foo routine_type | |
2083 | 2080 | | { |
2084 | 2081 | | inc x |
2085 | 2082 | | } |
2091 | 2088 | | copy foo, vec |
2092 | 2089 | | } |
2093 | 2090 | = ok |
2094 | ||
2095 | The new style routine definitions support typedefs. | |
2096 | ||
2097 | | typedef routine | |
2098 | | inputs x | |
2099 | | outputs x | |
2100 | | trashes z, n | |
2101 | | routine_type | |
2102 | | | |
2103 | | vector routine_type vec | |
2104 | | | |
2105 | | define foo routine_type | |
2106 | | { | |
2107 | | inc x | |
2108 | | } | |
2109 | | | |
2110 | | routine main | |
2111 | | outputs vec | |
2112 | | trashes a, z, n | |
2113 | | { | |
2114 | | copy foo, vec | |
2115 | | } | |
2116 | = ok |
491 | 491 | | copy [ptr] + y, foo |
492 | 492 | | } |
493 | 493 | = ok |
494 | ||
495 | Routines can be defined in a new style. | |
496 | ||
497 | | typedef routine | |
498 | | inputs x | |
499 | | outputs x | |
500 | | trashes z, n | |
501 | | routine_type | |
502 | | | |
503 | | vector routine_type vec | |
504 | | | |
505 | | define foo routine | |
506 | | inputs x | |
507 | | outputs x | |
508 | | trashes z, n | |
509 | | { | |
510 | | inc x | |
511 | | } | |
512 | | | |
513 | | routine main | |
514 | | outputs vec | |
515 | | trashes a, z, n | |
516 | | { | |
517 | | copy foo, vec | |
518 | | } | |
519 | = ok | |
520 | ||
521 | Only routines can be defined in the new style. | |
522 | ||
523 | | define foo byte table[256] | |
524 | | | |
525 | | routine main | |
526 | | trashes a, z, n | |
527 | | { | |
528 | | ld a, 0 | |
529 | | } | |
530 | ? SyntaxError |