git @ Cat's Eye Technologies SixtyPical / 8ccabdf
Work on the spec a bit. Chris Pressey 6 years ago
1 changed file(s) with 74 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
0 Sixtypical
0 SixtyPical
11 ==========
22
3 Sixtypical is a simplified version of [Sixtypical][].
4
5 This is a complete reboot of the previous design and implementation, which
6 was semantically a mess due to the way it was built.
7 This aims to be a simpler design which gets the static semantics right first,
8 and only then is extended to be more practical.
3 This document describes the SixtyPical programming language version 0.2,
4 both its execution aspect and its static analysis aspect (even though
5 these are, technically speaking, separate concepts.)
6
7 This document is nominally normative, but the tests in the `tests` directory
8 are even more normative.
99
1010 Types
1111 -----
1212
13 There are two TYPES in Sixtypical:
13 There are two TYPES in SixtyPical:
1414
1515 * bit (2 possible values)
1616 * byte (256 possible values)
1818 Memory locations
1919 ----------------
2020
21 The primary concept in Sixtypical is the MEMORY LOCATION. At any given point
21 A primary concept in SixtyPical is the MEMORY LOCATION. At any given point
2222 in time during execution, each memory location is either UNINITIALIZED or
2323 INITIALIZED. At any given point in the program text, too, each memory
2424 location is either uninitialized or initialized. Where-ever it is one or
2525 the other during execution, it is the same in the corresponding place in
2626 the program text; thus, it is a static property.
2727
28 (There is actually a third state, WRITTEN, which indicates that the memory
29 location is not only initialized, but also that it has been written to in
30 the current routine.)
31
3228 There are four general kinds of memory location. The first three are
3329 pre-defined and built-in.
3430
5248 ### Constants ###
5349
5450 It may be strange to think of constants as memory locations, but keep in mind
55 that a memory location in Sixtypical need not map to a memory location in the
56 underlying hardware. All constants are read-only. Each is
57 initially initialized with the value that corresponds with its name.
51 that a memory location in SixtyPical need not map to a memory location in the
52 underlying hardware. All constants are read-only. Each is initially
53 initialized with the value that corresponds with its name.
5854
5955 They come in bit and byte types. There are two bit constants,
6056
8076
8177 Every routine must list all the memory locations it READS from, i.e. its
8278 INPUTS, and all the memory locations it WRITES to, whether they are OUTPUTS
83 or merely TRASHED. Every memory location that is not written to is PRESERVED.
79 or merely TRASHED. Every memory location that is not written to by the
80 routine (or any routines that the routine calls) is PRESERVED by the routine.
8481
8582 routine foo
8683 inputs a, score
9289 Routines may call only routines previously defined in the program source.
9390 Thus, recursive routines are not allowed.
9491
95 There must be one routine called `main`. This routine is executed when
96 the program is run.
92 For a SixtyPical program to be run, there must be one routine called `main`.
93 This routine is executed when the program is run.
94
95 The memory locations given given as inputs are considered to be initialized
96 at the beginning of the routine. Various instructions cause memory locations
97 to be initialized after they are executed. Calling a routine which trashes
98 some memory locations causes those memory locations to be uninitialized after
99 that routine is called. At the end of a routine, all memory locations listed
100 as outputs must be initialised.
97101
98102 Instructions
99103 ------------
105109 Reads from src and writes to dest.
106110
107111 * It is illegal if dest is not a register.
108 * It is illegal if dest does not occur in the WRITES list of the current
112 * It is illegal if dest does not occur in the WRITES lists of the current
109113 routine.
110114 * It is illegal if src is not of same type as dest (i.e., is not a byte.)
111115 * It is illegal if src is uninitialized.
112 * It is illegal if src does not either:
113 * be a constant, or
114 * occur in the READS list of the current routine, or
115 * occur in the WRITES list of the current routine AND
116 that location has previously been written inside this routine.
117116
118117 After execution, dest is considered initialized. The flags `z` and `n` may be
119 changed by this instruction, and they are considered initialized after it has
120 executed.
118 changed by this instruction; they must be named in the WRITES lists, and they
119 are considered initialized after it has executed.
121120
122121 Some combinations, such as `ld x, y`, are illegal because they do not map to
123122 underlying opcodes.
142141 Reads from src and writes to dest.
143142
144143 * It is illegal if dest is a register or if dest is read-only.
145 * It is illegal if dest does not occur in the WRITES list of the current
144 * It is illegal if dest does not occur in the WRITES lists of the current
146145 routine.
147146 * It is illegal if src is not of same type as dest.
148147 * It is illegal if src is uninitialized.
149 * It is illegal if src does not either:
150 * be a constant, or
151 * occur in the READS list of the current routine, or
152 * occur in the WRITES list of the current routine AND
153 that location has previously been written inside this routine.
154148
155149 After execution, dest is considered initialized. No flags are
156150 changed by this instruction (unless of course dest is a flag.)
171165
172166 * It is illegal if src OR dest OR c is uninitialized.
173167 * It is illegal if dest is read-only.
174 * It is illegal if dest does not occur in the WRITES AND READS lists
168 * It is illegal if dest does not occur in the WRITES lists
175169 of the current routine.
176 * It is illegal if src does not either:
177 * be a constant, or
178 * occur in the READS list of the current routine, or
179 * occur in the WRITES list of the current routine AND
180 that location has previously been written inside this routine.
181
182 Affects n, z, c, and v flags.
183
184 dest continues to be initialized afterwards.
170
171 Affects n, z, c, and v flags, requiring that they be in the WRITES lists,
172 and initializing them afterwards.
173
174 dest and src continue to be initialized afterwards.
185175
186176 Notes:
187177
190180
191181 ### inc ###
192182
193 TODO: these do not honour carry!
183 inc <dest-memory-location>
184
185 Increments the value in dest. Does not honour carry.
186
187 * It is illegal if dest is uninitialized.
188 * 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 and z flags, requiring that they be in the WRITES lists,
193 and initializing them afterwards.
194
195 Notes:
194196
195197 inc x → INX
196198 inc y → INY
202204
203205 Subtracts the contents of src from dest and stores the result in dest.
204206
205 The constraints and effects are exactly the same as for `add`.
207 * It is illegal if src OR dest OR c is uninitialized.
208 * It is illegal if dest is read-only.
209 * It is illegal if dest does not occur in the WRITES lists
210 of the current routine.
211
212 Affects n, z, c, and v flags, requiring that they be in the WRITES lists,
213 and initializing them afterwards.
214
215 dest and src continue to be initialized afterwards.
206216
207217 Notes:
208218
211221
212222 ### dec ###
213223
214 TODO: these do not honour carry!
224 inc <dest-memory-location>
225
226 Decrements the value in dest. Does not honour carry.
227
228 * It is illegal if dest is uninitialized.
229 * It is illegal if dest is read-only.
230 * It is illegal if dest does not occur in the WRITES lists
231 of the current routine.
232
233 Affects n and z flags, requiring that they be in the WRITES lists,
234 and initializing them afterwards.
235
236 Notes:
215237
216238 dec x → DEX
217239 dec y → DEY
223245
224246 Subtracts the contents of src from dest, but does not store the result.
225247
226 The constraints and effects are the same as for `sub`, except that `c`
227 need not be initialized before executing `cmp`, and the `v` flag is
228 unaffected.
248 * It is illegal if src OR dest is uninitialized.
249
250 Affects n, z, and c flags, requiring that they be in the WRITES lists,
251 and initializing them afterwards.
229252
230253 Notes:
231254
233256 cmp a, 1 → CMP #1
234257 cmp x, 1 → CPX #1
235258 cmp y, 1 → CPY #1
259
260 - - - -
236261
237262 ### and ###
238263