boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit 5e19b52523881a930b8d0464a769727677be950e
parent 53f1be65ea19367289b852dc6d3f1676d8f3ad35
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sun, 26 Apr 2026 22:42:02 -0700

cc/parse: array element access at non-zero index fixture (§D.5)

The lbrack arm in parse-postfix-rest was already correct shape —
rval! the array, parse the index expression, rval! it, cg-binop add,
cg-push-deref. The §D.1 cg-load array-decay change is what makes
rval! work on arr-typed lvals. The fixture exists so a regression
in either piece shows up here.

Diffstat:
Mdocs/CC-PUNCHLIST.md | 16+++++++++-------
Atests/cc-parse/40-array-index.c | 12++++++++++++
Atests/cc-parse/40-array-index.expected-exit | 1+
3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/docs/CC-PUNCHLIST.md b/docs/CC-PUNCHLIST.md @@ -176,13 +176,15 @@ broken. Pick one fix and document it in The fixture exercises both s.inner.x (direct frame) and p->inner.x (indirect frame, via the §D.1 indirect path). -- [ ] **Array element access at non-zero index** - - cg: `cc-cg/NN-array-index.scm` — `int a[3]; a[0]=1; a[1]=2; a[2]=4; - return a[0]+a[1]+a[2];` → exit 7. - - parse: `cc-parse/NN-array-index.c` - - Needs: array lval decays to ptr-rval (in `cg-push-sym` or via a - new `cg-decay-array`); verify scaling for `arr` types in - `cg-binop add`. +- [x] **Array element access at non-zero index** + - cg: `cc-cg/40-array-index.scm` + - parse: `cc-parse/40-array-index.c` + - Done: cg-load on an arr-typed lval delegates to cg-decay-array, + pushing a ptr-rval to the first element. Existing `cg-binop add` + pointer-arithmetic path scales by the pointee size, so `a + i` + yields `&a[i]`, and cg-push-deref turns that into the element + lval. cg-take-addr on an arr lval was also adjusted to yield + T* (not (T[N])*) so `&a[0]` stays consistent. - [ ] **Multi-dim arrays** - parse: `cc-parse/NN-array-2d.c` diff --git a/tests/cc-parse/40-array-index.c b/tests/cc-parse/40-array-index.c @@ -0,0 +1,12 @@ +// tests/cc-parse/40-array-index.c — array element access at non-zero +// index via real C (§D.5 of docs/CC-PUNCHLIST.md). a[0]+a[1]+a[2] +// = 7. Distinct values 1,2,4 ensure each index is read independently +// (sum 7 forms a unique bit-pattern in 3 bits). + +int main() { + int a[3]; + a[0] = 1; + a[1] = 2; + a[2] = 4; + return a[0] + a[1] + a[2]; +} diff --git a/tests/cc-parse/40-array-index.expected-exit b/tests/cc-parse/40-array-index.expected-exit @@ -0,0 +1 @@ +7