git @ Cat's Eye Technologies SixtyPical / ed91756
We have a `for` loop now. Chris Pressey 3 years ago
2 changed file(s) with 3 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
33 0.14
44 ----
55
6 * Added the so-called "open-faced `for` loop", which spans a loop
7 variable over a range, the end of which is fixed.
68 * `--origin` and `--output-format` options added to reference compiler.
79 * "Tail position" is now more correctly determined for the purposes of
810 insisting that `goto` only appears in it.
6666 TODO
6767 ----
6868
69 ### `for`-like loop
70
71 We have range-checking in the abstract analysis now, but we lack practical ways
72 to use it.
73
74 We can `and` a value to ensure it is within a certain range. However, in the 6502
75 ISA the only register you can `and` is `A`, while loops are done with `X` or `Y`.
76 Insisting this as the way to do it would result in a lot of `TXA`s and `TAX`s.
77
78 What would be better is a dedicated `for` loop, like
79
80 for x in 0 to 15 {
81 // in here, we know the range of x is exactly 0-15 inclusive
82 // also in here: we are disallowed from changing x
83 }
84
85 However, this is slightly restrictive, and hides a lot.
86
87 However however, options which do not hide a lot, require a lot of looking at
88 (to ensure: did you increment the loop variable? only once? etc.)
89
90 The leading compromise so far is an "open-faced for loop", like
91
92 ld x, 15
93 for x downto 0 {
94 // same as above
95 }
96
97 This makes it a little more explicit, at least, even though the loop
98 decrementation is still hidden.
99
10069 ### Save registers on stack
10170
10271 This preserves them, so that, semantically, they can be used later even though they
12291 * Automatic tail-call optimization (could be tricky, w/constraints?)
12392 * Possibly `ld x, [ptr] + y`, possibly `st x, [ptr] + y`.
12493 * Maybe even `copy [ptra] + y, [ptrb] + y`, which can be compiled to indirect LDA then indirect STA!
94 * Optimize `ld a, z` and `st a, z` to zero-page operations if address of z < 256.
12595
12696 [VICE]: http://vice-emu.sourceforge.net/