designate an initializer's element by its index

[3] in braces reached the writer as a subscript of one operand, and
sexc died taking the second.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent 2345f7854e
commit edddb98178
4 changed files with 26 additions and 3 deletions

View File

@@ -387,7 +387,7 @@ forms, and what remains."
(let loop ((es elements) (acc (list)))
(match es
(() (reverse acc))
(((? designator? d))
(((or (? designator? d) (and ('¤ _) d)))
(sex-error elements "designated initializer without a value" d))
(((? designator? d) value . rest)
(loop rest
@@ -395,6 +395,12 @@ forms, and what remains."
(atom-to-fmt-c (designator-field d))
(walk-expr value))
acc)))
;; [3] 1: an element named by its index. A subscript has two
;; operands, so one alone can be nothing else
((('¤ index) value . rest)
(loop rest
(cons (list '%designate-index (walk-expr index) (walk-expr value))
acc)))
((e . rest) (loop rest (cons (walk-expr e) acc))))))
(define (designator? x)