git @ Cat's Eye Technologies SixtyPical / f2f716d
Going over the spec for version 0.8-PRE. Chris Pressey 4 years ago
1 changed file(s) with 75 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
1313 Types
1414 -----
1515
16 There are five TYPES in SixtyPical:
16 There are seven *types* in SixtyPical:
1717
1818 * bit (2 possible values)
1919 * byte (256 possible values)
2020 * byte table (256 entries, each holding a byte)
21 * word (65536 possible values)
22 * word table (256 entries, each holding a word)
2123 * routine (code stored somewhere in memory, read-only)
2224 * vector (address of a routine)
2325
2426 Memory locations
2527 ----------------
2628
27 A primary concept in SixtyPical is the MEMORY LOCATION. At any given point
28 in time during execution, each memory location is either UNINITIALIZED or
29 INITIALIZED. At any given point in the program text, too, each memory
29 A primary concept in SixtyPical is the *memory location*. At any given point
30 in time during execution, each memory location is either *uninitialized* or
31 *initialized*. At any given point in the program text, too, each memory
3032 location is either uninitialized or initialized. Where-ever it is one or
3133 the other during execution, it is the same in the corresponding place in
3234 the program text; thus, it is a static property.
6365 off
6466 on
6567
66 and two-hundred and fifty-six byte constants,
68 two hundred and fifty-six byte constants,
6769
6870 0
6971 1
7072 ...
7173 255
7274
75 and sixty-five thousand five hundred and thirty-six word constants,
76
77 0
78 1
79 ...
80 65535
81
82 Note that all byte constants serve double duty as word constants in that
83 context.
84
7385 ### User-defined ###
7486
7587 There may be any number of user-defined memory locations. They are defined
76 by giving the type, which must be `byte`, `byte table`, or `vector`, and the
88 by giving the type (which may be any type except `bit` and `routine`) and the
7789 name.
7890
7991 byte pos
8799
88100 byte pos : 0
89101
90 A user-defined vector memory location is decorated with READS and WRITES lists
91 like a routine (see below), and it may only hold addresses of routines which
92 are compatible. (Meaning, the routine's inputs (resp. outputs, trashes)
93 must be a subset of the vector's inputs (resp. outputs, trashes.))
102 A user-defined vector memory location is decorated with `inputs`, `outputs`
103 and `trashes` lists like a routine (see below), and it may only hold addresses
104 of routines which are compatible. (Meaning, the routine's inputs (resp. outputs,
105 trashes) must be a subset of the vector's inputs (resp. outputs, trashes.))
94106
95107 vector actor_logic
96108 inputs a, score
101113 Routines
102114 --------
103115
104 Every routine must list all the memory locations it READS from, i.e. its
105 INPUTS, and all the memory locations it WRITES to, whether they are OUTPUTS
106 or merely TRASHED. Every memory location that is not written to by the
107 routine (or any routines that the routine calls) is PRESERVED by the routine.
116 Every routine must list all the memory locations it *reads from*, which we
117 call its `inputs`, and all the memory locations it *writes to*. The latter
118 we divide into two groups: its `outputs` which it intentionally initializes,
119 and its `trashes`, which it does not care about, and leaves uninitialized.
120 For example, if it uses a register to temporarily store an intermediate
121 value used in a multiplication, that register has no meaning outside of
122 the multiplication, and is one of the routine's `trashes`.
123
124 It is common to say that the `trashes` are the memory locations that are
125 *not preserved* by the routine.
108126
109127 routine foo
110128 inputs a, score
113131 ...
114132 }
115133
134 The `inputs` are sometimes called the routine's READS set, while the
135 `outputs` and `trashes` are collectively called the WRITES set.
136
116137 Routines may call only routines previously defined in the program source.
117138 Thus, directly recursive routines are not allowed. (However, routines may
118139 also call routines via vectors, which are dynamically assigned. In this
121142 For a SixtyPical program to be run, there must be one routine called `main`.
122143 This routine is executed when the program is run.
123144
124 The memory locations given given as inputs are considered to be initialized
145 The memory locations given as inputs to a routine are considered to be initialized
125146 at the beginning of the routine. Various instructions cause memory locations
126147 to be initialized after they are executed. Calling a routine which trashes
127148 some memory locations causes those memory locations to be uninitialized after
128149 that routine is called. At the end of a routine, all memory locations listed
129 as outputs must be initialised.
150 as outputs must be initialized.
130151
131152 A routine can also be declared as "external", in which case its body need
132153 not be defined but an absolute address must be given for where the routine
140161 Instructions
141162 ------------
142163
164 Instructions are inspired by, and in many cases closely resemble, the 6502
165 instruction set. However, in many cases they do not map 1:1 to 6502 instructions.
166 If a SixtyPical instruction cannot be translated validly to one more more 6502
167 instructions while retaining all the stated constraints, that's a static error
168 in a SixtyPical program, and technically any implementation of SixtyPical, even
169 an interpreter, should flag it up.
170
143171 ### ld ###
144172
145173 ld <dest-memory-location>, <src-memory-location> [+ <index-memory-location>]
147175 Reads from src and writes to dest.
148176
149177 * It is illegal if dest is not a register.
150 * It is illegal if dest does not occur in the WRITES lists of the current
151 routine.
178 * It is illegal if dest does not occur in the WRITES of the current routine.
152179 * It is illegal if src is not of same type as dest (i.e., is not a byte.)
153180 * It is illegal if src is uninitialized.
154181
155182 After execution, dest is considered initialized. The flags `z` and `n` may be
156 changed by this instruction; they must be named in the WRITES lists, and they
183 changed by this instruction; they must be named in the WRITES, and they
157184 are considered initialized after it has executed.
158185
159186 If and only if src is a byte table, the index-memory-location must be given.
168195 Reads from src and writes to dest.
169196
170197 * It is illegal if dest is a register or if dest is read-only.
171 * It is illegal if dest does not occur in the WRITES lists of the current
172 routine.
198 * It is illegal if dest does not occur in the WRITES of the current routine.
173199 * It is illegal if src is not of same type as dest.
174200 * It is illegal if src is uninitialized.
175201
186212
187213 * It is illegal if src OR dest OR c is uninitialized.
188214 * It is illegal if dest is read-only.
189 * It is illegal if dest does not occur in the WRITES lists
190 of the current routine.
191
192 Affects n, z, c, and v flags, requiring that they be in the WRITES lists,
215 * It is illegal if dest does not occur in the WRITES of the current routine.
216
217 Affects n, z, c, and v flags, requiring that they be in the WRITES,
193218 and initializing them afterwards.
194219
195220 dest and src continue to be initialized afterwards.
202227
203228 * It is illegal if dest is uninitialized.
204229 * It is illegal if dest is read-only.
205 * It is illegal if dest does not occur in the WRITES lists
206 of the current routine.
207
208 Affects n and z flags, requiring that they be in the WRITES lists,
230 * It is illegal if dest does not occur in the WRITES of the current routine.
231
232 Affects n and z flags, requiring that they be in the WRITES,
209233 and initializing them afterwards.
210234
211235 ### sub ###
216240
217241 * It is illegal if src OR dest OR c is uninitialized.
218242 * It is illegal if dest is read-only.
219 * It is illegal if dest does not occur in the WRITES lists
220 of the current routine.
221
222 Affects n, z, c, and v flags, requiring that they be in the WRITES lists,
243 * It is illegal if dest does not occur in the WRITES of the current routine.
244
245 Affects n, z, c, and v flags, requiring that they be in the WRITES,
223246 and initializing them afterwards.
224247
225248 dest and src continue to be initialized afterwards.
232255
233256 * It is illegal if dest is uninitialized.
234257 * It is illegal if dest is read-only.
235 * It is illegal if dest does not occur in the WRITES lists
236 of the current routine.
237
238 Affects n and z flags, requiring that they be in the WRITES lists,
258 * It is illegal if dest does not occur in the WRITES of the current routine.
259
260 Affects n and z flags, requiring that they be in the WRITES,
239261 and initializing them afterwards.
240262
241263 ### cmp ###
247269
248270 * It is illegal if src OR dest is uninitialized.
249271
250 Affects n, z, and c flags, requiring that they be in the WRITES lists,
272 Affects n, z, and c flags, requiring that they be in the WRITES,
251273 and initializing them afterwards.
252274
253275 ### and, or, xor ###
261283
262284 * It is illegal if src OR dest OR is uninitialized.
263285 * It is illegal if dest is read-only.
264 * It is illegal if dest does not occur in the WRITES lists
265 of the current routine.
266
267 Affects n and z flags, requiring that they be in the WRITES lists of the
286 * It is illegal if dest does not occur in the WRITES of the current routine.
287
288 Affects n and z flags, requiring that they be in the WRITES of the
268289 current routine, and sets them as initialized afterwards.
269290
270291 dest and src continue to be initialized afterwards.
283304 * It is illegal if dest is a register besides `a`.
284305 * It is illegal if dest is read-only.
285306 * It is illegal if dest OR c is uninitialized.
286 * It is illegal if dest does not occur in the WRITES lists
287 of the current routine.
288
289 Affects the c flag, requiring that it be in the WRITES lists of the
307 * It is illegal if dest does not occur in the WRITES of the current routine.
308
309 Affects the c flag, requiring that it be in the WRITES of the
290310 current routine, and it continues to be initialized afterwards.
291311
292312 ### call ###
298318 which will be called indirectly. Execution will be transferred back to the
299319 current routine, when execution of the executable is finished.
300320
301 Just before the call,
302
303 * It is illegal if any of the memory locations in the target executable's
304 READS list is uninitialized.
321 * It is illegal if any of the memory locations listed in the called routine's
322 `inputs` are uninitialized immediately before the call.
305323
306324 Just after the call,
307325
308 * All memory locations listed as TRASHED in the called routine's WRITES
309 list are considered uninitialized.
310 * All memory locations listed as TRASHED in the called routine's OUTPUTS
311 list are considered initialized.
326 * All memory locations listed in the called routine's `trashes` are considered
327 to now be uninitialized.
328 * All memory locations listed in the called routine's `outputs` are considered
329 to not be initialized.
312330
313331 ### goto ###
314332
329347
330348 In addition,
331349
332 * The target executable's WRITES lists must not include any locations
333 that are not already included in the current routine's WRITES lists.
350 * The target executable's WRITES must not include any locations
351 that are not already included in the current routine's WRITES.
334352
335353 ### if ###
336354
382400 `z` and `n` flags and the `a` register.
383401
384402 * It is illegal if dest is read-only.
385 * It is illegal if dest does not occur in the WRITES lists of the current
386 routine.
403 * It is illegal if dest does not occur in the WRITES of the current routine.
387404 * It is illegal if src is not of same type as dest.
388405 * It is illegal if src is uninitialized.
389406