Changeset 403


Ignore:
Timestamp:
Jan 25, 2004, 2:14:24 PM (21 years ago)
Author:
Gary Byers
Message:

Try to introduce "foreign type ordinals", which can be embedded in
MACPTRs (this is hard to bootstrap for many reasons.)
(PREF foo :thing.embedded-record) expands into some SETFable noise
around %INC-PTR.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lib/foreign-types.lisp

    r385 r403  
    5858  (attributes #+darwinppc-target '(:signed-char :struct-by-value :prepend-underscores)
    5959              #+linuxppc-target ())
    60   (ordinal->type (make-array 100 :fill-pointer 0)))
     60  (ordinal->type (make-array 100 :fill-pointer 1)))
    6161
    6262(defvar *host-ftd* (make-ftd))
     
    288288  (class 'root :type symbol)
    289289  (bits nil :type (or null unsigned-byte))
    290   (alignment (guess-alignment bits) :type (or null unsigned-byte)))
     290  (alignment (guess-alignment bits) :type (or null unsigned-byte))
     291  (assigned-ordinal nil))
     292
     293(defun foreign-type-ordinal (ftype)
     294  (or (foreign-type-assigned-ordinal ftype)
     295      (setf (foreign-type-assigned-ordinal ftype)
     296            (vector-push-extend ftype (ftd-ordinal->type *target-ftd*)))))
     297
     298(defun ordinal-to-foreign-type (ordinal &optional (ftd *target-ftd*))
     299  (elt (ftd-ordinal->type ftd) ordinal))
     300
    291301
    292302(defmethod make-load-form ((s foreign-type) &optional env)
    293303  (make-load-form-saving-slots s :environment env))
     304
    294305
    295306
     
    623634    (make-foreign-integer-type :bits bits)))
    624635
     636
     637
    625638(def-foreign-type-translator integer (&optional (bits 32))
    626639  (if (<= bits 32)
     
    634647
    635648(def-foreign-type-method (integer :unparse) (type)
    636   (list (if (foreign-integer-type-signed type) 'signed 'unsigned)
     649  (list (if (foreign-integer-type-signed type) :signed :unsigned)
    637650        (foreign-integer-type-bits type)))
    638651
     
    855868;;;; The MEM-BLOCK type.
    856869
     870
    857871(def-foreign-type-class (mem-block :include foreign-value))
    858872
    859873(def-foreign-type-method (mem-block :extract-gen) (type sap offset)
    860   (declare (ignore type))
    861   `(%inc-ptr ,sap (/ ,offset 8)))
     874  (let* ((nbytes (%foreign-type-or-record-size type :bytes)))
     875    `(%composite-pointer-ref ,nbytes ,sap (/ ,offset 8))))
    862876
    863877(def-foreign-type-method (mem-block :deposit-gen) (type sap offset value)
     
    12981312
    12991313(defun %foreign-type-or-record (type)
    1300   (if (consp type)
    1301     (parse-foreign-type type)
    1302     (or (%find-foreign-record type)
    1303         (parse-foreign-type type))))
     1314  (if (typep type 'foreign-type)
     1315    type
     1316    (if (consp type)
     1317      (parse-foreign-type type)
     1318      (or (%find-foreign-record type)
     1319          (parse-foreign-type type)))))
    13041320
    13051321(defun %foreign-type-or-record-size (type &optional (units :bits))
     
    16171633            (accessors s))
    16181634          (accessors field-name))))))
     1635
     1636(defun %assert-macptr-ftype (macptr ftype)
     1637  (if (eq (class-of macptr) *macptr-class*)
     1638    (%set-macptr-type macptr (foreign-type-ordinal ftype)))
     1639  macptr)
     1640
     1641(defun %macptr-ftype (macptr)
     1642  (if (eq (class-of macptr) *macptr-class*)
     1643    (ordinal-to-foreign-type (%macptr-type macptr))))
     1644
     1645
    16191646 
     1647 
Note: See TracChangeset for help on using the changeset viewer.