Changeset 432


Ignore:
Timestamp:
Jan 30, 2004, 11:55:34 AM (21 years ago)
Author:
Gary Byers
Message:

Install predefined classes here. Use DEFCLASS to create NS-LISP-EXCEPTION.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/examples/objc-support.lisp

    r227 r432  
    55(eval-when (:compile-toplevel :load-toplevel :execute)
    66  (require "BRIDGE"))
     7
     8
     9#+apple-objc
     10(progn
     11  (let* ((class-count 0))
     12    (declare (fixnum class-count))
     13    (defun reset-objc-class-count () (setq class-count 0))
     14    (defun map-objc-classes ()
     15      (let* ((n (#_objc_getClassList (%null-ptr) 0)))
     16        (declare (fixnum n))
     17        (if (> n class-count)
     18          (%stack-block ((buffer (the fixnum (ash n ppc32::word-shift))))
     19            (#_objc_getClassList buffer n)
     20          (do* ((i class-count (1+ i)))
     21               ((= i n (setq class-count i)))
     22            (declare (fixnum i))
     23            (install-foreign-objc-class
     24             (%get-ptr buffer (the fixnum  (ash i ppc32::word-shift))))))))))
     25  (def-ccl-pointers revive-objc-classes ()
     26    (reset-objc-class-count)
     27    (map-objc-classes)))
     28
     29#+gnu-objc
     30(defun iterate-over-class-methods (class method-function)
     31  (do* ((mlist (pref class :objc_class.methods)
     32               (pref mlist :objc_method_list.method_next)))
     33       ((%null-ptr-p mlist))
     34    (do* ((n (pref mlist :objc_method_list.method_count))
     35          (i 0 (1+ i))
     36          (method (pref mlist :objc_method_list.method_list)
     37                  (%incf-ptr method (record-length :objc_method))))
     38         ((= i n))
     39      (declare (fixnum i n))
     40      (funcall method-function method class))))
     41
     42#+gnu-objc
     43(progn
     44  (let* ((objc-class-count 0))
     45    (defun reset-objc-class-count () (setq objc-class-count 0))
     46    (defun note-all-library-methods (method-function)
     47      (do* ((i objc-class-count (1+ i))
     48            (class (id->objc-class i) (id->objc-class i)))
     49           ((eq class 0))
     50        (iterate-over-class-methods class method-function)
     51        (iterate-over-class-methods (id->objc-metaclass i) method-function))))
     52  (def-ccl-pointers revive-objc-classes ()
     53    (reset-objc-class-count)))
     54
     55(defun retain-obcj-object (x)
     56  (objc-message-send x "retain"))
    757
    858#+apple-objc
     
    76126                     (nsobject-description (ns-exception c))))))
    77127
    78 (def-objc-class ns-lisp-exception ns-exception
    79   (lispid :unsigned))
     128
     129
     130(defclass ns-lisp-exception (ns::ns-exception)
     131    ((lispid :foreign-type :unsigned))
     132  (:metaclass ns::+ns-object))
    80133
    81134(define-objc-method ((:id :init-with-lisp-id (:unsigned lisp-id))
     
    84137                         :reason #@"lisp exception"
    85138                         :user-info (%null-ptr)))
    86   (setq lispid lisp-id)
     139  (setf (slot-value self 'lispid) lisp-id)
    87140  self)
    88141
    89142(define-objc-method ((:unsigned lisp-id) ns-lisp-exception)
    90   lispid)
     143  (slot-value self 'lispid))
    91144
    92145(defun ns-exception->lisp-condition (nsexception)
     
    95148    (id-map-free-object *condition-id-map* (send nsexception 'lisp-id))
    96149    (make-condition 'ns-exception :ns-exception nsexception)))
     150
    97151
    98152(defmethod ns-exception ((c condition))
     
    106160  #|(dbg (format nil "~a" c))|#
    107161  (make-objc-instance 'ns-lisp-exception
    108                       :with-lisp-id (assign-id-map-id *condition-id-map* c)))
     162                      :with-lisp-id (assign-id-map-id *condition-id-map* c)))
     163 
     164
     165
     166(defun ns-exception->lisp-condition (nsexception)
     167  (if (typep nsexception 'ns-lisp-exception)
     168    (id-map-free-object *condition-id-map* (slot-value nsexception 'lispid))
     169    (make-condition 'ns-exception :ns-exception nsexception)))
    109170
    110171#+apple-objc
     
    124185
    125186)
     187
     188
    126189
    127190(defun open-main-bundle ()
Note: See TracChangeset for help on using the changeset viewer.