1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-29 18:49:22 +00:00

Syntax for goto.

This commit is contained in:
Chris Pressey 2015-10-20 14:10:33 +01:00
parent 16649042cb
commit be76b9a00d
4 changed files with 40 additions and 6 deletions

View File

@ -33,7 +33,7 @@ TODO
For 0.6: For 0.6:
* `call` vector (generates an indirect JMP.) * `call` vector (generates an JSR to a trampoline that does indirect JMP.)
* `goto` (tail call) a routine or a vector. * `goto` (tail call) a routine or a vector.
* A more involved demo for the C64 — one that sets up an interrupt? * A more involved demo for the C64 — one that sets up an interrupt?

View File

@ -363,16 +363,20 @@ copy more general types of data (for example, vectors,) and it trashes the
After execution, dest is considered initialized, and `z` and `n`, and After execution, dest is considered initialized, and `z` and `n`, and
`a` are considered uninitialized. `a` are considered uninitialized.
### goto ###
TBW
Grammar Grammar
------- -------
Program ::= {Defn} {Routine}. Program ::= {Defn} {Routine}.
Defn ::= Type NewIdent [Constraints] ["@" WordConst]. Defn ::= Type Ident<new> [Constraints] ["@" WordConst].
Type ::= "byte" ["table"] | "vector" Type ::= "byte" ["table"] | "vector"
Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]. Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs].
Routine ::= "routine" NewIdent Constraints (Block | "@" WordConst). Routine ::= "routine" Ident<new> Constraints (Block | "@" WordConst).
LocExprs::= LocExpr {"," LocExpr}. LocExprs::= LocExpr {"," LocExpr}.
LocExpr ::= Register | Flag | LitByte | DefnIdent. LocExpr ::= Register | Flag | LitByte | Ident.
Register::= "a" | "x" | "y". Register::= "a" | "x" | "y".
Flag ::= "c" | "z" | "n" | "v". Flag ::= "c" | "z" | "n" | "v".
LitByte ::= "0" ... "255". LitByte ::= "0" ... "255".
@ -390,7 +394,8 @@ Grammar
| "shr" LocExpr | "shr" LocExpr
| "inc" LocExpr | "inc" LocExpr
| "dec" LocExpr | "dec" LocExpr
| "call" RoutineIdent | "call" Ident<routine>
| "goto" Ident<executable>
| "if" ["not"] LocExpr Block ["else" Block] | "if" ["not"] LocExpr Block ["else" Block]
| "repeat" Block ("until" ["not"] LocExpr | "forever") | "repeat" Block ("until" ["not"] LocExpr | "forever")
| "copy" LocExpr "," LocExpr ["+" LocExpr] | "copy" LocExpr "," LocExpr ["+" LocExpr]

View File

@ -260,7 +260,7 @@ class Parser(object):
self.scanner.scan() self.scanner.scan()
dest = self.locexpr() dest = self.locexpr()
return Instr(opcode=opcode, dest=dest, src=None) return Instr(opcode=opcode, dest=dest, src=None)
elif self.scanner.token in ("call",): elif self.scanner.token in ("call", "goto"):
opcode = self.scanner.token opcode = self.scanner.token
self.scanner.scan() self.scanner.scan()
name = self.scanner.token name = self.scanner.token

View File

@ -248,3 +248,32 @@ Only vectors can be decorated with constraints like that.
| routine main { | routine main {
| } | }
? SyntaxError ? SyntaxError
goto.
| routine foo {
| ld a, 0
| }
| routine main {
| goto foo
| }
= ok
| vector foo
|
| routine main {
| goto foo
| }
= ok
| routine main {
| goto foo
| }
? SyntaxError
| byte foo
|
| routine main {
| goto foo
| }
? SyntaxError