boot2

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

commit dba93b40eccda3f858875e16a36e137da772645e
parent 41d03e718e0db05e028e577171ed067100b44bbc
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sun, 26 Apr 2026 22:49:33 -0700

cc/parse: local array initializer (§E.7)

Local `int a[3] = {10, 20, 30};` now lays each element down via cg
stores into the frame slot at slot+(i*sizeof(elem)). Fixes the
base-off bug where parse-init-local-aggregate was passing 0 instead
of the sym's frame slot — writes were landing in the ret-slot region
instead of the array.

Reading back via `(int*)&a` exercises the cg-take-addr → cast → ptr
arith path the §E.6 cg-arith-conv tweak just unblocked.

Diffstat:
Mcc/parse.scm | 4++--
Atests/cc-parse/55-init-local-array.c | 11+++++++++++
Atests/cc-parse/55-init-local-array.expected-exit | 1+
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/cc/parse.scm b/cc/parse.scm @@ -706,9 +706,9 @@ (advance ps) (cond ((eq? (ctype-kind ty) 'arr) - (%parse-init-local-array-list ps sm 0 ty)) + (%parse-init-local-array-list ps sm (sym-slot sm) ty)) ((or (eq? (ctype-kind ty) 'struct) (eq? (ctype-kind ty) 'union)) - (%parse-init-local-struct-list ps sm 0 ty)) + (%parse-init-local-struct-list ps sm (sym-slot sm) ty)) (else (die #f "init local: brace on scalar?")))) (else (die (tok-loc (peek ps)) "init local aggregate?")))) diff --git a/tests/cc-parse/55-init-local-array.c b/tests/cc-parse/55-init-local-array.c @@ -0,0 +1,11 @@ +// tests/cc-parse/55-init-local-array.c — local array initializer. §E.7. +// +// Stack-allocated int[3] initialised inside main via a brace list; we +// read element 1 through a manually-decayed pointer. Whatever the +// parser does to lay down the initializer must hit the right offsets +// — here the test asserts that writes to a[0] don't bleed into a[1]. +int main(void) { + int a[3] = {10, 20, 30}; + int *p = (int *)&a; + return *(p + 1); +} diff --git a/tests/cc-parse/55-init-local-array.expected-exit b/tests/cc-parse/55-init-local-array.expected-exit @@ -0,0 +1 @@ +20