4
(defvar *immediate-types*
5
'(fixnum character short-float double-float boolean))
10
bignum function random-state
11
hash-table ratio single-float
12
rational standard-char
13
keyword readtable stream
16
complex nil signed-byte symbol
17
cons null unsigned-byte t
18
number simple-array vector
22
(double-float long-float single-float)
23
(character string-char)
24
((vector character) string simple-string)
25
((vector bit) bit-vector simple-bit-vector)
26
((vector t) simple-vector)
28
(dynamic-extent dynamic-extent )
29
(fix-or-sf-or-df fix-or-sf-or-df)
32
(setf (get w 'comp-type) (car v))))
33
(dolist (v *immediate-types*) (setf (get v 'comp-type) v))
35
(deftype fix-or-sf-or-df nil '(or fixnum short-float double-float))
36
(deftype boolean nil t)
37
(proclaim '(declaration dynamic-extent))
38
;(deftype dynamic-extent nil t)
40
(defun grab-1-decl (x decls &aux type l tem place)
44
(comp-warn "bad declaration ~a" x)
45
(return-from grab-1-decl decls)
47
(or (consp x) (go error))
48
(setq type (car x) l (cdr x))
49
(or (null l) (consp l) (go error))
52
(comp-warn "bad declaration ~a" x)
53
(return-from grab-1-decl decls)
55
(cond ((or (setq tem (get type 'comp-type))
58
(setq tem (comp-type (car l)))
60
(unless (eq t (setq tem (comp-type tem)))
61
(or decls (setq decls (list nil)))
63
(or (symbolp v) (go error))
64
(push (cons v tem) (car decls)))))
66
(cond ((null decls) (setq decls (list nil nil)))
68
(setf (cdr decls) (list nil))))
69
(setq place (cdr decls))
71
(or (symbolp v) (go error))
74
((or (eq type 'inline)
77
(progn (desetq (type . l) l) t)))
78
(dolist-safe (v l) (push
79
(cons v (increment-function-decl
80
type (function-declaration v)))
83
; (((v1 . type1) (v2 . type2) ..)(special-var1 special-var2 ..))
86
(defun best-array-element-type (type)
87
(cond ((or (eql t type) (null type)) t)
88
((memq type '(bit unsigned-char signed-char
94
((subtypep type 'fixnum)
95
(dolist (v '(bit unsigned-char signed-char
99
(cond ((subtypep type v)
101
((eql type 'string-char) 'character)
102
(t (or (dolist (v '(string-char bit short-float
104
(cond ((subtypep type v)
110
(let ((tem (b1-walk x 'type-of)))
114
(defun assure-list (x)
116
(if (null x) (return t))
117
(if (consp x) (setq x (cdr x))
118
(error "expected a list ~a" x))))
120
(deftype struct (x) 'structure)
121
(defun comp-type (type &aux tem element-type sizes)
122
;; coerce type to ones understood by compiler
123
(cond ;((member type *immediate-types*)
124
;(return-from comp-type type))
126
(setq tem (get type 'comp-type)))
127
(return-from comp-type tem))
129
(setq tem (get type 'si::deftype-definition)))
130
(comp-type (funcall tem)))
133
((eq (car type) 'struct)
134
(list 'struct (best-array-element-type (cadr type))))
135
((progn (setq type (si::normalize-type type)) nil))
136
((member (car type) '(array simple-array vector simple-vector))
137
(when (consp (cdr type))
138
(setq element-type (best-array-element-type (cadr type)))
139
(when(consp (cddr type))
140
(setq sizes (caddr type))
143
(unless (typep (second sizes) 'fixnum) (setq sizes nil)))
144
((typep sizes 'fixnum) )
145
(t (setq sizes nil))))
146
(cond ((or (eql sizes 1) (null (cdr sizes)))
147
(setq tem 'vector) (setq sizes nil))
148
(t (setq tem 'array)))
149
(list* tem element-type (if sizes (list sizes)))))
150
((eq (car type) 'integer)
151
(if (si::sub-interval-p (cdr type)
152
(list most-negative-fixnum
153
most-positive-fixnum))
156
((eq (car type) 'values)
157
(if (null (cddr type))
158
(comp-type (second type))
159
(cons 'values (mapcar 'comp-type (cdr (the-list type))))))
163
(setf (get 'var 'result-type-b1) 'result-type-b1-var)
164
(defun result-type-b1-var (x) (or (third x) t))
166
(defun result-type (form &aux fd)
167
;; compute the result type of form , where FORM is somethign
168
;; returned by b1-walk
170
(cond ((and (symbolp (car form))
171
(setq fd (get (car form) 'result-type-b1)))
173
((and (atom (second form))
174
(typep (second form) 'desk))
175
(desk-result-type (second form)))
183
(setf (get 'dv 'result-type-b1) 'dv-result-type)
184
(defun dv-result-type (x)
185
(let ((val (third x)))
186
(cond ((typep val 'fixnum) 'fixnum)
187
((typep val 'short-float) 'short-float)
188
((typep val 'double-float) 'double-float)
189
((typep val 'character) 'character)
190
((typep val 'character) 'character)
193
(defun comp-subtypep (x y &aux xa xb)
194
; (cond ((and (atom x) (not (eq y t)) (not (eq x y))
195
; (subtypep x y))(comp-warn "subtypep ~a ~a" x y)))
201
((member (car x) '(array struct))
202
(and (eq (car y) (car y)) (subtypep (cdr x) (cdr y))))
205
(defun type-and (a b)
206
(if (eq a b) (return-from type-and a))
207
(if (eq a t) (return-from type-and b))
208
(if (eq b t) (return-from type-and a))
209
(multiple-value-bind (typ sure)
212
(cond (typ (return-from type-and a))))
213
(multiple-value-bind (typ sure)
216
(cond (typ (return-from type-and b))))