repos
/
smoke
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Speedup overload resolution and some other stuff for faster C++ method calling.
Annotate for file src/overload-resolution.lisp
2009-04-17 tobias
1
;;; C++ overload resolution
15:26:55 '
2
;;; See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf
'
3
'
4
(in-package :smoke)
'
5
2009-07-22 tobias
6
(defun cstring= (string1 string2)
22:26:05 '
7
"Returns T when the C strings STRING1 and STRING2 are equal
'
8
and NIL otherwise."
'
9
(declare (optimize (speed 3) (safety 0)))
'
10
(dotimes (i array-total-size-limit)
'
11
(let ((char1 (mem-aref string1 :char i))
'
12
(char2 (mem-aref string2 :char i)))
'
13
(when (/= char1 char2)
'
14
(return-from cstring= nil))
'
15
(when (or (= 0 char1)
'
16
(= 0 char2))
'
17
(return-from cstring= (= char1 char2))))))
'
18
2009-06-22 tobias
19
(declaim (inline cmp))
12:18:08 '
20
(defun cmp (a b)
2009-07-22 tobias
21
"Returns -1 if a < b; 0 if a = b and 1 if a > b"
22:26:05 '
22
(declare (values (integer -1 1)))
'
23
(if (< a b)
'
24
-1
'
25
(if (> a b)
'
26
1
'
27
0)))
2009-06-22 tobias
28
2009-07-22 tobias
29
(declaim (inline cstring-cmp))
22:26:05 '
30
(defun cstring-cmp (string1 string2)
'
31
"Compares the C strings STRING1 and STRING2."
'
32
(declare (foreign-pointer string1 string2)
'
33
(values (integer -1 1))
'
34
(optimize (speed 3)))
'
35
(dotimes (i array-total-size-limit (error "omg"))
'
36
(let ((char1 (mem-aref string1 :char i))
'
37
(char2 (mem-aref string2 :char i)))
'
38
(when (/= char1 char2)
'
39
(return-from cstring-cmp (if (< char1 char2) -1 1)))
'
40
(when (= 0 char1) ;; <=> (= 0 char2)
'
41
(return-from cstring-cmp 0)))))
2009-04-17 tobias
42
2009-06-22 tobias
43
(defun cstring/= (string1 string2)
12:18:08 '
44
"Returns T when the C strings STRING1 and STRING2 are not equal
'
45
and NIL otherwise."
2009-07-22 tobias
46
(declare (optimize (speed 3)))
22:26:05 '
47
(dotimes (i array-total-size-limit)
'
48
(let ((char1 (mem-aref string1 :char i))
'
49
(char2 (mem-aref string2 :char i)))
'
50
(when (/= char1 char2)
'
51
(return-from cstring/= i))
'
52
(when (= 0 char1)
'
53
(return-from cstring/= nil)))))
'
54
'
55
(declaim (inline smoke-method-name))
'
56
(defun smoke-method-name (method)
'
57
(mem-aref (smoke-array-pointer (smoke-module-method-names
'
58
(smoke-method-smoke method)))
'
59
:pointer
'
60
(the (smoke-index 0)
'
61
(method-slot-value method 'name))))
2009-04-17 tobias
62
2009-06-22 tobias
63
(defun method-cmp (method class-id name)
12:18:08 '
64
"Compares METHOD to the method with NAME of class CLASS-ID."
'
65
(declare (foreign-pointer name)
'
66
(type (smoke-index 0) class-id)
'
67
(smoke-method method)
2009-07-22 tobias
68
(values (integer -1 1))
2009-06-22 tobias
69
(optimize (speed 3) (debug 0) (safety 0)))
12:18:08 '
70
(let ((id-cmp (cmp (the (smoke-index 0) (method-slot-value method 'class))
'
71
(the (smoke-index 0) class-id))))
2009-07-22 tobias
72
(declare (type (integer -1 1) id-cmp)
22:26:05 '
73
(dynamic-extent id-cmp))
2009-06-22 tobias
74
(if (/= 0 id-cmp)
12:18:08 '
75
id-cmp
2009-07-22 tobias
76
(cstring-cmp (smoke-method-name method)
2009-06-22 tobias
77
name))))
12:18:08 '
78
2009-07-08 tobias
79
;;; INLINE OPTIMIZE
20:41:19 '
80
(declaim (inline first-unabigious-index))
2009-06-22 tobias
81
(defun first-unabigious-index (smoke index)
12:18:08 '
82
(declare (type smoke-index index)
2009-04-17 tobias
83
(optimize (speed 3)))
2009-06-22 tobias
84
(if (>= index 0)
12:18:08 '
85
index
'
86
(mem-aref (smoke-module-ambiguous-method-list smoke)
'
87
'smoke-index
'
88
(- index))))
2009-04-17 tobias
89
2009-06-22 tobias
90
(defun find-method-for-class (name class)
12:18:08 '
91
"Returns the index of a method with name NAME for class CLASS."
'
92
(declare (type foreign-pointer name)
'
93
(type smoke-class class)
'
94
(optimize (speed 3)))
'
95
(let* ((start 1) ;; 0 is "no method"
2009-06-30 tobias
96
(class-id (id class))
22:47:39 '
97
(smoke (smoke class))
2009-07-03 tobias
98
(end (1+ (smoke-array-length (smoke-module-method-maps smoke)))))
2009-07-08 tobias
99
(declare (type (smoke-index 0) start end)
20:41:19 '
100
(dynamic-extent start))
2009-06-22 tobias
101
(loop until (> start end) do
12:18:08 '
102
(let* ((index (the smoke-index (floor (+ end start) 2)))
'
103
(method (make-smoke-method
'
104
:smoke smoke
'
105
:id (the (smoke-index 0)
'
106
(first-unabigious-index
'
107
smoke
'
108
(foreign-slot-value
'
109
(mem-aref (smoke-array-pointer
'
110
(smoke-module-method-maps
'
111
smoke))
'
112
'smoke-method-map index)
'
113
'smoke-method-map
'
114
'method)))))
2009-07-22 tobias
115
(cmp (the (integer -1 1) (method-cmp method class-id name))))
22:26:05 '
116
(declare (type (integer -1 1) cmp)
2009-07-08 tobias
117
(dynamic-extent method))
2009-07-22 tobias
118
(ecase cmp
22:26:05 '
119
(-1 (setf start (1+ index)))
'
120
(0 (return-from find-method-for-class index))
'
121
(1 (setf end (1- index)))))))
2009-06-22 tobias
122
-1)
2009-04-17 tobias
123
2009-08-27 tobias
124
(defmacro push-candidate-method (index name argument-count class methods)
2009-06-22 tobias
125
(with-gensyms (method-map method-index method ambig-index i smoke)
12:18:08 '
126
`(let* ((,smoke (smoke ,class))
'
127
(,method-map (mem-aref
'
128
(smoke-array-pointer
'
129
(smoke-module-method-maps ,smoke))
'
130
'smoke-method-map
2009-07-22 tobias
131
,index))
2009-06-22 tobias
132
(,method-index (foreign-slot-value ,method-map 'smoke-method-map 'method))
12:18:08 '
133
(,method (make-smoke-method
'
134
:smoke ,smoke
'
135
:id (first-unabigious-index
'
136
,smoke
'
137
,method-index))))
'
138
(declare (type smoke-index ,method-index))
'
139
(if (cstring/= ,name
'
140
(smoke-method-name ,method))
'
141
nil
'
142
(progn
'
143
(when (= (the smoke-index ,argument-count)
'
144
(the smoke-index (get-arguments-length ,method)))
'
145
(if (< ,method-index 0)
'
146
(let ((,ambig-index (- ,method-index)))
'
147
(declare (type smoke-index ,ambig-index))
'
148
(loop as ,i = (the smoke-index
'
149
(mem-aref (smoke-module-ambiguous-method-list
'
150
,smoke)
'
151
'smoke-index
'
152
,ambig-index))
'
153
while (> (the smoke-index ,i) 0) do
2009-08-27 tobias
154
(incf ,ambig-index)
11:43:13 '
155
(push (make-smoke-method :smoke ,smoke
'
156
:id ,i)
'
157
,methods)))
'
158
(push ,method ,methods)))
2009-06-22 tobias
159
t)))))
2009-05-11 tobias
160
2009-08-30 tobias
161
(defun all-smoke-superclasses (class)
14:12:44 '
162
"Returns a list of all super-classes of CLASS and CLASS itself."
'
163
(declare (optimize (speed 3)))
'
164
(let ((classes (list class)))
'
165
(dolist (class (closer-mop:class-direct-superclasses class) classes)
'
166
(when (typep class 'smoke-standard-class)
'
167
(setf classes (append (all-smoke-superclasses class) classes))))))
'
168
2009-08-27 tobias
169
(defun viable-functions (name argument-count class)
11:43:13 '
170
"Returns a list of methods named NAME that take ARGUMENT-COUNT methods."
'
171
;; 13.3.2
'
172
;; FIXME make a lazy map-viable-functions to allow returning early,
'
173
;; when an exact match is found.
2009-06-22 tobias
174
(declare (optimize (speed 3)))
12:18:08 '
175
(with-foreign-string (name name)
2009-07-22 tobias
176
(let ((methods)
22:26:05 '
177
(smoke (smoke class)))
2009-08-27 tobias
178
(dolist (class (all-smoke-superclasses class))
2009-07-22 tobias
179
(let ((start-index (find-method-for-class name class)))
22:26:05 '
180
(declare (type smoke-index start-index))
'
181
(loop for index from start-index downto 1
'
182
while (push-candidate-method index name argument-count class
'
183
methods))
'
184
(loop for index from (1+ start-index)
'
185
to (the smoke-index (smoke-array-length
'
186
(smoke-module-method-maps smoke)))
'
187
while (push-candidate-method index name argument-count class
'
188
methods))))
2009-06-22 tobias
189
methods)))
12:18:08 '
190
2009-07-22 tobias
191
(eval-when (:compile-toplevel :load-toplevel :execute)
22:26:05 '
192
(defconstant +exact-match+ 0)
'
193
(defconstant +promotion+ 1)
'
194
(defconstant +conversion+ 2))
'
195
2009-07-08 tobias
196
(declaim (inline make-conversion make-exact-match make-promotion
20:41:19 '
197
make-number-conversion make-pointer-conversion
'
198
make-boolean-conversion make-user-conversion))
'
199
(defstruct conversion
'
200
(function-name nil :type (or symbol function) :read-only t)
'
201
(rank -1 :type fixnum :read-only t))
2009-04-17 tobias
202
2009-07-08 tobias
203
(defstruct (exact-match (:include conversion (rank +exact-match+))))
2009-04-17 tobias
204
2009-07-08 tobias
205
(defstruct (promotion (:include conversion (rank +promotion+))))
2009-04-17 tobias
206
2009-07-08 tobias
207
(defstruct (number-conversion (:include conversion (rank +conversion+))))
2009-04-17 tobias
208
2009-07-08 tobias
209
(defstruct (pointer-conversion (:include conversion (rank (1+ +conversion+))))
20:41:19 '
210
(from (find-class t) :type class :read-only t)
'
211
(to (find-class t) :type class :read-only t))
2009-04-17 tobias
212
2009-07-08 tobias
213
(defstruct (boolean-conversion (:include conversion (rank (+ 2 +conversion+)))))
2009-04-17 tobias
214
2009-07-08 tobias
215
(defstruct (user-conversion (:include conversion (rank (+ 3 +conversion+)))))
2009-04-17 tobias
216
2009-08-27 tobias
217
(defgeneric conversion< (conversion1 conversion2)
11:43:13 '
218
(:documentation
'
219
"Returns true when CONVERSION1 is better than CONVERSION2.")
2009-04-17 tobias
220
;; 13.3.3.2 Ranking implicit conversion sequences
15:26:55 '
221
;; 4
'
222
(:method (conversion1 conversion2)
2009-06-22 tobias
223
(declare (optimize (speed 3)))
2009-08-27 tobias
224
(or (null conversion2)
2009-07-08 tobias
225
(< (the fixnum (conversion-rank conversion1))
20:41:19 '
226
(the fixnum (conversion-rank conversion2)))))
2009-04-17 tobias
227
(:method ((conversion1 pointer-conversion) (conversion2 pointer-conversion))
2009-06-22 tobias
228
(declare (optimize (speed 3)))
2009-07-08 tobias
229
(if (eq (pointer-conversion-from conversion1)
20:41:19 '
230
(pointer-conversion-from conversion2))
2009-04-17 tobias
231
;; A->B < A->C <=> B subclass of C
2009-07-08 tobias
232
(subtypep (pointer-conversion-to conversion1)
20:41:19 '
233
(pointer-conversion-to conversion2))
'
234
(if (eq (pointer-conversion-to conversion1)
'
235
(pointer-conversion-to conversion2))
2009-04-17 tobias
236
;; B->A < C->A <=> B subclass of C
2009-07-08 tobias
237
(subtypep (pointer-conversion-from conversion1)
20:41:19 '
238
(pointer-conversion-from conversion2))
2009-04-17 tobias
239
nil))))
15:26:55 '
240
'
241
(defgeneric conversion= (conversion1 conversion2)
2009-08-27 tobias
242
(:documentation
11:43:13 '
243
"Returns true when the standard conversion sequence CONVERSION1
'
244
is indistinguishable from CONVERSION2.")
2009-04-17 tobias
245
(:method (conversion1 conversion2)
2009-07-08 tobias
246
(= (conversion-rank conversion1) (conversion-rank conversion2)))
2009-05-11 tobias
247
(:method ((conversion1 (eql nil)) (conversion2 (eql nil)))
2009-07-22 tobias
248
t)
22:26:05 '
249
(:method ((conversion1 pointer-conversion) (conversion2 pointer-conversion))
'
250
(and (not (conversion< conversion1 conversion2))
'
251
(not (conversion< conversion2 conversion1)))))
2009-04-17 tobias
252
15:26:55 '
253
(defun max-conversion (conversion1 conversion2)
2009-05-11 tobias
254
"Returns the greater conversion of CONVERSION1 and CONVERSION2."
2009-04-17 tobias
255
(if (null conversion2)
15:26:55 '
256
conversion1
2009-08-27 tobias
257
(if (conversion< conversion1 conversion2)
2009-04-17 tobias
258
conversion2
15:26:55 '
259
conversion1)))
2009-05-11 tobias
260
2010-02-20 tobias
261
(eval-when (:compile-toplevel :load-toplevel :execute)
17:24:36 '
262
(defun conversion-function (name &optional arg)
'
263
(if arg
'
264
`(if (using-typep)
'
265
`(,,name
'
266
(find-class ',(class-name ,arg)))
'
267
#'(lambda (object)
'
268
(funcall (fdefinition ,name)
'
269
object ,arg)))
'
270
`(if (using-typep)
'
271
,name
'
272
(fdefinition ,name)))))
'
273
2009-09-01 tobias
274
(defmacro make-match (type &optional (name ''identity)
11:44:21 '
275
(argument nil)
2009-05-11 tobias
276
&rest args)
2009-07-08 tobias
277
`(,(symbolicate 'make- (eval type))
20:41:19 '
278
:function-name ,(conversion-function name argument)
2009-09-01 tobias
279
,@args))
2009-04-17 tobias
280
2009-05-11 tobias
281
(defun+using-type get-conversion-sequence object (object type &optional user)
2009-07-01 tobias
282
"Retrains a conversion sequence to convert a instance of type CLASS
2009-05-11 tobias
283
to an instance of type TYPE. When USER is true user conversions are considered."
2009-07-08 tobias
284
(if-let (match (call-using-type exact-match object type))
14:56:52 '
285
(if (eql t match)
'
286
(make-match 'exact-match)
'
287
(make-match 'exact-match match))
'
288
(or (call-using-type promotion object type)
'
289
(call-using-type conversion object type)
'
290
(and user
'
291
(call-using-type user-conversion object type)))))
2009-04-17 tobias
292
2009-05-11 tobias
293
(defun+using-types standard-conversion-sequence (method classes &optional user)
11:07:39 '
294
"Returns the conversion sequences to convert the arguments of types CLASSES
'
295
to the types required by METHOD."
2009-08-27 tobias
296
(let ((max-rank)
11:43:13 '
297
(conversions))
'
298
(loop for type in (arguments method)
'
299
for class in classes do
'
300
(let ((rank (call-using-type get-conversion-sequence class type user)))
'
301
(when (null rank)
'
302
(setf max-rank nil)
'
303
(return nil))
'
304
(setf max-rank (max-conversion rank max-rank))
'
305
(push (conversion-function-name rank) conversions)))
'
306
(values max-rank (reverse conversions))))
2009-04-17 tobias
307
2009-05-11 tobias
308
(defun+using-types conversion-sequence (method classes)
11:07:39 '
309
(call-using-types standard-conversion-sequence method classes t))
2009-04-17 tobias
310
2009-08-27 tobias
311
(defun+using-types find-best-viable-function (name arguments class)
2009-05-11 tobias
312
"Returns the method named NAME of class CLASS that can be called
11:07:39 '
313
using arguments of types TYPES with the lowest conversion sequence."
'
314
(call-using-types find-best-viable-function2
'
315
(function-using-types conversion-sequence)
2009-08-27 tobias
316
name arguments class))
2009-04-17 tobias
317
2009-08-27 tobias
318
(defun+using-types find-best-viable-function2 (get-sequence name objects class)
11:43:13 '
319
(declare (type (function (t list) (values t function)) get-sequence))
2009-05-11 tobias
320
(when (and (using-typep)
11:07:39 '
321
(not (typep class 'smoke-standard-class)))
'
322
(throw 'unspecific-type class))
2009-05-11 tobias
323
(let ((viable-functions (viable-functions name (length objects)
2009-08-27 tobias
324
class))
2009-05-11 tobias
325
(best-rank)
2009-04-17 tobias
326
(best-method)
15:26:55 '
327
(conversions))
2009-08-27 tobias
328
(loop for method in viable-functions do
11:43:13 '
329
(multiple-value-bind (rank method-conversions)
'
330
(funcall get-sequence method objects)
'
331
;; FIXME test for ambiguous overload #'conversion=
'
332
(when (and rank (conversion< rank best-rank))
'
333
(setf best-rank rank)
'
334
(setf best-method method)
'
335
(setf conversions method-conversions)
'
336
(when (conversion= rank (make-match 'exact-match))
'
337
(return)))))
'
338
(values best-method conversions)))
2009-04-17 tobias
339
2009-05-11 tobias
340
(defvar *from-lisp-translations* (make-hash-table :test 'equal))
11:07:39 '
341
'
342
(defmacro define-from-lisp-translation (type-names lisp-type
'
343
&optional
'
344
(conversion-function-name 'identity))
2009-05-11 tobias
345
"Defines a translation from LISP-TYPE to the C++ types TYPE-NAMES using
14:11:35 '
346
the function CONVERSION-FUNCTION-NAME."
2009-05-11 tobias
347
`(progn ,@(loop for type-name in (ensure-list type-names)
2009-05-11 tobias
348
collect `(setf (gethash ,type-name *from-lisp-translations*)
2009-09-02 tobias
349
#'(lambda (type)
11:49:34 '
350
(and (subtypep type ',lisp-type)
2009-05-11 tobias
351
',conversion-function-name))))))
11:07:39 '
352
'
353
(define-from-lisp-translation ("void*" "const void*" "void**" "const void**")
'
354
foreign-pointer)
'
355
'
356
;; FIXME grovel this?
'
357
(deftype c-integer (ctype)
'
358
(let ((bits (* 8 (foreign-type-size ctype))))
2009-05-11 tobias
359
(if (starts-with-subseq
2009-05-11 tobias
360
(symbol-name :unsigned)
11:07:39 '
361
(symbol-name ctype))
'
362
`(unsigned-byte ,bits)
'
363
`(signed-byte ,bits))))
'
364
'
365
'
366
(defun+using-type exact-match object (object type)
'
367
"Test for an exact match."
2009-04-17 tobias
368
(case (type-id type)
2009-06-22 tobias
369
(0 (when-let (test (gethash (name type) *from-lisp-translations*))
2009-09-02 tobias
370
(funcall test (object.type-of))))
2009-05-11 tobias
371
(1 (object.typep 'boolean))
11:07:39 '
372
(2 (object.typep 'standard-char))
'
373
(3 (object.typep '(c-integer :unsigned-char)))
'
374
(4 (object.typep '(c-integer :short)))
'
375
(5 (object.typep '(c-integer :unsigned-short)))
'
376
(6 (object.typep '(c-integer :int)))
'
377
(7 (object.typep '(c-integer :unsigned-int)))
'
378
(10 (object.typep 'single-float))
'
379
(11 (object.typep 'double-float))
2010-01-25 tobias
380
(12 (object.typep 'enum)) ;; FIXME enum-type
2009-09-09 tobias
381
(13 (and (object.typep 'smoke-standard-object)
13:22:32 '
382
(smoke-type= (get-class type) (object.type-of))))))
2009-05-11 tobias
383
11:07:39 '
384
'
385
(defun make-cleanup-pointer (pointer cleanup-function)
2009-05-26 tobias
386
"Returns a pointer that calls CLEANUP-FUNCTION with pointer as argument
09:54:47 '
387
when it is finalized."
2009-05-11 tobias
388
(let ((address (pointer-address pointer)))
11:07:39 '
389
(tg:finalize pointer #'(lambda ()
'
390
(funcall cleanup-function
'
391
(make-pointer address))))))
'
392
2009-04-17 tobias
393
(defun make-auto-pointer (pointer)
15:26:55 '
394
"Returns a pointer that frees the memory at POINTER when it is finalized."
2009-05-26 tobias
395
(make-cleanup-pointer pointer #'foreign-free))
2009-04-17 tobias
396
2009-05-11 tobias
397
(defun coerce-c-string (string)
11:07:39 '
398
(make-auto-pointer (foreign-string-alloc string)))
'
399
2010-02-20 tobias
400
(defun coerce-enum (enum)
2009-05-11 tobias
401
(cxx-support:value enum))
11:07:39 '
402
2009-07-02 tobias
403
(defun coerce-double-float (number)
21:51:50 '
404
(float number 0d0))
'
405
'
406
;; FIXME incomplete
2009-05-11 tobias
407
(defun+using-type promotion object (object type)
2009-04-17 tobias
408
(declare (smoke-type type))
15:26:55 '
409
(case (type-id type)
2009-05-11 tobias
410
(0 (when (and (string= (name type) "const char*")
11:07:39 '
411
(object.typep 'string))
'
412
(make-match 'promotion 'coerce-c-string)))
'
413
(6 (when (object.typep 'enum)
2010-02-20 tobias
414
(make-match 'promotion 'coerce-enum)))
2009-05-11 tobias
415
(7 (when (object.typep 'enum)
2010-02-20 tobias
416
(make-match 'promotion 'coerce-enum)))
2009-07-02 tobias
417
(11 (when (object.typep 'real)
2010-02-20 tobias
418
(make-match 'promotion 'coerce-double-float)))))
2009-04-17 tobias
419
2009-05-26 tobias
420
(declaim (inline coerce-to-class))
2009-05-11 tobias
421
(defun coerce-cast (object to-class)
11:07:39 '
422
(cast object to-class))
2009-04-17 tobias
423
2009-05-11 tobias
424
(defun coerce-to-void (object)
11:07:39 '
425
object)
2009-04-17 tobias
426
2009-05-11 tobias
427
(defun+using-type conversion-cast object (object type)
11:07:39 '
428
(when (and (class-p type)
'
429
(object.typep 'smoke-standard-object)
2009-08-27 tobias
430
(derived-p (object.type-of) (get-class type)))
2009-05-11 tobias
431
(make-match 'pointer-conversion
11:07:39 '
432
'coerce-cast
'
433
(find-smoke-class (get-class type))
'
434
:from (object.type-of)
'
435
:to (find-smoke-class (get-class type)))))
'
436
'
437
(defun+using-type conversion-void object (object type)
'
438
(when (and (string= (name type) "void*")
'
439
(object.typep 'smoke-standard-object))
'
440
(make-match 'pointer-conversion
'
441
'coerce-void
'
442
nil
'
443
:from (object.type-of)
'
444
:to (find-class 't))))
'
445
'
446
(defun+using-type conversion-pointer object (object type)
2009-07-22 tobias
447
;; Not using pointer-p to allow passing a raw pointer for
22:26:05 '
448
;; objects on the stack and references
2009-05-24 tobias
449
;; (e.g.: for qInstallMsgHandler(QtMsgHandler) )
21:28:44 '
450
;;
2009-07-22 tobias
451
;; FIXME this breaks passing pointers to references
22:26:05 '
452
;; e.g.: calling the function foo(QByteArray& foo)
'
453
;; with (foo pointer) assumes pointer to point to a QByteArray,
'
454
;; but actually the conversion sequence QByteArray(pointer) should be used.
'
455
;; When pointer is a null pointer it fails horribly!.
2009-05-24 tobias
456
(when (and (or (= 0 (type-id type)) ; voidp
21:28:44 '
457
(= 13 (type-id type))) ; class
2009-05-11 tobias
458
(object.typep 'foreign-pointer))
11:07:39 '
459
(make-match 'pointer-conversion 'identity nil
2009-08-02 tobias
460
:from (find-class 't)
10:12:41 '
461
:to (find-class 't)))) ;; FIXME get the class when applicable
2009-05-11 tobias
462
11:07:39 '
463
'
464
(defun+using-type conversion object (object type)
'
465
(or (call-using-type conversion-cast object type)
'
466
(call-using-type conversion-void object type)
'
467
(call-using-type conversion-pointer object type)))
'
468
'
469
(defun+using-type user-conversion object (object type)
'
470
(or (call-using-type operator-conversion object type)
'
471
(call-using-type constructor-conversion object type)))
'
472
'
473
(defun+using-type operator-conversion object (object type)
'
474
(when (object.typep 'smoke-standard-object)
'
475
(let ((method (find-smoke-method (object.type-of)
2009-07-24 tobias
476
(format nil "operator ~A"
13:32:23 '
477
(if (class-p type)
'
478
(name (get-class type))
'
479
(name type))))))
2009-05-11 tobias
480
(when (valid-p method)
2009-08-27 tobias
481
(assert (not (void-p type))
11:43:13 '
482
()
'
483
"Conversion operators not supported by Smoke.
'
484
Update to Smoke >= r955426.")
2009-07-24 tobias
485
(make-match 'user-conversion
13:32:23 '
486
(lispify (name method) :cxx))))))
2009-05-11 tobias
487
2009-05-26 tobias
488
(declaim (inline coerce-to-class))
2009-05-11 tobias
489
(defun coerce-to-class (object to-class)
11:07:39 '
490
(make-instance to-class
'
491
:args (list object)))
'
492
'
493
(defun+using-type constructor-conversion object (object type)
'
494
(when (class-p type)
2009-08-27 tobias
495
(let ((to-class (find-smoke-class (get-class type))))
11:43:13 '
496
(when (call-using-types find-best-viable-function2
'
497
(if (using-typep)
'
498
#'standard-conversion-sequence-using-types
'
499
#'standard-conversion-sequence)
2009-07-22 tobias
500
(format nil "~A" (name (get-class type)))
2009-08-27 tobias
501
(list object) to-class)
2010-01-10 tobias
502
(make-match 'user-conversion
17:31:42 '
503
'coerce-to-class
'
504
to-class)))))
2009-04-17 tobias
505
15:26:55 '
506
(defun call-sequence (method object sequence &rest args)
'
507
(s-call method object
2009-05-11 tobias
508
(mapcar #'(lambda (conversion argument)
11:07:39 '
509
(funcall conversion argument))
'
510
sequence args)))
2009-05-27 tobias
511
17:47:28 '
512
(defun format-no-applicable-cxx-method (stream name class arguments)
'
513
(format stream
'
514
"No applicable method ~S of ~A for ~S.
2009-07-02 tobias
515
Candidates are:~{~T~A~%~}."
2009-05-27 tobias
516
name class arguments
17:47:28 '
517
(mapcar #'signature
'
518
(viable-functions name
'
519
(length arguments)
'
520
(smoke-class-of class)))))
'
521
'
522
(define-condition no-applicable-cxx-method (error)
'
523
((method :initarg :method :reader condition-method)
'
524
(class :initarg :class :reader condition-class)
'
525
(arguments :initarg :arguments :reader condition-arguments))
'
526
(:report (lambda (condition stream)
'
527
(format-no-applicable-cxx-method stream
'
528
(condition-method condition)
'
529
(condition-class condition)
'
530
(condition-arguments condition)))))
2009-09-01 tobias
531
2009-04-17 tobias
532
(defun call-using-args (object-or-class name arguments)
2009-06-22 tobias
533
"Calls the method NAME of OBJECT-OR-CLASS with ARGUMENTS."
2009-09-09 tobias
534
(declare (optimize (speed 3)))
2009-08-27 tobias
535
(if (null arguments)
11:43:13 '
536
(let ((method (find-smoke-method (smoke-class-of object-or-class)
'
537
name)))
'
538
(unless (valid-p method)
'
539
(error (make-condition 'no-applicable-cxx-method
'
540
:method name
'
541
:class object-or-class
'
542
:arguments arguments)))
'
543
(if (static-p method)
'
544
(s-call method (null-pointer))
'
545
(s-call method (cast object-or-class (get-class method)))))
'
546
(multiple-value-bind (method sequence)
'
547
(find-best-viable-function name
'
548
arguments
'
549
(smoke-class-of object-or-class))
'
550
(when (null method)
'
551
(error (make-condition 'no-applicable-cxx-method
'
552
:method name
'
553
:class object-or-class
'
554
:arguments arguments)))
'
555
(if (static-p method)
'
556
(apply #'call-sequence method (null-pointer) sequence arguments)
'
557
(apply #'call-sequence method (cast object-or-class (get-class method))
'
558
sequence arguments)))))