forked from alex-eg/sex
walk a define's body, and parenthesise it
The body was pasted as read, so `cast' stayed a call and names kept their dashes; and fmt-c parenthesised only a function-like body, so an object-like one regrouped with the operator it was pasted under. Fixes #55.
This commit is contained in:
@@ -433,6 +433,15 @@
|
||||
((pair? x) (cons (replace (car x)) (replace (cdr x))))
|
||||
(else x))))
|
||||
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: an object-like body is parenthesised
|
||||
;; as a function-like one is. Upstream left it bare, so with
|
||||
;; `#define D -1.0 / 6.0', `x * D' was `(x * -1.0) / 6.0'. Only a
|
||||
;; name or a literal that cannot lose its sign to a neighbour is
|
||||
;; left as written.
|
||||
(define (c-atomic-body? x)
|
||||
(or (symbol? x)
|
||||
(and (c-literal? x) (not (and (number? x) (negative? x))))))
|
||||
|
||||
(define (cpp-define x . body)
|
||||
(define (name-of x) (c-expr (if (pair? x) (cadr x) x)))
|
||||
(lambda (st)
|
||||
@@ -450,9 +459,8 @@
|
||||
(cat " "
|
||||
(fmt-let 'writer (make-cpp-writer st)
|
||||
(fmt-let 'macro-params params
|
||||
((if (or (not (pair? x))
|
||||
(and (null? (cdr body))
|
||||
(c-literal? (car body))))
|
||||
((if (and (null? (cdr body))
|
||||
(c-atomic-body? (car body)))
|
||||
(lambda (x) x)
|
||||
c-paren)
|
||||
(c-in-expr (apply c-begin body))))))
|
||||
|
||||
Reference in New Issue
Block a user