mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-11-26 14:49:15 +00:00
Add syntax for extern routines, add syntax tests.
This commit is contained in:
parent
d716c9b4e0
commit
49d90dfae0
@ -103,6 +103,15 @@ some memory locations causes those memory locations to be uninitialized after
|
|||||||
that routine is called. At the end of a routine, all memory locations listed
|
that routine is called. At the end of a routine, all memory locations listed
|
||||||
as outputs must be initialised.
|
as outputs must be initialised.
|
||||||
|
|
||||||
|
A routine can also be declared as "external", in which case its body need
|
||||||
|
not be defined but an absolute address must be given for where the routine
|
||||||
|
is located in memory.
|
||||||
|
|
||||||
|
routine chrout
|
||||||
|
inputs a
|
||||||
|
trashes a
|
||||||
|
@ 65490
|
||||||
|
|
||||||
Instructions
|
Instructions
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@ -291,12 +300,13 @@ Grammar
|
|||||||
Defn ::= "byte" NewIdent.
|
Defn ::= "byte" NewIdent.
|
||||||
Routine ::= "routine" NewIdent
|
Routine ::= "routine" NewIdent
|
||||||
["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]
|
["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]
|
||||||
Block.
|
(Block | "@" WordConst).
|
||||||
LocExprs::= LocExpr {"," LocExpr}.
|
LocExprs::= LocExpr {"," LocExpr}.
|
||||||
LocExpr ::= Register | Flag | Const | DefnIdent.
|
LocExpr ::= Register | Flag | LitByte | DefnIdent.
|
||||||
Register::= "a" | "x" | "y".
|
Register::= "a" | "x" | "y".
|
||||||
Flag ::= "c" | "z" | "n" | "v".
|
Flag ::= "c" | "z" | "n" | "v".
|
||||||
Const ::= "0" ... "255".
|
LitByte ::= "0" ... "255".
|
||||||
|
LitWord ::= "0" ... "65535".
|
||||||
Block ::= "{" {Instr} "}".
|
Block ::= "{" {Instr} "}".
|
||||||
Instr ::= "ld" LocExpr "," LocExpr
|
Instr ::= "ld" LocExpr "," LocExpr
|
||||||
| "st" LocExpr "," LocExpr
|
| "st" LocExpr "," LocExpr
|
||||||
|
@ -30,7 +30,7 @@ class Scanner(object):
|
|||||||
self.token = None
|
self.token = None
|
||||||
self.type = 'EOF'
|
self.type = 'EOF'
|
||||||
return
|
return
|
||||||
if self.scan_pattern(r'\,|\/|\{|\}', 'operator'):
|
if self.scan_pattern(r'\,|\@|\{|\}', 'operator'):
|
||||||
return
|
return
|
||||||
if self.scan_pattern(r'\d+', 'integer literal'):
|
if self.scan_pattern(r'\d+', 'integer literal'):
|
||||||
return
|
return
|
||||||
@ -119,10 +119,17 @@ class Parser(object):
|
|||||||
outputs = self.locexprs()
|
outputs = self.locexprs()
|
||||||
if self.scanner.consume('trashes'):
|
if self.scanner.consume('trashes'):
|
||||||
trashes = self.locexprs()
|
trashes = self.locexprs()
|
||||||
|
if self.scanner.consume('@'):
|
||||||
|
self.scanner.check_type('integer literal')
|
||||||
|
block = None
|
||||||
|
addr = int(self.scanner.token)
|
||||||
|
self.scanner.scan()
|
||||||
|
else:
|
||||||
block = self.block()
|
block = self.block()
|
||||||
|
addr = None
|
||||||
return Routine(
|
return Routine(
|
||||||
name=name, inputs=inputs, outputs=outputs, trashes=trashes,
|
name=name, inputs=inputs, outputs=outputs, trashes=trashes,
|
||||||
block=block
|
block=block, addr=addr
|
||||||
)
|
)
|
||||||
|
|
||||||
def locexprs(self):
|
def locexprs(self):
|
||||||
|
1
test.sh
1
test.sh
@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
falderal --substring-error \
|
falderal --substring-error \
|
||||||
|
tests/SixtyPical\ Syntax.md \
|
||||||
tests/SixtyPical\ Execution.md \
|
tests/SixtyPical\ Execution.md \
|
||||||
tests/SixtyPical\ Analysis.md \
|
tests/SixtyPical\ Analysis.md \
|
||||||
tests/SixtyPical\ Compilation.md
|
tests/SixtyPical\ Compilation.md
|
||||||
|
@ -29,3 +29,20 @@ Rudimentary program.
|
|||||||
| add a, 4
|
| add a, 4
|
||||||
| }
|
| }
|
||||||
= 00c018690460
|
= 00c018690460
|
||||||
|
|
||||||
|
Call extern.
|
||||||
|
|
||||||
|
| routine chrout
|
||||||
|
| inputs a
|
||||||
|
| trashes a
|
||||||
|
| @ 65490
|
||||||
|
|
|
||||||
|
| routine main
|
||||||
|
| inputs a
|
||||||
|
| outputs a
|
||||||
|
| trashes c, z, n, v
|
||||||
|
| {
|
||||||
|
| ld a, 65
|
||||||
|
| call chrout
|
||||||
|
| }
|
||||||
|
= 00c018690460
|
||||||
|
41
tests/SixtyPical Syntax.md
Normal file
41
tests/SixtyPical Syntax.md
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
Sixtypical Execution
|
||||||
|
====================
|
||||||
|
|
||||||
|
This is a test suite, written in [Falderal][] format, for the syntax of
|
||||||
|
the Sixtypical language, disgregarding execution, static analysis, etc.
|
||||||
|
|
||||||
|
[Falderal]: http://catseye.tc/node/Falderal
|
||||||
|
|
||||||
|
-> Functionality "Check syntax of Sixtypical program" is implemented by
|
||||||
|
-> shell command "bin/sixtypical %(test-body-file) && echo ok"
|
||||||
|
|
||||||
|
-> Tests for functionality "Check syntax of Sixtypical program"
|
||||||
|
|
||||||
|
Rudimentary program.
|
||||||
|
|
||||||
|
| routine main {
|
||||||
|
| ld a, 0
|
||||||
|
| add a, 1
|
||||||
|
| }
|
||||||
|
= ok
|
||||||
|
|
||||||
|
Syntax error
|
||||||
|
|
||||||
|
| routine foo (
|
||||||
|
| ld a, 0
|
||||||
|
| add a, 1
|
||||||
|
| )
|
||||||
|
? SyntaxError
|
||||||
|
|
||||||
|
Extern routines
|
||||||
|
|
||||||
|
| routine chrout
|
||||||
|
| inputs a
|
||||||
|
| trashes a
|
||||||
|
| @ 65490
|
||||||
|
|
|
||||||
|
| routine chrin
|
||||||
|
| outputs a
|
||||||
|
| trashes x
|
||||||
|
| @ 65487
|
||||||
|
= ok
|
Loading…
Reference in New Issue
Block a user