keep an aggregate written in place behind a pointer

A type was flattened word by word, a struct's body included, so
(* (struct ((c int)))) came out struct c{ int; } *.
This commit is contained in:
2026-10-17 17:35:48 +03:00
parent d9b9316eb0
commit 62ca848de8
2 changed files with 30 additions and 6 deletions

View File

@@ -7,7 +7,7 @@
(chicken module)
(chicken string)
(chicken syntax)
brev-separate ; fn, flatten
brev-separate ; fn
fmt
sex-fmt-c
matchable
@@ -456,6 +456,7 @@ forms, and what remains."
(define (has-pointer-star? form)
(and (pair? form)
(not (structured-type? form))
(not (inline-aggregate? form))
(or (memq '* form)
(any has-pointer-star? (filter pair? form)))))
@@ -485,11 +486,22 @@ forms, and what remains."
(sex-error type "a fn type is a function pointer already: write (fn ...), not (* (fn ...))" type)
(sex-error type "a pointer to an array is not supported" type))))
(if (atom? type) (atom-to-fmt-c type)
(flatten
(tree-map atom-to-fmt-c
(flatten
(list-join (reverse (list-split type '*))
'(*)))))))
(type-words (list-join (reverse (list-split type '*)) '(*)))))
;;; A type's words, flat, except that an aggregate written out in full is
;;; one of them, walked: (* (struct ((c int)))) is `struct {...} *'
(define (type-words items)
(append-map (lambda (item)
(cond ((inline-aggregate? item) (list (walk-type item)))
((pair? item) (type-words item))
((null? item) (list))
(else (list (atom-to-fmt-c item)))))
items))
;;; (struct ((c int))), (union u (...)), (enum (red green)): a body, not
;;; just a tag
(define (inline-aggregate? form)
(and (pair? form) (memq (car form) '(struct union enum)) (any list? (cdr form))))
(define (walk-fn-def form)
(match form