git @ Cat's Eye Technologies SixtyPical / be76b9a
Syntax for `goto`. Chris Pressey 6 years ago
4 changed file(s) with 40 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3232
3333 For 0.6:
3434
35 * `call` vector (generates an indirect JMP.)
35 * `call` vector (generates an JSR to a trampoline that does indirect JMP.)
3636 * `goto` (tail call) a routine or a vector.
3737 * A more involved demo for the C64 — one that sets up an interrupt?
3838
362362 After execution, dest is considered initialized, and `z` and `n`, and
363363 `a` are considered uninitialized.
364364
365 ### goto ###
366
367 TBW
368
365369 Grammar
366370 -------
367371
368372 Program ::= {Defn} {Routine}.
369 Defn ::= Type NewIdent [Constraints] ["@" WordConst].
373 Defn ::= Type Ident<new> [Constraints] ["@" WordConst].
370374 Type ::= "byte" ["table"] | "vector"
371375 Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs].
372 Routine ::= "routine" NewIdent Constraints (Block | "@" WordConst).
376 Routine ::= "routine" Ident<new> Constraints (Block | "@" WordConst).
373377 LocExprs::= LocExpr {"," LocExpr}.
374 LocExpr ::= Register | Flag | LitByte | DefnIdent.
378 LocExpr ::= Register | Flag | LitByte | Ident.
375379 Register::= "a" | "x" | "y".
376380 Flag ::= "c" | "z" | "n" | "v".
377381 LitByte ::= "0" ... "255".
389393 | "shr" LocExpr
390394 | "inc" LocExpr
391395 | "dec" LocExpr
392 | "call" RoutineIdent
396 | "call" Ident<routine>
397 | "goto" Ident<executable>
393398 | "if" ["not"] LocExpr Block ["else" Block]
394399 | "repeat" Block ("until" ["not"] LocExpr | "forever")
395400 | "copy" LocExpr "," LocExpr ["+" LocExpr]
259259 self.scanner.scan()
260260 dest = self.locexpr()
261261 return Instr(opcode=opcode, dest=dest, src=None)
262 elif self.scanner.token in ("call",):
262 elif self.scanner.token in ("call", "goto"):
263263 opcode = self.scanner.token
264264 self.scanner.scan()
265265 name = self.scanner.token
247247 | routine main {
248248 | }
249249 ? SyntaxError
250
251 goto.
252
253 | routine foo {
254 | ld a, 0
255 | }
256 | routine main {
257 | goto foo
258 | }
259 = ok
260
261 | vector foo
262 |
263 | routine main {
264 | goto foo
265 | }
266 = ok
267
268 | routine main {
269 | goto foo
270 | }
271 ? SyntaxError
272
273 | byte foo
274 |
275 | routine main {
276 | goto foo
277 | }
278 ? SyntaxError