- (setf (alien-type-class-include old) include)
- (setf (gethash name *alien-type-classes*)
- (make-alien-type-class :name name :include include)))))
+ (setf (alien-type-class-include old) include)
+ (setf (gethash name *alien-type-classes*)
+ (make-alien-type-class :name name :include include)))))
) ; EVAL-WHEN
;;; We define a keyword "BOA" constructor so that we can reference the
;;; slot names in init forms.
(def!macro define-alien-type-class ((name &key include include-args)
) ; EVAL-WHEN
;;; We define a keyword "BOA" constructor so that we can reference the
;;; slot names in init forms.
(def!macro define-alien-type-class ((name &key include include-args)
- (etypecase include
- (null
- (values nil 'alien-type nil))
- (symbol
- (values
- include
- (symbolicate "ALIEN-" include "-TYPE")
- nil))
- (list
- (values
- (car include)
- (symbolicate "ALIEN-" (car include) "-TYPE")
- (cdr include))))
+ (etypecase include
+ (null
+ (values nil 'alien-type nil))
+ (symbol
+ (values
+ include
+ (symbolicate "ALIEN-" include "-TYPE")
+ nil))
+ (list
+ (values
+ (car include)
+ (symbolicate "ALIEN-" (car include) "-TYPE")
+ (cdr include))))
- (eval-when (:compile-toplevel :load-toplevel :execute)
- (create-alien-type-class-if-necessary ',name ',(or include 'root)))
- (def!struct (,defstruct-name
- (:include ,include-defstruct
- (class ',name)
- ,@overrides)
- (:constructor
- ,(symbolicate "MAKE-" defstruct-name)
- (&key class bits alignment
- ,@(mapcar (lambda (x)
- (if (atom x) x (car x)))
- slots)
- ,@include-args
- ;; KLUDGE
- &aux (alignment (or alignment (guess-alignment bits))))))
- ,@slots)))))
+ (eval-when (:compile-toplevel :load-toplevel :execute)
+ (create-alien-type-class-if-necessary ',name ',(or include 'root)))
+ (def!struct (,defstruct-name
+ (:include ,include-defstruct
+ (class ',name)
+ ,@overrides)
+ (:constructor
+ ,(symbolicate "MAKE-" defstruct-name)
+ (&key class bits alignment
+ ,@(mapcar (lambda (x)
+ (if (atom x) x (car x)))
+ slots)
+ ,@include-args
+ ;; KLUDGE
+ &aux (alignment (or alignment (guess-alignment bits))))))
+ ,@slots)))))
(def!macro define-alien-type-method ((class method) lambda-list &rest body)
(let ((defun-name (symbolicate class "-" method "-METHOD")))
`(progn
(defun ,defun-name ,lambda-list
(def!macro define-alien-type-method ((class method) lambda-list &rest body)
(let ((defun-name (symbolicate class "-" method "-METHOD")))
`(progn
(defun ,defun-name ,lambda-list
(def!macro invoke-alien-type-method (method type &rest args)
(let ((slot (method-slot method)))
(once-only ((type type))
`(funcall (do ((class (alien-type-class-or-lose (alien-type-class ,type))
(def!macro invoke-alien-type-method (method type &rest args)
(let ((slot (method-slot method)))
(once-only ((type type))
`(funcall (do ((class (alien-type-class-or-lose (alien-type-class ,type))
- (alien-type-class-include class)))
- ((null class)
- (error "method ~S not defined for ~S"
- ',method (alien-type-class ,type)))
- (let ((fn (,slot class)))
- (when fn
- (return fn))))
- ,type ,@args))))
+ (alien-type-class-include class)))
+ ((null class)
+ (error "method ~S not defined for ~S"
+ ',method (alien-type-class ,type)))
+ (let ((fn (,slot class)))
+ (when fn
+ (return fn))))
+ ,type ,@args))))
(eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
(defun auxiliary-type-definitions (env)
(multiple-value-bind (result expanded-p)
(eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
(defun auxiliary-type-definitions (env)
(multiple-value-bind (result expanded-p)
- result
- ;; This is like having the global symbol-macro definition be
- ;; NIL, but global symbol-macros make me vaguely queasy, so
- ;; I do it this way instead.
- nil))))
+ result
+ ;; This is like having the global symbol-macro definition be
+ ;; NIL, but global symbol-macros make me vaguely queasy, so
+ ;; I do it this way instead.
+ nil))))
;;; Process stuff in a new scope.
(def!macro with-auxiliary-alien-types (env &body body)
``(symbol-macrolet ((&auxiliary-type-definitions&
;;; Process stuff in a new scope.
(def!macro with-auxiliary-alien-types (env &body body)
``(symbol-macrolet ((&auxiliary-type-definitions&
- ,(append *new-auxiliary-types*
- (auxiliary-type-definitions ,env))))
+ ,(append *new-auxiliary-types*
+ (auxiliary-type-definitions ,env))))
- (:primitive
- (let ((translator (info :alien-type :translator type)))
- (unless translator
- (error "no translator for primitive alien type ~S" type))
- (funcall translator (list type) env)))
- (:defined
- (or (info :alien-type :definition type)
- (error "no definition for alien type ~S" type)))
- (:unknown
- (error "unknown alien type: ~S" type)))))
+ (:primitive
+ (let ((translator (info :alien-type :translator type)))
+ (unless translator
+ (error "no translator for primitive alien type ~S" type))
+ (funcall translator (list type) env)))
+ (:defined
+ (or (info :alien-type :definition type)
+ (error "no definition for alien type ~S" type)))
+ (:unknown
+ (error "unknown alien type: ~S" type)))))
(defun auxiliary-alien-type (kind name env)
(declare (type (or sb!kernel:lexenv null) env))
(flet ((aux-defn-matches (x)
(defun auxiliary-alien-type (kind name env)
(declare (type (or sb!kernel:lexenv null) env))
(flet ((aux-defn-matches (x)
- (values (third in-auxiliaries) t)
- (ecase kind
- (:struct
- (info :alien-type :struct name))
- (:union
- (info :alien-type :union name))
- (:enum
- (info :alien-type :enum name)))))))
+ (values (third in-auxiliaries) t)
+ (ecase kind
+ (:struct
+ (info :alien-type :struct name))
+ (:union
+ (info :alien-type :union name))
+ (:enum
+ (info :alien-type :enum name)))))))
(defun (setf auxiliary-alien-type) (new-value kind name env)
(declare (type (or sb!kernel:lexenv null) env))
(flet ((aux-defn-matches (x)
(defun (setf auxiliary-alien-type) (new-value kind name env)
(declare (type (or sb!kernel:lexenv null) env))
(flet ((aux-defn-matches (x)
(when (find-if #'aux-defn-matches *new-auxiliary-types*)
(error "attempt to multiply define ~A ~S" kind name))
(when (find-if #'aux-defn-matches (auxiliary-type-definitions env))
(when (find-if #'aux-defn-matches *new-auxiliary-types*)
(error "attempt to multiply define ~A ~S" kind name))
(when (find-if #'aux-defn-matches (auxiliary-type-definitions env))
- (:struct
- (info :alien-type :struct name))
- (:union
- (info :alien-type :union name))
- (:enum
- (info :alien-type :enum name)))
- (error "attempt to shadow definition of ~A ~S" kind name)))))
+ (:struct
+ (info :alien-type :struct name))
+ (:union
+ (info :alien-type :union name))
+ (:enum
+ (info :alien-type :enum name)))
+ (error "attempt to shadow definition of ~A ~S" kind name)))))
(with-unique-names (whole env)
(let ((defun-name (symbolicate "ALIEN-" name "-TYPE-TRANSLATOR")))
(multiple-value-bind (body decls docs)
(with-unique-names (whole env)
(let ((defun-name (symbolicate "ALIEN-" name "-TYPE-TRANSLATOR")))
(multiple-value-bind (body decls docs)
- (sb!kernel:parse-defmacro lambda-list whole body name
- 'define-alien-type-translator
- :environment env)
- `(eval-when (:compile-toplevel :load-toplevel :execute)
- (defun ,defun-name (,whole ,env)
- (declare (ignorable ,env))
- ,@decls
- (block ,name
- ,body))
- (%define-alien-type-translator ',name #',defun-name ,docs))))))
+ (sb!kernel:parse-defmacro lambda-list whole body name
+ 'define-alien-type-translator
+ :environment env)
+ `(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun ,defun-name (,whole ,env)
+ (declare (ignorable ,env))
+ ,@decls
+ (block ,name
+ ,body))
+ (%define-alien-type-translator ',name #',defun-name ,docs))))))
(with-auxiliary-alien-types env
(let ((alien-type (parse-alien-type type env)))
`(eval-when (:compile-toplevel :load-toplevel :execute)
(with-auxiliary-alien-types env
(let ((alien-type (parse-alien-type type env)))
`(eval-when (:compile-toplevel :load-toplevel :execute)
- ,@(when *new-auxiliary-types*
- `((%def-auxiliary-alien-types ',*new-auxiliary-types*)))
- ,@(when name
- `((%define-alien-type ',name ',alien-type)))))))
+ ,@(when *new-auxiliary-types*
+ `((%def-auxiliary-alien-types ',*new-auxiliary-types*)))
+ ,@(when name
+ `((%define-alien-type ',name ',alien-type)))))))
(def!macro def-alien-type (&rest rest)
(deprecation-warning 'def-alien-type 'define-alien-type)
`(define-alien-type ,@rest))
(def!macro def-alien-type (&rest rest)
(deprecation-warning 'def-alien-type 'define-alien-type)
`(define-alien-type ,@rest))
;; Unless this is done we never actually get back the full type
;; from INFO, since the *new-auxiliary-types* have precendence.
(setf *new-auxiliary-types*
;; Unless this is done we never actually get back the full type
;; from INFO, since the *new-auxiliary-types* have precendence.
(setf *new-auxiliary-types*
- (remove info *new-auxiliary-types*
- :test (lambda (a b)
- (and (eq (first a) (first b))
- (eq (second a) (second b))))))
+ (remove info *new-auxiliary-types*
+ :test (lambda (a b)
+ (and (eq (first a) (first b))
+ (eq (second a) (second b))))))
- (macrolet ((frob (kind)
- `(let ((old (info :alien-type ,kind name)))
- (unless (or (null old) (alien-type-= old defn))
- (warn
- "redefining ~A ~S to be:~% ~S,~%was:~% ~S"
- kind name defn old))
- (setf (info :alien-type ,kind name) defn))))
- (ecase kind
- (:struct (frob :struct))
- (:union (frob :union))
- (:enum (frob :enum)))))))
+ (macrolet ((frob (kind)
+ `(let ((old (info :alien-type ,kind name)))
+ (unless (or (null old) (alien-type-= old defn))
+ (warn
+ "redefining ~A ~S to be:~% ~S,~%was:~% ~S"
+ kind name defn old))
+ (setf (info :alien-type ,kind name) defn))))
+ (ecase kind
+ (:struct (frob :struct))
+ (:union (frob :union))
+ (:enum (frob :enum)))))))
(defun %define-alien-type (name new)
(ecase (info :alien-type :kind name)
(:primitive
(error "~S is a built-in alien type." name))
(:defined
(let ((old (info :alien-type :definition name)))
(defun %define-alien-type (name new)
(ecase (info :alien-type :kind name)
(:primitive
(error "~S is a built-in alien type." name))
(:defined
(let ((old (info :alien-type :definition name)))
- (unless (or (null old) (alien-type-= new old))
- (warn "redefining ~S to be:~% ~S,~%was~% ~S"
- name
- (unparse-alien-type new)
- (unparse-alien-type old)))))
+ (unless (or (null old) (alien-type-= new old))
+ (warn "redefining ~S to be:~% ~S,~%was~% ~S"
+ name
+ (unparse-alien-type new)
+ (unparse-alien-type old)))))
- (:make-load-form-fun sb!kernel:just-dump-it-normally)
- (:constructor make-alien-type (&key class bits alignment
- &aux (alignment (or alignment (guess-alignment bits))))))
+ (:make-load-form-fun sb!kernel:just-dump-it-normally)
+ (:constructor make-alien-type (&key class bits alignment
+ &aux (alignment (or alignment (guess-alignment bits))))))
(class 'root :type symbol)
(bits nil :type (or null unsigned-byte))
(alignment nil :type (or null unsigned-byte)))
(class 'root :type symbol)
(bits nil :type (or null unsigned-byte))
(alignment nil :type (or null unsigned-byte)))
;; The type of this alien.
(type (missing-arg) :type alien-type)
;; The form to evaluate to produce the SAP pointing to where in the heap
;; The type of this alien.
(type (missing-arg) :type alien-type)
;; The form to evaluate to produce the SAP pointing to where in the heap
(def!method print-object ((info heap-alien-info) stream)
(print-unreadable-object (info stream :type t)
(funcall (formatter "~S ~S")
(def!method print-object ((info heap-alien-info) stream)
(print-unreadable-object (info stream :type t)
(funcall (formatter "~S ~S")
,form)))
(defun compute-extract-lambda (type)
`(lambda (sap offset ignore)
(declare (type system-area-pointer sap)
,form)))
(defun compute-extract-lambda (type)
`(lambda (sap offset ignore)
(declare (type system-area-pointer sap)
(defun compute-deposit-lambda (type)
(declare (type alien-type type))
`(lambda (sap offset ignore value)
(declare (type system-area-pointer sap)
(defun compute-deposit-lambda (type)
(declare (type alien-type type))
`(lambda (sap offset ignore value)
(declare (type system-area-pointer sap)
(let ((value (deport value ',type)))
,(invoke-alien-type-method :deposit-gen type 'sap 'offset 'value)
;; Note: the reason we don't just return the pre-deported value
(let ((value (deport value ',type)))
,(invoke-alien-type-method :deposit-gen type 'sap 'offset 'value)
;; Note: the reason we don't just return the pre-deported value
- (if (alien-integer-type-signed type)
- (case (alien-integer-type-bits type)
- (8 'signed-sap-ref-8)
- (16 'signed-sap-ref-16)
- (32 'signed-sap-ref-32)
- (64 'signed-sap-ref-64))
- (case (alien-integer-type-bits type)
- (8 'sap-ref-8)
- (16 'sap-ref-16)
- (32 'sap-ref-32)
- (64 'sap-ref-64)))))
+ (if (alien-integer-type-signed type)
+ (case (alien-integer-type-bits type)
+ (8 'signed-sap-ref-8)
+ (16 'signed-sap-ref-16)
+ (32 'signed-sap-ref-32)
+ (64 'signed-sap-ref-64))
+ (case (alien-integer-type-bits type)
+ (8 'sap-ref-8)
+ (16 'sap-ref-16)
+ (32 'sap-ref-32)
+ (64 'sap-ref-64)))))
- `(,ref-fun ,sap (/ ,offset sb!vm:n-byte-bits))
- (error "cannot extract ~W-bit integers"
- (alien-integer-type-bits type)))))
+ `(,ref-fun ,sap (/ ,offset sb!vm:n-byte-bits))
+ (error "cannot extract ~W-bit integers"
+ (alien-integer-type-bits type)))))
- :include-args (signed))
- name ; name of this enum (if any)
- from ; alist from keywords to integers
- to ; alist or vector from integers to keywords
- kind ; kind of from mapping, :VECTOR or :ALIST
- offset) ; offset to add to value for :VECTOR from mapping
+ :include-args (signed))
+ name ; name of this enum (if any)
+ from ; alist from symbols to integers
+ to ; alist or vector from integers to symbols
+ kind ; kind of from mapping, :VECTOR or :ALIST
+ offset) ; offset to add to value for :VECTOR from mapping
- (let ((result (parse-enum name mappings)))
- (when name
- (multiple-value-bind (old old-p)
- (auxiliary-alien-type :enum name env)
- (when old-p
- (unless (alien-type-= result old)
- (warn "redefining alien enum ~S" name))))
- (setf (auxiliary-alien-type :enum name env) result))
- result))
- (name
- (multiple-value-bind (result found)
- (auxiliary-alien-type :enum name env)
- (unless found
- (error "unknown enum type: ~S" name))
- result))
- (t
- (error "empty enum type: ~S" type))))
+ (let ((result (parse-enum name mappings)))
+ (when name
+ (multiple-value-bind (old old-p)
+ (auxiliary-alien-type :enum name env)
+ (when old-p
+ (unless (alien-type-= result old)
+ (warn "redefining alien enum ~S" name))))
+ (setf (auxiliary-alien-type :enum name env) result))
+ result))
+ (name
+ (multiple-value-bind (result found)
+ (auxiliary-alien-type :enum name env)
+ (unless found
+ (error "unknown enum type: ~S" name))
+ result))
+ (t
+ (error "empty enum type: ~S" type))))
- (if (listp el)
- (values (first el) (second el))
- (values el (1+ prev)))
- (setf prev val)
- (unless (keywordp sym)
- (error "The enumeration element ~S is not a keyword." sym))
- (unless (integerp val)
- (error "The element value ~S is not an integer." val))
- (unless (and max (> max val)) (setq max val))
- (unless (and min (< min val)) (setq min val))
- (when (rassoc val from-alist)
- (error "The element value ~S is used more than once." val))
- (when (assoc sym from-alist :test #'eq)
- (error "The enumeration element ~S is used more than once." sym))
- (push (cons sym val) from-alist)))
+ (if (listp el)
+ (values (first el) (second el))
+ (values el (1+ prev)))
+ (setf prev val)
+ (unless (symbolp sym)
+ (error "The enumeration element ~S is not a symbol." sym))
+ (unless (integerp val)
+ (error "The element value ~S is not an integer." val))
+ (unless (and max (> max val)) (setq max val))
+ (unless (and min (< min val)) (setq min val))
+ (when (rassoc val from-alist)
+ (warn "The element value ~S is used more than once." val))
+ (when (assoc sym from-alist :test #'eq)
+ (error "The enumeration element ~S is used more than once." sym))
+ (push (cons sym val) from-alist)))
(setf from-alist (sort from-alist #'< :key #'cdr))
(cond
;; If range is at least 20% dense, use vector mapping. Crossover
;; point solely on basis of space would be 25%. Vector mapping
;; is always faster, so give the benefit of the doubt.
(setf from-alist (sort from-alist #'< :key #'cdr))
(cond
;; If range is at least 20% dense, use vector mapping. Crossover
;; point solely on basis of space would be 25%. Vector mapping
;; is always faster, so give the benefit of the doubt.
- ((< 0.2 (/ (float (length from-alist)) (float (- max min))))
- ;; If offset is small and ignorable, ignore it to save time.
- (when (< 0 min 10) (setq min 0))
- (let ((to (make-array (1+ (- max min)))))
- (dolist (el from-alist)
- (setf (svref to (- (cdr el) min)) (car el)))
- (make-alien-enum-type :name name :signed signed
- :from from-alist :to to :kind
- :vector :offset (- min))))
+ ((< 0.2 (/ (float (length from-alist)) (float (1+ (- max min)))))
+ ;; If offset is small and ignorable, ignore it to save time.
+ (when (< 0 min 10) (setq min 0))
+ (let ((to (make-array (1+ (- max min)))))
+ (dolist (el from-alist)
+ (setf (svref to (- (cdr el) min)) (car el)))
+ (make-alien-enum-type :name name :signed signed
+ :from from-alist :to to :kind
+ :vector :offset (- min))))
- ,@(let ((prev -1))
- (mapcar (lambda (mapping)
- (let ((sym (car mapping))
- (value (cdr mapping)))
- (prog1
- (if (= (1+ prev) value)
- sym
- `(,sym ,value))
- (setf prev value))))
- (alien-enum-type-from type)))))
+ ,@(let ((prev -1))
+ (mapcar (lambda (mapping)
+ (let ((sym (car mapping))
+ (value (cdr mapping)))
+ (prog1
+ (if (= (1+ prev) value)
+ sym
+ `(,sym ,value))
+ (setf prev value))))
+ (alien-enum-type-from type)))))
- ,@(mapcar (lambda (mapping)
- `(,(car mapping) ,(cdr mapping)))
- (alien-enum-type-to type))))))
+ ,@(mapcar (lambda (mapping)
+ `(,(car mapping) ',(cdr mapping)))
+ (alien-enum-type-to type))))))
`(sap-ref-single ,sap (/ ,offset sb!vm:n-byte-bits)))
(define-alien-type-class (double-float :include (float (bits 64))
`(sap-ref-single ,sap (/ ,offset sb!vm:n-byte-bits)))
(define-alien-type-class (double-float :include (float (bits 64))
(define-alien-type-method (pointer :subtypep) (type1 type2)
(and (alien-pointer-type-p type2)
(let ((to1 (alien-pointer-type-to type1))
(define-alien-type-method (pointer :subtypep) (type1 type2)
(and (alien-pointer-type-p type2)
(let ((to1 (alien-pointer-type-to type1))
`(sap+ ,sap (/ ,offset sb!vm:n-byte-bits)))
(define-alien-type-method (mem-block :deposit-gen) (type sap offset value)
`(sap+ ,sap (/ ,offset sb!vm:n-byte-bits)))
(define-alien-type-method (mem-block :deposit-gen) (type sap offset value)
(let ((parsed-ele-type (parse-alien-type ele-type env)))
(make-alien-array-type
:element-type parsed-ele-type
:dimensions dims
:alignment (alien-type-alignment parsed-ele-type)
:bits (if (and (alien-type-bits parsed-ele-type)
(let ((parsed-ele-type (parse-alien-type ele-type env)))
(make-alien-array-type
:element-type parsed-ele-type
:dimensions dims
:alignment (alien-type-alignment parsed-ele-type)
:bits (if (and (alien-type-bits parsed-ele-type)
- (every #'integerp dims))
- (* (align-offset (alien-type-bits parsed-ele-type)
- (alien-type-alignment parsed-ele-type))
- (reduce #'* dims))))))
+ (every #'integerp dims))
+ (* (align-offset (alien-type-bits parsed-ele-type)
+ (alien-type-alignment parsed-ele-type))
+ (reduce #'* dims))))))
(define-alien-type-method (array :subtypep) (type1 type2)
(and (alien-array-type-p type2)
(let ((dim1 (alien-array-type-dimensions type1))
(define-alien-type-method (array :subtypep) (type1 type2)
(and (alien-array-type-p type2)
(let ((dim1 (alien-array-type-dimensions type1))
- (dim2 (alien-array-type-dimensions type2)))
- (and (= (length dim1) (length dim2))
- (or (and dim2
- (null (car dim2))
- (equal (cdr dim1) (cdr dim2)))
- (equal dim1 dim2))
- (alien-subtype-p (alien-array-type-element-type type1)
- (alien-array-type-element-type type2))))))
+ (dim2 (alien-array-type-dimensions type2)))
+ (and (= (length dim1) (length dim2))
+ (or (and dim2
+ (null (car dim2))
+ (equal (cdr dim1) (cdr dim2)))
+ (equal dim1 dim2))
+ (alien-subtype-p (alien-array-type-element-type type1)
+ (alien-array-type-element-type type2))))))
(name (missing-arg) :type symbol)
(type (missing-arg) :type alien-type)
(bits nil :type (or unsigned-byte null))
(name (missing-arg) :type symbol)
(type (missing-arg) :type alien-type)
(bits nil :type (or unsigned-byte null))
- "~S ~S~@[:~D~]"
- (alien-record-field-type field)
- (alien-record-field-name field)
- (alien-record-field-bits field))))
+ "~S ~S~@[:~D~]"
+ (alien-record-field-type field)
+ (alien-record-field-name field)
+ (alien-record-field-bits field))))
- (let* ((old (and name (auxiliary-alien-type kind name env)))
- (old-fields (and old (alien-record-type-fields old))))
- ;; KLUDGE: We can't easily compare the new fields
- ;; against the old fields, since the old fields have
- ;; already been parsed into an internal
- ;; representation, so we just punt, assuming that
- ;; they're consistent. -- WHN 200000505
- #|
- (unless (equal fields old-fields)
- ;; FIXME: Perhaps this should be a warning, and we
- ;; should overwrite the old definition and proceed?
- (error "mismatch in fields for ~S~% old ~S~% new ~S"
- name old-fields fields))
- |#
- (if old-fields
- old
- (let ((type (or old (make-alien-record-type :name name :kind kind))))
- (when (and name (not old))
- (setf (auxiliary-alien-type kind name env) type))
- (parse-alien-record-fields type fields env)
- type))))
- (name
- (or (auxiliary-alien-type kind name env)
- (setf (auxiliary-alien-type kind name env)
- (make-alien-record-type :name name :kind kind))))
- (t
- (make-alien-record-type :kind kind))))
+ (let* ((old (and name (auxiliary-alien-type kind name env)))
+ (old-fields (and old (alien-record-type-fields old))))
+ ;; KLUDGE: We can't easily compare the new fields
+ ;; against the old fields, since the old fields have
+ ;; already been parsed into an internal
+ ;; representation, so we just punt, assuming that
+ ;; they're consistent. -- WHN 200000505
+ #|
+ (unless (equal fields old-fields)
+ ;; FIXME: Perhaps this should be a warning, and we
+ ;; should overwrite the old definition and proceed?
+ (error "mismatch in fields for ~S~% old ~S~% new ~S"
+ name old-fields fields))
+ |#
+ (if old-fields
+ old
+ (let ((type (or old (make-alien-record-type :name name :kind kind))))
+ (when (and name (not old))
+ (setf (auxiliary-alien-type kind name env) type))
+ (parse-alien-record-fields type fields env)
+ type))))
+ (name
+ (or (auxiliary-alien-type kind name env)
+ (setf (auxiliary-alien-type kind name env)
+ (make-alien-record-type :name name :kind kind))))
+ (t
+ (make-alien-record-type :kind kind))))
;;; This is used by PARSE-ALIEN-TYPE to parse the fields of struct and
;;; union types. RESULT holds the record type we are paring the fields
;;; of, and FIELDS is the list of field specifications.
(defun parse-alien-record-fields (result fields env)
(declare (type alien-record-type result)
;;; This is used by PARSE-ALIEN-TYPE to parse the fields of struct and
;;; union types. RESULT holds the record type we are paring the fields
;;; of, and FIELDS is the list of field specifications.
(defun parse-alien-record-fields (result fields env)
(declare (type alien-record-type result)
- (declare (ignore bits))
- (let* ((field-type (parse-alien-type type env))
- (bits (alien-type-bits field-type))
- (alignment (alien-type-alignment field-type))
- (parsed-field
- (make-alien-record-field :type field-type
- :name var)))
- (push parsed-field parsed-fields)
- (when (null bits)
- (error "unknown size: ~S" (unparse-alien-type field-type)))
- (when (null alignment)
- (error "unknown alignment: ~S" (unparse-alien-type field-type)))
- (setf overall-alignment (max overall-alignment alignment))
- (ecase (alien-record-type-kind result)
- (:struct
- (let ((offset (align-offset total-bits alignment)))
- (setf (alien-record-field-offset parsed-field) offset)
- (setf total-bits (+ offset bits))))
- (:union
- (setf total-bits (max total-bits bits)))))))
+ (declare (ignore bits))
+ (let* ((field-type (parse-alien-type type env))
+ (bits (alien-type-bits field-type))
+ (alignment (alien-type-alignment field-type))
+ (parsed-field
+ (make-alien-record-field :type field-type
+ :name var)))
+ (push parsed-field parsed-fields)
+ (when (null bits)
+ (error "unknown size: ~S" (unparse-alien-type field-type)))
+ (when (null alignment)
+ (error "unknown alignment: ~S" (unparse-alien-type field-type)))
+ (setf overall-alignment (max overall-alignment alignment))
+ (ecase (alien-record-type-kind result)
+ (:struct
+ (let ((offset (align-offset total-bits alignment)))
+ (setf (alien-record-field-offset parsed-field) offset)
+ (setf total-bits (+ offset bits))))
+ (:union
+ (setf total-bits (max total-bits bits)))))))
(let ((new (nreverse parsed-fields)))
(setf (alien-record-type-fields result) new))
(setf (alien-record-type-alignment result) overall-alignment)
(setf (alien-record-type-bits result)
(let ((new (nreverse parsed-fields)))
(setf (alien-record-type-fields result) new))
(setf (alien-record-type-alignment result) overall-alignment)
(setf (alien-record-type-bits result)
(t '???))
,(alien-record-type-name type)
,@(unless (member type *record-types-already-unparsed* :test #'eq)
(t '???))
,(alien-record-type-name type)
,@(unless (member type *record-types-already-unparsed* :test #'eq)
- (push type *record-types-already-unparsed*)
- (mapcar (lambda (field)
- `(,(alien-record-field-name field)
- ,(%unparse-alien-type (alien-record-field-type field))
- ,@(if (alien-record-field-bits field)
- (list (alien-record-field-bits field)))))
- (alien-record-type-fields type)))))
+ (push type *record-types-already-unparsed*)
+ (mapcar (lambda (field)
+ `(,(alien-record-field-name field)
+ ,(%unparse-alien-type (alien-record-field-type field))
+ ,@(if (alien-record-field-bits field)
+ (list (alien-record-field-bits field)))))
+ (alien-record-type-fields type)))))
;;; Test the record fields. Keep a hashtable table of already compared
;;; types to detect cycles.
(defun record-fields-match-p (field1 field2)
(and (eq (alien-record-field-name field1)
;;; Test the record fields. Keep a hashtable table of already compared
;;; types to detect cycles.
(defun record-fields-match-p (field1 field2)
(and (eq (alien-record-field-name field1)
(defvar *alien-type-matches* nil
"A hashtable used to detect cycles while comparing record types.")
(define-alien-type-method (record :type=) (type1 type2)
(and (eq (alien-record-type-name type1)
(defvar *alien-type-matches* nil
"A hashtable used to detect cycles while comparing record types.")
(define-alien-type-method (record :type=) (type1 type2)
(and (eq (alien-record-type-name type1)
- (alien-record-type-kind type2))
- (eql (alien-type-bits type1)
- (alien-type-bits type2))
- (eql (alien-type-alignment type1)
- (alien-type-alignment type2))
+ (alien-record-type-kind type2))
+ (eql (alien-type-bits type1)
+ (alien-type-bits type2))
+ (eql (alien-type-alignment type1)
+ (alien-type-alignment type2))
- (setf (gethash type1 *alien-type-matches*) (cons type2 old))
- (every #'record-fields-match-p
- (alien-record-type-fields type1)
- (alien-record-type-fields type2))))
- (if *alien-type-matches*
- (let ((types (gethash type1 *alien-type-matches*)))
- (or (memq type2 types) (match-fields types)))
- (let ((*alien-type-matches* (make-hash-table :test #'eq)))
- (match-fields))))))
+ (setf (gethash type1 *alien-type-matches*) (cons type2 old))
+ (every #'record-fields-match-p
+ (alien-record-type-fields type1)
+ (alien-record-type-fields type2))))
+ (if *alien-type-matches*
+ (let ((types (gethash type1 *alien-type-matches*)))
+ (or (memq type2 types) (match-fields types)))
+ (let ((*alien-type-matches* (make-hash-table :test #'eq)))
+ (match-fields))))))
;;; these structures and LOCAL-ALIEN and friends communicate
;;; information about how that local alien is represented.
(def!struct (local-alien-info
;;; these structures and LOCAL-ALIEN and friends communicate
;;; information about how that local alien is represented.
(def!struct (local-alien-info
- (:make-load-form-fun sb!kernel:just-dump-it-normally)
- (:constructor make-local-alien-info
- (&key type force-to-memory-p
- &aux (force-to-memory-p (or force-to-memory-p
- (alien-array-type-p type)
- (alien-record-type-p type))))))
+ (:make-load-form-fun sb!kernel:just-dump-it-normally)
+ (:constructor make-local-alien-info
+ (&key type force-to-memory-p
+ &aux (force-to-memory-p (or force-to-memory-p
+ (alien-array-type-p type)
+ (alien-record-type-p type))))))
;; the type of the local alien
(type (missing-arg) :type alien-type)
;; Must this local alien be forced into memory? Using the ADDR macro
;; the type of the local alien
(type (missing-arg) :type alien-type)
;; Must this local alien be forced into memory? Using the ADDR macro
- "~:[~;(forced to stack) ~]~S"
- (local-alien-info-force-to-memory-p info)
- (unparse-alien-type (local-alien-info-type info)))))
+ "~:[~;(forced to stack) ~]~S"
+ (local-alien-info-force-to-memory-p info)
+ (unparse-alien-type (local-alien-info-type info)))))
- (cons
- (case (car form)
- (slot
- (cons '%slot-addr (cdr form)))
- (deref
- (cons '%deref-addr (cdr form)))
- (%heap-alien
- (cons '%heap-alien-addr (cdr form)))
- (local-alien
- (let ((info (let ((info-arg (second form)))
- (and (consp info-arg)
- (eq (car info-arg) 'quote)
- (second info-arg)))))
- (unless (local-alien-info-p info)
- (error "Something is wrong, LOCAL-ALIEN-INFO not found: ~S"
- form))
- (setf (local-alien-info-force-to-memory-p info) t))
- (cons '%local-alien-addr (cdr form)))))
- (symbol
- (let ((kind (info :variable :kind form)))
- (when (eq kind :alien)
- `(%heap-alien-addr ',(info :variable :alien-info form))))))
- (error "~S is not a valid L-value." form))))
+ (cons
+ (case (car form)
+ (slot
+ (cons '%slot-addr (cdr form)))
+ (deref
+ (cons '%deref-addr (cdr form)))
+ (%heap-alien
+ (cons '%heap-alien-addr (cdr form)))
+ (local-alien
+ (let ((info (let ((info-arg (second form)))
+ (and (consp info-arg)
+ (eq (car info-arg) 'quote)
+ (second info-arg)))))
+ (unless (local-alien-info-p info)
+ (error "Something is wrong, LOCAL-ALIEN-INFO not found: ~S"
+ form))
+ (setf (local-alien-info-force-to-memory-p info) t))
+ (cons '%local-alien-addr (cdr form)))))
+ (symbol
+ (let ((kind (info :variable :kind form)))
+ (when (eq kind :alien)
+ `(%heap-alien-addr ',(info :variable :alien-info form))))))
+ (error "~S is not a valid L-value." form))))