Repository navigation
Expand file tree
/
Copy pathhost.lisp
More file actions
319 lines (296 loc) · 13.4 KB
/
Copy pathhost.lisp
File metadata and controls
319 lines (296 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
(in-package #:ctype)
;;;; These default specializations make ctype reflect the host type system.
(defmethod most-positive-fixnum (client)
(declare (ignore client))
cl:most-positive-fixnum)
(defmethod most-negative-fixnum (client)
(declare (ignore client))
cl:most-negative-fixnum)
;;; We close over the subtypeps but call eql within the zero methods,
;;; because I suspect that eql is more likely to be constant folded.
;;; Of course performance isn't going to be affected much either way.
(let ((reduction (if (cl:subtypep 'short-float 'single-float)
'single-float
'short-float)))
(defmethod reduce-float-type (client (type (eql 'short-float)))
(declare (ignore client))
reduction))
(defmethod reduce-float-type (client (type (eql 'single-float)))
(declare (ignore client))
'single-float)
(let ((reduction (if (cl:subtypep 'double-float 'single-float)
'single-float
'double-float)))
(defmethod reduce-float-type (client (type (eql 'double-float)))
reduction))
(let ((reduction (cond ((cl:subtypep 'long-float 'single-float) 'single-float)
((cl:subtypep 'long-float 'double-float) 'double-float)
(t 'long-float))))
(defmethod reduce-float-type (client (type (eql 'long-float)))
reduction))
(let ((distinct-float-types
(append (if (cl:subtypep 'short-float 'single-float) () '(short-float))
'(single-float)
(if (cl:subtypep 'double-float 'single-float) () '(double-float))
(if (cl:subtypep 'long-float 'double-float) () '(long-float)))))
(defmethod distinct-float-types (client)
(declare (ignore client))
distinct-float-types))
(macrolet ((defzeroes (type neg pos)
`(defmethod distinct-zeroes-p (client (type (eql ',type)))
(declare (ignore client))
(eql ,neg ,pos))))
(defzeroes short-float -0S0 0S0)
(defzeroes single-float -0F0 0F0)
(defzeroes double-float -0D0 0D0)
(defzeroes long-float -0L0 0L0))
(defmethod upgraded-complex-part-type (client specifier &optional env)
(declare (ignore client))
(cl:upgraded-complex-part-type specifier env))
(defmethod upgraded-array-element-type (client specifier &optional env)
(declare (ignore client))
(cl:upgraded-array-element-type specifier env))
(let ((complex-arrays-distinct-p (not (cl:subtypep 'array 'simple-array))))
(defmethod complex-arrays-distinct-p (client)
(declare (ignore client))
complex-arrays-distinct-p))
(defmethod find-class (client name &optional (errorp t) env)
(declare (ignore client))
(cl:find-class name errorp env))
;;; Helper function that loops over all codepoints to determine ranges.
;;; Assuming code-char-limit is sane, this shouldn't take too long.
(defun find-ranges (predicate &optional (start 0) (end cl:char-code-limit))
(loop :with ranges := nil
:with inside-range-p := nil
:with range-start := nil
:with range-end := nil
:for i :from start :below end
:do (if (funcall predicate (code-char i))
(if inside-range-p
(incf range-end)
(setq range-start i
range-end i
inside-range-p t))
(when inside-range-p
(progn
(push (cons range-start range-end) ranges)
(setq inside-range-p nil))))
:finally (return (nreverse ranges))))
(let ((standard-charset-pairs (find-ranges #'standard-char-p)))
(defmethod standard-charset-pairs (client)
(declare (ignore client))
standard-charset-pairs))
(let ((base-charset-pairs (find-ranges (lambda (c) (cl:typep c 'base-char)))))
(defmethod base-charset-pairs (client)
(declare (ignore client))
base-charset-pairs))
(defmethod char-code-limit (client)
(declare (ignore client))
cl:char-code-limit)
(defmethod sfdefinition (client name)
(declare (ignore client))
(cl:fdefinition name))
;;; Typexpand is messy.
;;; We could leave it undefined, and leave it to programmers to define
;;; appropriate clients for their implementations, or something. But I
;;; figure many programmers want it to Just Work in the basic sense of
;;; mimicking the host type system, so we do some implementation specifics.
#+ecl
(progn
;;; This is like si::normalize-type, except we return a type specifier and
;;; whether it expanded, and don't signal an error if something is malformed.
;;; This obviously uses internals - fragile - but ECL doesn't export this.
(defun typexpand-1 (spec env)
(declare (ignore env))
(cond ((symbolp spec)
(let ((expander (si:get-sysprop spec 'si::deftype-definition)))
(if expander
(values (funcall expander nil) t)
(values spec nil))))
((consp spec)
(let* ((head (car spec)) (args (cdr spec))
(expander (si:get-sysprop head 'si::deftype-definition)))
(if expander
(values (funcall expander args) t)
(values spec nil))))
(t (values spec nil))))
(defun %typexpand (type-specifier environment)
(loop with ever-expanded = nil
do (multiple-value-bind (expansion expandedp)
(typexpand-1 type-specifier environment)
(if expandedp
(setf ever-expanded t type-specifier expansion)
(return (values type-specifier ever-expanded)))))))
(defmethod typexpand (client tspec env)
(declare (ignore client) (ignorable env))
#+abcl (system:normalize-type tspec)
#+ccl (ccl::type-expand tspec env)
#+clasp (cleavir-env:type-expand env tspec)
#+cmucl (kernel:type-expand tspec)
#+ecl (%typexpand tspec env)
#+sbcl (sb-ext:typexpand tspec env)
#+sicl (sicl-type:typexpand tspec env)
;; in the worst case, just pretend deftype isn't real.
;; That will at least let you parse basic types without complaints.
#-(or abcl ccl clasp ccl ecl sbcl sicl) tspec)
;;; These are also kind of messy, for about the same reason.
(defmethod string-uaets (client)
#+abcl '(nil base-char character)
#+ccl '(base-char) ; FIXME: verify this. What is UAET of CHARACTER?
#+clasp '(base-char character)
#+cmucl '(base-char) ; Also verify
#+ecl '(base-char character)
#+sbcl '(nil base-char character)
#+sicl '(character)
#-(or abcl ccl clasp cmucl ecl sbcl sicl) '(base-char character)) ; guess!
(defmethod class-aliases (client)
#+(or abcl ccl cmucl ecl sbcl) ()
#+clasp
'((core:abstract-simple-vector (simple-array * (*)))
(core:simple-vector-fixnum (simple-array fixnum (*)))
(core:simple-vector-byte2-t (simple-array ext:byte2 (*)))
(core:simple-vector-byte4-t (simple-array ext:byte4 (*)))
(core:simple-vector-byte8-t (simple-array ext:byte8 (*)))
(core:simple-vector-byte16-t (simple-array ext:byte16 (*)))
(core:simple-vector-byte32-t (simple-array ext:byte32 (*)))
(core:simple-vector-byte64-t (simple-array ext:byte64 (*)))
(core:simple-vector-int2-t (simple-array ext:integer2 (*)))
(core:simple-vector-int4-t (simple-array ext:integer4 (*)))
(core:simple-vector-int8-t (simple-array ext:integer8 (*)))
(core:simple-vector-int16-t (simple-array ext:integer16 (*)))
(core:simple-vector-int32-t (simple-array ext:integer32 (*)))
(core:simple-vector-int64-t (simple-array ext:integer64 (*)))
(core:simple-vector-float (simple-array single-float (*)))
(core:simple-vector-double (simple-array double-float (*)))
(core:simple-character-string (simple-array character (*)))
(core:complex-vector (and (not simple-array) (array * (*))))
(core:bit-vector-ns (and (not simple-array) (array bit (*))))
(core:complex-vector-fixnum
(and (not simple-array) (array fixnum (*))))
(core:complex-vector-byte2-t
(and (not simple-array) (array ext:byte2 (*))))
(core:complex-vector-byte4-t
(and (not simple-array) (array ext:byte4 (*))))
(core:complex-vector-byte8-t
(and (not simple-array) (array ext:byte8 (*))))
(core:complex-vector-byte16-t
(and (not simple-array) (array ext:byte16 (*))))
(core:complex-vector-byte32-t
(and (not simple-array) (array ext:byte32 (*))))
(core:complex-vector-byte64-t
(and (not simple-array) (array ext:byte64 (*))))
(core:complex-vector-int2-t
(and (not simple-array) (array ext:integer2 (*))))
(core:complex-vector-int4-t
(and (not simple-array) (array ext:integer4 (*))))
(core:complex-vector-int8-t
(and (not simple-array) (array ext:integer8 (*))))
(core:complex-vector-int16-t
(and (not simple-array) (array ext:integer16 (*))))
(core:complex-vector-int32-t
(and (not simple-array) (array ext:integer32 (*))))
(core:complex-vector-int64-t
(and (not simple-array) (array ext:integer64 (*))))
(core:complex-vector-float
(and (not simple-array) (array single-float (*))))
(core:complex-vector-double
(and (not simple-array) (array double-float (*))))
(core:str8ns (and (not simple-array) (array base-char (*))))
(core:str-wns (and (not simple-array) (array character (*))))
(core:complex-vector-t (and (not simple-array) (array t (*))))
(core:simple-mdarray (and (not vector) simple-array))
(core:simple-mdarray-bit (and (not vector) (simple-array bit)))
(core:simple-mdarray-fixnum
(and (not vector) (simple-array fixnum)))
(core:simple-mdarray-byte2-t
(and (not vector) (simple-array ext:byte2)))
(core:simple-mdarray-byte4-t
(and (not vector) (simple-array ext:byte4)))
(core:simple-mdarray-byte8-t
(and (not vector) (simple-array ext:byte8)))
(core:simple-mdarray-byte16-t
(and (not vector) (simple-array ext:byte16)))
(core:simple-mdarray-byte32-t
(and (not vector) (simple-array ext:byte32)))
(core:simple-mdarray-byte64-t
(and (not vector) (simple-array ext:byte64)))
(core:simple-mdarray-int2-t
(and (not vector) (simple-array ext:integer2)))
(core:simple-mdarray-int4-t
(and (not vector) (simple-array ext:integer4)))
(core:simple-mdarray-int8-t
(and (not vector) (simple-array ext:integer8)))
(core:simple-mdarray-int16-t
(and (not vector) (simple-array ext:integer16)))
(core:simple-mdarray-int32-t
(and (not vector) (simple-array ext:integer32)))
(core:simple-mdarray-int64-t
(and (not vector) (simple-array ext:integer64)))
(core:simple-mdarray-float
(and (not vector) (simple-array single-float)))
(core:simple-mdarray-double
(and (not vector) (simple-array double-float)))
(core:simple-mdarray-base-char
(and (not vector) (simple-array base-char)))
(core:simple-mdarray-character
(and (not vector) (simple-array character)))
(core:simple-mdarray-t
(and (not vector) (simple-array t)))
(core:mdarray (and array (not vector)))
(core:mdarray-bit
(and (not simple-array) (not vector) (array bit)))
(core:mdarray-fixnum
(and (not simple-array) (not vector) (array fixnum)))
(core:mdarray-byte2-t
(and (not simple-array) (not vector) (array ext:byte2)))
(core:mdarray-byte4-t
(and (not simple-array) (not vector) (array ext:byte4)))
(core:mdarray-byte8-t
(and (not simple-array) (not vector) (array ext:byte8)))
(core:mdarray-byte16-t
(and (not simple-array) (not vector) (array ext:byte16)))
(core:mdarray-byte32-t
(and (not simple-array) (not vector) (array ext:byte32)))
(core:mdarray-byte64-t
(and (not simple-array) (not vector) (array ext:byte64)))
(core:mdarray-int2-t
(and (not simple-array) (not vector) (array ext:integer2)))
(core:mdarray-int4-t
(and (not simple-array) (not vector) (array ext:integer4)))
(core:mdarray-int8-t
(and (not simple-array) (not vector) (array ext:integer8)))
(core:mdarray-int16-t
(and (not simple-array) (not vector) (array ext:integer16)))
(core:mdarray-int32-t
(and (not simple-array) (not vector) (array ext:integer32)))
(core:mdarray-int64-t
(and (not simple-array) (not vector) (array ext:integer64)))
(core:mdarray-float
(and (not simple-array) (not vector) (array single-float)))
(core:mdarray-double
(and (not simple-array) (not vector) (array double-float)))
(core:mdarray-base-char
(and (not simple-array) (not vector) (array base-char)))
(core:mdarray-character
(and (not simple-array) (not vector) (array character)))
(core:mdarray-t
(and (not simple-array) (not vector) (array t))))
#+sicl
'((sicl-array:array-t (array t))
(sicl-array:array-bit (array bit))
(sicl-array:array-unsigned-byte-8 (array (unsigned-byte 8)))
(sicl-array:array-unsigned-byte-32 (array (unsigned-byte 32)))
(sicl-array:array-signed-byte-32 (array (signed-byte 32)))
(sicl-array:array-unsigned-byte-64 (array (unsigned-byte 64)))
(sicl-array:array-signed-byte-64 (array (signed-byte 64)))
(sicl-array:array-character (array character))
(sicl-array:array-single-float (array single-float))
(sicl-array:array-double-float (array single-float))
(sicl-array:array-complex-single-float (array (complex single-float)))
(sicl-array:array-complex-double-float (array (complex double-float)))
(sicl-array:vector-unsigned-byte-8 (vector (unsigned-byte 8)))
(sicl-array:vector-unsigned-byte-32 (vector (unsigned-byte 32)))
(sicl-array:vector-signed-byte-32 (vector (signed-byte 32)))
(sicl-array:vector-unsigned-byte-64 (vector (unsigned-byte 64)))
(sicl-array:vector-signed-byte-64 (vector (signed-byte 64))))
#-(or abcl ccl clasp cmucl ecl sbcl sicl) ()) ; guess!