git @ Cat's Eye Technologies SixtyPical / 49d90df
Add syntax for extern routines, add syntax tests. Chris Pressey 6 years ago
5 changed file(s) with 82 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
102102 that routine is called. At the end of a routine, all memory locations listed
103103 as outputs must be initialised.
104104
105 A routine can also be declared as "external", in which case its body need
106 not be defined but an absolute address must be given for where the routine
107 is located in memory.
108
109 routine chrout
110 inputs a
111 trashes a
112 @ 65490
113
105114 Instructions
106115 ------------
107116
290299 Defn ::= "byte" NewIdent.
291300 Routine ::= "routine" NewIdent
292301 ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]
293 Block.
302 (Block | "@" WordConst).
294303 LocExprs::= LocExpr {"," LocExpr}.
295 LocExpr ::= Register | Flag | Const | DefnIdent.
304 LocExpr ::= Register | Flag | LitByte | DefnIdent.
296305 Register::= "a" | "x" | "y".
297306 Flag ::= "c" | "z" | "n" | "v".
298 Const ::= "0" ... "255".
307 LitByte ::= "0" ... "255".
308 LitWord ::= "0" ... "65535".
299309 Block ::= "{" {Instr} "}".
300310 Instr ::= "ld" LocExpr "," LocExpr
301311 | "st" LocExpr "," LocExpr
2929 self.token = None
3030 self.type = 'EOF'
3131 return
32 if self.scan_pattern(r'\,|\/|\{|\}', 'operator'):
32 if self.scan_pattern(r'\,|\@|\{|\}', 'operator'):
3333 return
3434 if self.scan_pattern(r'\d+', 'integer literal'):
3535 return
118118 outputs = self.locexprs()
119119 if self.scanner.consume('trashes'):
120120 trashes = self.locexprs()
121 block = self.block()
121 if self.scanner.consume('@'):
122 self.scanner.check_type('integer literal')
123 block = None
124 addr = int(self.scanner.token)
125 self.scanner.scan()
126 else:
127 block = self.block()
128 addr = None
122129 return Routine(
123130 name=name, inputs=inputs, outputs=outputs, trashes=trashes,
124 block=block
131 block=block, addr=addr
125132 )
126133
127134 def locexprs(self):
00 #!/bin/sh
11
22 falderal --substring-error \
3 tests/SixtyPical\ Syntax.md \
34 tests/SixtyPical\ Execution.md \
45 tests/SixtyPical\ Analysis.md \
56 tests/SixtyPical\ Compilation.md
2828 | add a, 4
2929 | }
3030 = 00c018690460
31
32 Call extern.
33
34 | routine chrout
35 | inputs a
36 | trashes a
37 | @ 65490
38 |
39 | routine main
40 | inputs a
41 | outputs a
42 | trashes c, z, n, v
43 | {
44 | ld a, 65
45 | call chrout
46 | }
47 = 00c018690460
0 Sixtypical Execution
1 ====================
2
3 This is a test suite, written in [Falderal][] format, for the syntax of
4 the Sixtypical language, disgregarding execution, static analysis, etc.
5
6 [Falderal]: http://catseye.tc/node/Falderal
7
8 -> Functionality "Check syntax of Sixtypical program" is implemented by
9 -> shell command "bin/sixtypical %(test-body-file) && echo ok"
10
11 -> Tests for functionality "Check syntax of Sixtypical program"
12
13 Rudimentary program.
14
15 | routine main {
16 | ld a, 0
17 | add a, 1
18 | }
19 = ok
20
21 Syntax error
22
23 | routine foo (
24 | ld a, 0
25 | add a, 1
26 | )
27 ? SyntaxError
28
29 Extern routines
30
31 | routine chrout
32 | inputs a
33 | trashes a
34 | @ 65490
35 |
36 | routine chrin
37 | outputs a
38 | trashes x
39 | @ 65487
40 = ok