git @ Cat's Eye Technologies SixtyPical / f0b8942
Allow vectors to be decorated with inputs/outputs/trashes; test. Chris Pressey 6 years ago
5 changed file(s) with 111 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
3232
3333 For 0.6:
3434
35 * `interrupt` routines.
36 * `goto` (tail call).
37 * `vector` type... with declared `inputs` `outputs` `trashes`?
38 * `copy` instruction... that can copy a constant to a user-def mem loc.
35 * declared `inputs` `outputs` `trashes` on the `vector` type.
36 * `goto` (tail call) a routine or a vector.
3937 * A more involved demo for the C64 — one that sets up an interrupt.
4038
4139 For 0.7:
4745
4846 At some point...
4947
48 * `interrupt` routines.
5049 * add line number (or at least routine name) to error messages.
5150 * 6502-mnemonic aliases (`sec`, `clc`)
5251 * other handy aliases (`eq` for `z`, etc.)
52 * have `copy` instruction able to copy a constant to a user-def mem loc, etc.
5353 * add absolute addressing in shl/shr, absolute-indexed for add, sub, etc.
5454 * check and disallow recursion.
8282
8383 byte table screen @ 1024
8484
85 A user-defined vector memory location is decorated with READS and WRITES lists
86 like a routine (see below), and it may only hold addresses of routines which
87 are compatible. (Meaning, the routine's inputs (resp. outputs, trashes)
88 must be a subset of the vector's inputs (resp. outputs, trashes.))
89
90 vector actor_logic
91 inputs a, score
92 outputs x
93 trashes y
94 @ $c000
95
8596 Routines
8697 --------
8798
349360 -------
350361
351362 Program ::= {Defn} {Routine}.
352 Defn ::= "byte" ["table"] NewIdent ["@" WordConst].
353 Routine ::= "routine" NewIdent
354 ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]
355 (Block | "@" WordConst).
363 Defn ::= Type NewIdent [Constraints] ["@" WordConst].
364 Type ::= "byte" ["table"] | "vector"
365 Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs].
366 Routine ::= "routine" NewIdent Constraints (Block | "@" WordConst).
356367 LocExprs::= LocExpr {"," LocExpr}.
357368 LocExpr ::= Register | Flag | LitByte | DefnIdent.
358369 Register::= "a" | "x" | "y".
131131 self.scanner.check_type('identifier')
132132 name = self.scanner.token
133133 self.scanner.scan()
134
135 (inputs, outputs, trashes) = self.constraints()
136 if type != TYPE_VECTOR and (inputs or outputs or trashes):
137 raise SyntaxError("Cannot apply constraints to non-vector type")
138
134139 addr = None
135140 if self.scanner.consume('@'):
136141 self.scanner.check_type('integer literal')
137142 addr = int(self.scanner.token)
138143 self.scanner.scan()
139 return Defn(name=name, type=type, addr=addr)
140
141 def routine(self):
142 self.scanner.expect('routine')
143 name = self.scanner.token
144 self.scanner.scan()
144 return Defn(name=name, type=type, addr=addr,
145 inputs=inputs, outputs=outputs, trashes=trashes)
146
147 def constraints(self):
145148 inputs = []
146149 outputs = []
147150 trashes = []
151154 outputs = self.locexprs()
152155 if self.scanner.consume('trashes'):
153156 trashes = self.locexprs()
157 return (inputs, outputs, trashes)
158
159 def routine(self):
160 self.scanner.expect('routine')
161 name = self.scanner.token
162 self.scanner.scan()
163 (inputs, outputs, trashes) = self.constraints()
154164 if self.scanner.consume('@'):
155165 self.scanner.check_type('integer literal')
156166 block = None
988988 | }
989989 ? UninitializedAccessError: x
990990
991 Can't `st` to a memory location that doesn't appear in (outputs ∪ trashes).
991 Can't `copy` to a memory location that doesn't appear in (outputs ∪ trashes).
992992
993993 | byte lives
994994 | routine main
10351035 | copy 0, lives
10361036 | }
10371037 ? UninitializedOutputError: a
1038
1039 Unless of course you subsequently initialize them.
1040
1041 | byte lives
1042 | routine main
1043 | outputs lives, a, z, n
1044 | {
1045 | copy 0, lives
1046 | ld a, 0
1047 | }
1048 = ok
1049
1050 You can copy the address of a routine into a vector, if that vector is declared appropriately.
1051
1052 | vector vec
1053 | inputs x
1054 | outputs x
1055 | trashes z, n
1056 |
1057 | routine foo
1058 | inputs x
1059 | outputs x
1060 | trashes z, n
1061 | {
1062 | inc x
1063 | }
1064 |
1065 | routine main
1066 | inputs foo
1067 | outputs vec
1068 | trashes a, z, n
1069 | {
1070 | copy foo, vec
1071 | }
1072 = ok
1073
1074 But not if the vector is declared inappropriately.
1075
1076 | vector vec
1077 | inputs y
1078 | outputs y
1079 | trashes z, n
1080 |
1081 | routine foo
1082 | inputs x
1083 | outputs x
1084 | trashes z, n
1085 | {
1086 | inc x
1087 | }
1088 |
1089 | routine main
1090 | inputs foo
1091 | outputs vec
1092 | trashes a, z, n
1093 | {
1094 | copy foo, vec
1095 | }
1096 ? IllegalWriteError
217217 Declaring a vector.
218218
219219 | vector cinv
220 | inputs a
221 | outputs x
222 | trashes a, x, z, n
223 | @ 788
220224 |
221225 | routine foo {
222226 | ld a, 0
227231 | }
228232 | }
229233 = ok
234
235 Only vectors can be decorated with constraints like that.
236
237 | byte cinv
238 | inputs a
239 | outputs x
240 | trashes a, x, z, n
241 | @ 788
242 |
243 | routine main {
244 | }
245 ? SyntaxError