write an empty block as {}

(do), and a for with no body, gave c-begin nothing to begin with, and
the writer died on its arity.
This commit is contained in:
2026-10-17 17:35:48 +03:00
parent d6ad58f9c0
commit 0313b04a70
2 changed files with 28 additions and 13 deletions

View File

@@ -619,11 +619,15 @@
(define (c-braced-block . args)
(apply c-braced-block/aux 0 args))
;; MODIFIED FROM UPSTREAM fmt-c: a block of nothing is `{}', where
;; c-begin had nothing to begin with and died on its arity.
(define (c-braced-block/aux offset header . body)
(lambda (st)
((cat (if header header "") (c-open-brace st) (c-indent st offset)
(apply c-begin body) fl
(c-current-indent-string st offset) (c-close-brace st))
((if (null? body)
(cat (if header (cat header " ") "") "{}")
(cat (if header header "") (c-open-brace st) (c-indent st offset)
(apply c-begin body) fl
(c-current-indent-string st offset) (c-close-brace st)))
st)))
(define (c-begin . args)
@@ -729,17 +733,18 @@
fl))))
;; MODIFIED FROM UPSTREAM fmt-c: a header's first and last slots are
;; the one place a comma expression goes bare, so they say so.
;; the one place a comma expression goes bare, so they say so. And a
;; loop with no body has the empty block.
(define (c-for init check update . body)
(c-reset-newline
(cat
(c-block
(c-in-expr
(cat "for (" (c-with-op 'comma (c-expr init)) "; "
(c-in-test (c-expr check)) "; "
(c-with-op 'comma (c-expr update)) ")"))
(c-in-stmt (apply c-begin body)))
fl)))
(let ((header (c-in-expr
(cat "for (" (c-with-op 'comma (c-expr init)) "; "
(c-in-test (c-expr check)) "; "
(c-with-op 'comma (c-expr update)) ")"))))
(c-reset-newline
(cat (if (null? body)
(c-braced-block header)
(c-block header (c-in-stmt (apply c-begin body))))
fl))))
(define (c-param x)
(cond