Changeset 5890
- Timestamp:
- Feb 10, 2007, 11:01:15 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/examples/objc-support.lisp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/examples/objc-support.lisp
r5865 r5890 5 5 (eval-when (:compile-toplevel :load-toplevel :execute) 6 6 (require "BRIDGE")) 7 8 (defun allocate-objc-object (class) 9 (send class 'alloc)) 10 7 11 8 12 #-apple-objc-2.0 … … 10 14 (def-foreign-type :<CGF>loat :float) 11 15 (def-foreign-type :<NSUI>nteger :unsigned)' 12 (def-foreign-type :<NSI>nteger :signed)) 16 (def-foreign-type :<NSI>nteger :signed) 17 ) 13 18 14 19 (defconstant +cgfloat-zero+ 15 20 #+(and apple-objc-2.0 64-bit-target) 0.0d0 16 21 #-(and apple-objc-2.0 64-bit-target) 0.0f0) 22 23 (deftype cg-float () 24 #+(and apple-objc-2.0 64-bit-target) 'double-float 25 #-(and apple-objc-2.0 64-bit-target) 'single-float) 17 26 18 27 #+apple-objc … … 178 187 (error (c) (external-call "__NSRaiseError" :address (ns-exception c) :void)))) 179 188 189 #+ppc-target 180 190 (defun objc-callback-error-return (condition return-value-pointer return-address-pointer) 181 (%set-object return-address-pointer 0 182 (%reference-external-entry-point (load-time-value (external "__NSRaiseError")))) 191 ;; On PPC, the "address" of an external entry point is always 192 ;; aligned on a 32-bit word boundary. On PPC32, it can always 193 ;; be represented as a fixnum; on PPC64, it might be a pointer 194 ;; instead. 195 ;; Note that this clobbers the actual (foreign) return address, 196 ;; replacing it with the address of #__NSRaiseError. Note also 197 ;; that storing the NSException object as the return value has 198 ;; the desired effect of causing #__NSRaiseError to be called 199 ;; with that NSException as its argument (because r3 is used both 200 ;; as the canonical return value register and used to pass the 201 ;; first argument on PPC.) 202 (let* ((addr (%reference-external-entry-point (load-time-value (external "__NSRaiseError"))))) 203 (if (type addr 'fixnum) 204 (%set-object return-address-pointer 0 addr) 205 (setf (%get-ptr return-address-pointer 0) addr))) 183 206 (setf (%get-ptr return-value-pointer 0) (ns-exception condition)) 184 207 nil) 185 208 209 #+x8664-target 210 (progn 211 (defloadvar *x8664-objc-callback-error-return-trampoline* 212 (let* ((code-bytes '(#x48 #x89 #xc7 ; movq %rax %rdi 213 #x66 #x48 #x0f #x7e ; movd %xmm0,%rax 214 #x52 ; pushq %rdx 215 #xff #xe0)) ; jmp *rax 216 (nbytes (length code-bytes)) 217 (ptr (#_malloc nbytes))) 218 (dotimes (i nbytes ptr) 219 (setf (%get-unsigned-byte ptr i) (pop code-bytes))))) 220 221 (defun objc-callback-error-return (condition return-value-pointer return-address-pointer) 222 ;; The callback glue reserves space for %rax at return-value-pointer-8, 223 ;; for %rdx at -16, for %xmm0 at -24. Store NS-EXCEPTION in the 224 ;; %rax slot, the address of #__NSRaiseError in the %rdx slot, the 225 ;; original return address in the %xmm0 slot, and force a return to 226 ;; the trampoline code above. 227 (setf (%get-ptr return-value-pointer -8) (ns-exception condition) 228 (%get-ptr return-value-pointer -16) (%get-ptr return-address-pointer 0) 229 (%get-ptr return-address-pointer 0) *x8664-objc-callback-error-return-trampoline*) 230 ;; A foreign entry point is always an integer on x8664. 231 (let* ((addr (%reference-external-entry-point (load-time-value (external "__NSRaiseError"))))) 232 (if (< addr 0) ;unlikely 233 (setf (%%get-signed-longlong return-value-pointer -24) addr) 234 (setf (%%get-unsigned-longlong return-value-pointer -24) addr))) 235 nil) 236 237 238 239 ) 240 241 186 242 ) 187 243 … … 192 248 193 249 ;;; Create a new immutable dictionary just like src, replacing the 194 ;;; value of "newkey" with "newvalue".250 ;;; value of each key in key-value-pairs with the corresponding value. 195 251 (defun copy-dictionary (src &rest key-value-pairs) 196 252 (declare (dynamic-extent key-value-pairs))
Note:
See TracChangeset
for help on using the changeset viewer.
