boot2

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

commit 4f1c5eb58ba3c7376a83262f152db851e73801d4
parent ff130e4a25e02fe7231bf399779b0bcf38d2903b
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sun, 26 Apr 2026 22:47:48 -0700

cc/parse: struct passed by pointer to function (§D.7)

Smoke-tests §D primitives end-to-end: caller takes &s, callee
dereferences via p->x / p->y. No cg or parser changes — composes
cg-push-field + arrow + the pre-existing param/call/return wiring.

Diffstat:
Mdocs/CC-PUNCHLIST.md | 8+++++---
Atests/cc-parse/42-struct-fn-arg.c | 18++++++++++++++++++
Atests/cc-parse/42-struct-fn-arg.expected-exit | 1+
3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/docs/CC-PUNCHLIST.md b/docs/CC-PUNCHLIST.md @@ -194,9 +194,11 @@ broken. Pick one fix and document it in fn-suffix arm so `T (...)(...)` chains compose correctly. Decay + ptr arithmetic from §D.5 then handles the rest. -- [ ] **Struct passed by pointer to a function** - - parse: `cc-parse/NN-struct-fn-arg.c` — passes `&s`. - - Needs: nothing new; smoke-tests §D primitives. +- [x] **Struct passed by pointer to a function** + - parse: `cc-parse/42-struct-fn-arg.c` — passes `&s` to `sum2`, + callee returns `p->x + p->y`. + - Done: composes §D.1/§D.3 (cg-push-field, arrow access) and the + pre-existing param/call/return wiring. No new primitive. *Pass-by-value of structs is outside CC.md's accepted set; tcc.c doesn't use it.* diff --git a/tests/cc-parse/42-struct-fn-arg.c b/tests/cc-parse/42-struct-fn-arg.c @@ -0,0 +1,18 @@ +// tests/cc-parse/42-struct-fn-arg.c — struct passed by pointer to a +// function (§D.7 of docs/CC-PUNCHLIST.md). Smoke-tests §D primitives: +// caller takes &s, callee dereferences via -> on the pointer arg. +// +// sum2(&s) where s={3,5} returns 8. + +struct P { int x; int y; }; + +int sum2(struct P *p) { + return p->x + p->y; +} + +int main() { + struct P s; + s.x = 3; + s.y = 5; + return sum2(&s); +} diff --git a/tests/cc-parse/42-struct-fn-arg.expected-exit b/tests/cc-parse/42-struct-fn-arg.expected-exit @@ -0,0 +1 @@ +8