type a value if as the join of its branches
It had no rule, so _ could not be set from one.
This commit is contained in:
12
semen.scm
12
semen.scm
@@ -1422,6 +1422,12 @@
|
||||
;; 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 value if is the join of its values, as an operator is of its
|
||||
;; operands -- and nothing when one of them says nothing
|
||||
((if) (let ((types (map (cut expression-type <> env)
|
||||
(if-values (remove comment-form? (cdr expr))))))
|
||||
(and (every identity types)
|
||||
(fold (lambda (t joined) (arith-join joined t)) #f types))))
|
||||
;; 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:
|
||||
@@ -1482,6 +1488,12 @@
|
||||
(let ((type (underlying (parse-type written))))
|
||||
(or (ptr-type? type) (array-type? type)))))
|
||||
|
||||
;;; (if t1 v1 t2 v2 e) -> (v1 v2 e)
|
||||
(define (if-values parts)
|
||||
(if (and (pair? parts) (pair? (cdr parts)) (pair? (cddr parts)))
|
||||
(cons (cadr parts) (if-values (cddr parts)))
|
||||
parts))
|
||||
|
||||
(define (arith-join left right)
|
||||
(cond
|
||||
((not left) right)
|
||||
|
||||
Reference in New Issue
Block a user