From ba26e4e8286159637f70fb5a3893734470c97dc3 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Fri, 16 Oct 2026 15:25:29 +0300 Subject: [PATCH] write every star of a pointer chain to a struct c-struct/aux wrote the tag and the first * after it and dropped the rest, so (* * struct pt) declared a struct pt *. --- sex-fmt-c.scm | 5 ++++- tests/codegen.scm | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sex-fmt-c.scm b/sex-fmt-c.scm index 912585b..8f22397 100644 --- a/sex-fmt-c.scm +++ b/sex-fmt-c.scm @@ -649,6 +649,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; data structures + ;; MODIFIED FROM UPSTREAM fmt-c: behind a pointer, the rest of the + ;; chain is O -- `struct p * * q' is body `*' and O (*) -- and it was + ;; dropped, so the declaration lost all but its first star. (define (c-struct/aux type x . o) ;; can be just pointer to SUC, need to support such case: ;; struct whatever * - body is just '*' @@ -673,7 +676,7 @@ (cat " " name) "") (if (not (null? body)) - (cat body) + (apply cat body (map (lambda (t) (cat " " t)) o)) "")))))) (define (c-struct . args) (apply c-struct/aux "struct" args)) diff --git a/tests/codegen.scm b/tests/codegen.scm index 4fa205c..b8e17f0 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -752,6 +752,14 @@ whitespace aside, THEN?" (test-assert "and negation beside a binary operator" (emits? (in-fn "(var n int (+ (- a) b))") "-a + b"))) + ;; c-struct/aux wrote the tag and the first `*' after it, and + ;; dropped the rest of the chain + (test-group "a pointer chain to a struct" + (test-assert "keeps every star" + (emits? (in-fn "(var q (* * struct p))") "struct p* * q;")) + (test-assert "and every qualifier between them" + (emits? (in-fn "(var q (* const * union u))") "union u* const * q;"))) + ;; An array bound was taken only when it was an integer literal, so a ;; symbolic one fell into the type: `[int N]' came out `int N a[]'. (test-group "array bounds"