1
0
forked from alex-eg/sex

fix (. (* p) x) expanding to *(p).x

Was an fmt-c-writer bug: unary-op must parenthize itself, and not it's
arg
This commit is contained in:
2026-09-29 21:37:18 +03:00
parent 8a3f51e833
commit d3f05cecae
2 changed files with 37 additions and 2 deletions

View File

@@ -1015,9 +1015,24 @@
(cat nl (make-space (+ 2 (fmt-col st))) str " "))
st))))))))))
;; `-' arrives as the symbol binary minus uses, and so with binary
;; precedence: `(+ (- b) b)' asked under that spelling comes out
;; `(-b) + b'.
(define (unary-operator op)
(case op
((-) 'unary-)
((+) 'unary+)
((*) 'unary-*)
((&) 'unary-&)
(else op)))
;; Parenthesises the whole expression rather than the operand: the
;; other way round, `(. (* p) x)' came out `*(p).x', which C reads as
;; `*(p.x)'.
(define (c-unary-op op x)
(c-wrap-stmt
(cat (display-to-string op) (c-maybe-paren op (c-expr x)))))
(c-maybe-paren (unary-operator op)
(cat (display-to-string op) (c-expr x)))))
;; some convenience definitions