forked from alex-eg/sex
type a pointer difference as ptrdiff-t
The join took the first pointer, so (- p q) declared the distance between two pointers as a third.
This commit is contained in:
14
semen.scm
14
semen.scm
@@ -1308,7 +1308,13 @@
|
||||
`(closure ,(arglist-types (second expr)) ,(third expr))))
|
||||
;; `c-and' and `c-or' are the names from before `&&' and `||'
|
||||
((== != < > <= >= && |\|\|| ! c-and c-or) 'bool)
|
||||
((+ - / %) (arithmetic-type expr env))
|
||||
;; one pointer from another is how far apart they are
|
||||
((-) (if (and (= 3 (length expr))
|
||||
(every (lambda (operand) (address? (expression-type operand env)))
|
||||
(cdr expr)))
|
||||
'ptrdiff-t
|
||||
(arithmetic-type expr env)))
|
||||
((+ / %) (arithmetic-type expr env))
|
||||
;; the bitwise operators join like the arithmetic ones
|
||||
((^ |\||) (arithmetic-type expr env))
|
||||
;; a shift is the promoted left operand, not a join:
|
||||
@@ -1351,6 +1357,12 @@
|
||||
#f
|
||||
(cdr expr)))
|
||||
|
||||
;;; A pointer, or an array that is one as an operand
|
||||
(define (address? written)
|
||||
(and written
|
||||
(let ((type (underlying (parse-type written))))
|
||||
(or (ptr-type? type) (array-type? type)))))
|
||||
|
||||
(define (arith-join left right)
|
||||
(cond
|
||||
((not left) right)
|
||||
|
||||
Reference in New Issue
Block a user