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:
@@ -7,7 +7,7 @@
|
||||
(chicken module)
|
||||
(chicken string)
|
||||
(chicken syntax)
|
||||
brev-separate ; fn, flatten
|
||||
brev-separate ; fn
|
||||
fmt
|
||||
sex-fmt-c
|
||||
matchable
|
||||
@@ -447,6 +447,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)))))
|
||||
|
||||
@@ -476,11 +477,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
|
||||
|
||||
Reference in New Issue
Block a user