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:
18
semen.scm
18
semen.scm
@@ -1320,7 +1320,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)
|
||||
@@ -1378,10 +1378,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))
|
||||
@@ -2169,7 +2172,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.
|
||||
|
||||
Reference in New Issue
Block a user