... |
... |
@@ -141,59 +141,78 @@ |
141
|
141
|
(alien-function-type-result-type type)
|
142
|
142
|
(make-result-state))))))
|
143
|
143
|
|
144
|
|
-(deftransform %alien-funcall ((function type &rest args))
|
145
|
|
- (assert (c::constant-continuation-p type))
|
|
144
|
+(defun %alien-funcall-aux (function type &rest args)
|
|
145
|
+ (declare (ignorable function type args))
|
146
|
146
|
(let* ((type (c::continuation-value type))
|
147
|
147
|
(arg-types (alien-function-type-arg-types type))
|
148
|
148
|
(result-type (alien-function-type-result-type type)))
|
149
|
149
|
(assert (= (length arg-types) (length args)))
|
150
|
|
- (if (or (some #'(lambda (type)
|
151
|
|
- (and (alien-integer-type-p type)
|
152
|
|
- (> (alien::alien-integer-type-bits type) 32)))
|
153
|
|
- arg-types)
|
154
|
|
- (and (alien-integer-type-p result-type)
|
155
|
|
- (> (alien::alien-integer-type-bits result-type) 32)))
|
156
|
|
- (collect ((new-args) (lambda-vars) (new-arg-types))
|
157
|
|
- (dolist (type arg-types)
|
158
|
|
- (let ((arg (gensym)))
|
159
|
|
- (lambda-vars arg)
|
160
|
|
- (cond ((and (alien-integer-type-p type)
|
161
|
|
- (> (alien::alien-integer-type-bits type) 32))
|
162
|
|
- (new-args `(logand ,arg #xffffffff))
|
163
|
|
- (new-args `(ash ,arg -32))
|
164
|
|
- (new-arg-types (parse-alien-type '(unsigned 32)))
|
165
|
|
- (if (alien-integer-type-signed type)
|
166
|
|
- (new-arg-types (parse-alien-type '(signed 32)))
|
167
|
|
- (new-arg-types (parse-alien-type '(unsigned 32)))))
|
168
|
|
- (t
|
169
|
|
- (new-args arg)
|
170
|
|
- (new-arg-types type)))))
|
171
|
|
- (cond ((and (alien-integer-type-p result-type)
|
172
|
|
- (> (alien::alien-integer-type-bits result-type) 32))
|
173
|
|
- (let ((new-result-type
|
174
|
|
- (let ((alien::*values-type-okay* t))
|
175
|
|
- (parse-alien-type
|
176
|
|
- (if (alien-integer-type-signed result-type)
|
177
|
|
- '(values (unsigned 32) (signed 32))
|
178
|
|
- '(values (unsigned 32) (unsigned 32)))))))
|
179
|
|
- `(lambda (function type ,@(lambda-vars))
|
180
|
|
- (declare (ignore type))
|
181
|
|
- (multiple-value-bind (low high)
|
182
|
|
- (%alien-funcall function
|
183
|
|
- ',(make-alien-function-type
|
184
|
|
- :arg-types (new-arg-types)
|
185
|
|
- :result-type new-result-type)
|
186
|
|
- ,@(new-args))
|
187
|
|
- (logior low (ash high 32))))))
|
|
150
|
+ (unless (or (some #'(lambda (type)
|
|
151
|
+ (and (alien-integer-type-p type)
|
|
152
|
+ (> (alien::alien-integer-type-bits type) 32)))
|
|
153
|
+ arg-types)
|
|
154
|
+ (and (alien-integer-type-p result-type)
|
|
155
|
+ (/= (alien::alien-integer-type-bits result-type) 32)))
|
|
156
|
+ (format t "give up~%")
|
|
157
|
+ (c::give-up))
|
|
158
|
+ (collect ((new-args) (lambda-vars) (new-arg-types))
|
|
159
|
+ (dolist (type arg-types)
|
|
160
|
+ (let ((arg (gensym)))
|
|
161
|
+ (lambda-vars arg)
|
|
162
|
+ (cond ((and (alien-integer-type-p type)
|
|
163
|
+ (> (alien::alien-integer-type-bits type) 32))
|
|
164
|
+ (new-args `(logand ,arg #xffffffff))
|
|
165
|
+ (new-args `(ash ,arg -32))
|
|
166
|
+ (new-arg-types (parse-alien-type '(unsigned 32)))
|
|
167
|
+ (if (alien-integer-type-signed type)
|
|
168
|
+ (new-arg-types (parse-alien-type '(signed 32)))
|
|
169
|
+ (new-arg-types (parse-alien-type '(unsigned 32)))))
|
188
|
170
|
(t
|
189
|
|
- `(lambda (function type ,@(lambda-vars))
|
190
|
|
- (declare (ignore type))
|
191
|
|
- (%alien-funcall function
|
192
|
|
- ',(make-alien-function-type
|
193
|
|
- :arg-types (new-arg-types)
|
194
|
|
- :result-type result-type)
|
195
|
|
- ,@(new-args))))))
|
196
|
|
- (c::give-up))))
|
|
171
|
+ (new-args arg)
|
|
172
|
+ (new-arg-types type)))))
|
|
173
|
+ (cond ((and (alien-integer-type-p result-type)
|
|
174
|
+ (< (alien::alien-integer-type-bits result-type) 32))
|
|
175
|
+ (let ((new-result-type
|
|
176
|
+ (parse-alien-type
|
|
177
|
+ (if (alien-integer-type-signed result-type)
|
|
178
|
+ '(signed 32)
|
|
179
|
+ '(unsigned 32)))))
|
|
180
|
+ `(lambda (function type ,@(lambda-vars))
|
|
181
|
+ (declare (ignore type))
|
|
182
|
+ (%alien-funcall function
|
|
183
|
+ ',(make-alien-function-type
|
|
184
|
+ :arg-types (new-arg-types)
|
|
185
|
+ :result-type new-result-type)
|
|
186
|
+ ,@(new-args)))))
|
|
187
|
+ ((and (alien-integer-type-p result-type)
|
|
188
|
+ (> (alien::alien-integer-type-bits result-type) 32))
|
|
189
|
+ (let ((new-result-type
|
|
190
|
+ (let ((alien::*values-type-okay* t))
|
|
191
|
+ (parse-alien-type
|
|
192
|
+ (if (alien-integer-type-signed result-type)
|
|
193
|
+ '(values (unsigned 32) (signed 32))
|
|
194
|
+ '(values (unsigned 32) (unsigned 32)))))))
|
|
195
|
+ `(lambda (function type ,@(lambda-vars))
|
|
196
|
+ (declare (ignore type))
|
|
197
|
+ (multiple-value-bind (low high)
|
|
198
|
+ (%alien-funcall function
|
|
199
|
+ ',(make-alien-function-type
|
|
200
|
+ :arg-types (new-arg-types)
|
|
201
|
+ :result-type new-result-type)
|
|
202
|
+ ,@(new-args))
|
|
203
|
+ (logior low (ash high 32))))))
|
|
204
|
+ (t
|
|
205
|
+ `(lambda (function type ,@(lambda-vars))
|
|
206
|
+ (declare (ignore type))
|
|
207
|
+ (%alien-funcall function
|
|
208
|
+ ',(make-alien-function-type
|
|
209
|
+ :arg-types (new-arg-types)
|
|
210
|
+ :result-type result-type)
|
|
211
|
+ ,@(new-args))))))))
|
|
212
|
+
|
|
213
|
+(deftransform %alien-funcall ((function type &rest args))
|
|
214
|
+ (assert (c::constant-continuation-p type))
|
|
215
|
+ (apply #'%alien-funcall-aux function type args))
|
197
|
216
|
|
198
|
217
|
(define-vop (foreign-symbol-code-address)
|
199
|
218
|
(:translate #+linkage-table foreign-symbol-code-address
|