diff --git a/README.markdown b/README.markdown index 3831af3..84ee4e6 100644 --- a/README.markdown +++ b/README.markdown @@ -33,7 +33,7 @@ TODO 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. * A more involved demo for the C64 — one that sets up an interrupt? diff --git a/doc/SixtyPical.md b/doc/SixtyPical.md index 53a78f8..b21770d 100644 --- a/doc/SixtyPical.md +++ b/doc/SixtyPical.md @@ -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 `a` are considered uninitialized. +### goto ### + +TBW + Grammar ------- Program ::= {Defn} {Routine}. - Defn ::= Type NewIdent [Constraints] ["@" WordConst]. + Defn ::= Type Ident [Constraints] ["@" WordConst]. Type ::= "byte" ["table"] | "vector" Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]. - Routine ::= "routine" NewIdent Constraints (Block | "@" WordConst). + Routine ::= "routine" Ident Constraints (Block | "@" WordConst). LocExprs::= LocExpr {"," LocExpr}. - LocExpr ::= Register | Flag | LitByte | DefnIdent. + LocExpr ::= Register | Flag | LitByte | Ident. Register::= "a" | "x" | "y". Flag ::= "c" | "z" | "n" | "v". LitByte ::= "0" ... "255". @@ -390,7 +394,8 @@ Grammar | "shr" LocExpr | "inc" LocExpr | "dec" LocExpr - | "call" RoutineIdent + | "call" Ident + | "goto" Ident | "if" ["not"] LocExpr Block ["else" Block] | "repeat" Block ("until" ["not"] LocExpr | "forever") | "copy" LocExpr "," LocExpr ["+" LocExpr] diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 198b0dd..2323213 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -260,7 +260,7 @@ class Parser(object): self.scanner.scan() dest = self.locexpr() 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 self.scanner.scan() name = self.scanner.token diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index ed3b687..0567d2d 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -248,3 +248,32 @@ Only vectors can be decorated with constraints like that. | routine main { | } ? 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