type #t, an enum's constants and the bitwise names

None had a rule. A constant is typed as its enum, where C says int, so
that the enum's ops are found through it. And bit-and, bit-not and the
rest were respelled bit_and before fmt-c could see them, and called.
This commit is contained in:
2026-10-19 13:38:30 +03:00
parent 904c832384
commit 33e996f94d
3 changed files with 36 additions and 4 deletions

View File

@@ -1331,7 +1331,7 @@
((number? expr) 'double)
((string? expr) '(* const char))
((char? expr) 'char)
((memq expr '(true false)) 'bool)
((or (boolean? expr) (memq expr '(true false))) 'bool)
;; `#(T : ...)' carries its own type; a bare `#(...)' has none and
;; takes one from whatever it is being written into
((vector? expr)
@@ -1389,10 +1389,13 @@
(arithmetic-type expr env)))
((+ / %) (arithmetic-type expr env))
;; the bitwise operators join like the arithmetic ones
((^ |\||) (arithmetic-type expr env))
((^ |\|| bit-and bit-or bit-xor bitwise-and bitwise-ior bitwise-xor)
(arithmetic-type expr env))
;; a shift is the promoted left operand, not a join:
;; (<< l b), l : long -> long; (>> c b), c : char -> int
((<< >>) (promoted-type (expression-type (second expr) env)))
;; a complement is the operand promoted, as a negation is
((~ bit-not bitwise-not) (promoted-type (expression-type (second expr) env)))
;; ...and an increment is the operand unpromoted:
;; (++ c), c : char -> char
((++ --) (expression-type (second expr) env))
@@ -2180,7 +2183,16 @@
(case (car f)
((struct) (add-struct name form))
((union) (add-union name form))
((enum) (add-enum name form))))))
((enum)
(add-enum name form)
;; a constant is its enum's, which `_' reads and whose ops it
;; calls -- where C says int, and converts between them
(when (and (pair? (cddr f)) (list? (caddr f)))
(for-each (lambda (value)
(let ((constant (if (pair? value) (car value) value)))
(when (symbol? constant)
(add-name-type! constant `(enum ,name)))))
(remove comment-form? (caddr f)))))))))
;;; No function around a toplevel form, so no scope chain: what a
;;; global's initializer names comes from `get-name-type' alone.