forked from alex-eg/sex
read an array's length as types does
Inference took only an integer for a length, and read a name there as part of the element type: [_ N] did not solve, and an array of [int N] decayed to int N *.
This commit is contained in:
23
infer.scm
23
infer.scm
@@ -78,8 +78,9 @@
|
||||
(target ptr-target)
|
||||
(quals ptr-quals))
|
||||
|
||||
;;; `size' is an integer, or #f for `(¤ int)' -- an array of unwritten
|
||||
;;; length.
|
||||
;;; `size' is the length as written -- 4, N, (* 2 N) -- or #f for
|
||||
;;; `(¤ int)', an array of unwritten length. Two are one length when
|
||||
;;; they are written alike.
|
||||
(define-record-type <array>
|
||||
(make-array-type elt size)
|
||||
array-type?
|
||||
@@ -222,15 +223,15 @@
|
||||
(name (and (pair? (cdr words)) (symbol? (cadr words)) (cadr words))))
|
||||
(make-agg kind name words quals)))
|
||||
|
||||
;;; (¤ elt ... size) -- the size is the last element when it is an
|
||||
;;; integer, and absent otherwise. The element words are unwrapped the
|
||||
;;; way the C writer unwraps them, so `[int 16]' and `[(int) 16]' are
|
||||
;;; one type.
|
||||
;;; (¤ elt ... size) -- the size is the bound `types' finds there: an
|
||||
;;; integer, a name, an expression, or absent. The element words are
|
||||
;;; unwrapped the way the C writer unwraps them, so `[int 16]' and
|
||||
;;; `[(int) 16]' are one type.
|
||||
(define (parse-array surface)
|
||||
(let* ((rest (cdr (nest-array-type surface)))
|
||||
(sized? (and (pair? rest) (integer? (last rest))))
|
||||
(size (and sized? (last rest)))
|
||||
(words (if sized? (drop-right rest 1) rest)))
|
||||
(let* ((nested (nest-array-type surface))
|
||||
(sized? (array-bound? nested))
|
||||
(size (and sized? (array-bound nested)))
|
||||
(words (if sized? (drop-right (cdr nested) 1) (cdr nested))))
|
||||
(when (null? words)
|
||||
(sex-error surface "array type without an element type" surface))
|
||||
(make-array-type (parse-type (maybe-unwrap words)) size)))
|
||||
@@ -383,7 +384,7 @@
|
||||
;; One of them may be `(¤ int)': an unwritten length constrains
|
||||
;; nothing, the way it does not in C either.
|
||||
(when (and (array-size a) (array-size b)
|
||||
(not (= (array-size a) (array-size b))))
|
||||
(not (equal? (array-size a) (array-size b))))
|
||||
(type-mismatch a b form))
|
||||
(unify (array-elt a) (array-elt b) form))
|
||||
((and (fn-type? a) (fn-type? b))
|
||||
|
||||
Reference in New Issue
Block a user