1
0
forked from alex-eg/sex

dispatch . on the type it reads from

Which of C's two member operators applies is a question the compiler
can already answer -- (.length v) and (.length p) have picked & or *
off the receiver's type since methods moved into the head -- so making
the programmer answer it again asks them to restate what semen knows,
and to revisit every reader of a field the day it becomes a pointer.

A path resolves a step at a time, since only the type in hand answers
for the next field. A receiver nothing can type is read as a value and
warned about rather than refused: refusing leaves no spelling at all
for a struct out of a header nobody has parsed.

Two things had to come along. A parameter written (p * struct point)
was recorded with nothing but the `*' for a type, which left half the
paths in list-macros unanswerable. And fmt-c parenthesised a member
access written inside another, which went unnoticed while only match
nested them -- its bindings have been reading ((s.u).circle).r since
sums went in.
This commit is contained in:
2026-10-05 02:08:15 +03:00
parent 95f39e4b44
commit fb4b8aa1f9
4 changed files with 125 additions and 15 deletions

View File

@@ -110,10 +110,19 @@
(define (c-paren x) (cat "(" (c-expr x) ")"))
;; `.' and `->' associate left, and their right operand is always a
;; name, so a member access written inside another is the left one
;; and needs no parens of its own: `s.u.circle.r', not `((s.u).circle).r'
(define (c-member-op? x)
(let ((str (display-to-string x)))
(or (string=? str ".") (string=? str "->"))))
(define (c-maybe-paren op x)
(lambda (st)
((fmt-let 'op op
(if (and (c-op<= (fmt-op st) op)
(not (and (c-member-op? (fmt-op st))
(c-member-op? op)))
(not (vector? x)))
(c-paren x)
x))