- ((bit character complex cons float function integer list nil
- null number rational real signed-byte symbol t unsigned-byte)
- (values (typep host-object target-type) t))
- ;; Floating point types are guaranteed to correspond, too, but
- ;; less exactly.
- ((single-float double-float)
- (cond ((floatp host-object)
- (warn-about-possible-float-info-loss)
- (values (typep host-object target-type) t))
- (t
- (values nil t))))
- ;; Some types require translation between the cross-compilation
- ;; host Common Lisp and the target SBCL.
- (sb!xc:class (values (typep host-object 'sb!xc:class) t))
- (fixnum (values (target-fixnump host-object) t))
- ;; Some types are too hard to handle in the positive case, but at
- ;; least we can be confident in a large fraction of the negative
- ;; cases..
- ((base-string simple-base-string simple-string)
- (if (stringp host-object)
- (warn-and-give-up)
- (values nil t)))
- ((character base-char)
- (cond ((typep host-object 'standard-char)
- (values t t))
- ((not (characterp host-object))
- (values nil t))
- (t
- (warn-and-give-up))))
- ((stream instance)
- ;; Neither target CL:STREAM nor target SB!KERNEL:INSTANCE is
- ;; implemented as a STRUCTURE-OBJECT, so they'll fall through the
- ;; tests above. We don't want to assume too much about them here,
- ;; but at least we know enough about them to say that neither T
- ;; nor NIL nor indeed any other symbol in the cross-compilation
- ;; host is one. That knowledge suffices to answer so many of the
- ;; questions that the cross-compiler asks that it's well worth
- ;; special-casing it here.
- (if (symbolp host-object)
- (values nil t)
- (warn-and-give-up)))
- ;; And the Common Lisp type system is complicated, and we don't
- ;; try to implement everything.
- (otherwise (warn-and-give-up)))))))
+ (target-type-is-in
+ '(atom bit character complex cons float function integer keyword
+ list nil null number rational real signed-byte symbol t
+ unsigned-byte))
+ (values (typep host-object target-type) t))
+ (;; Floating point types are guaranteed to correspond,
+ ;; too, but less exactly.
+ (target-type-is-in
+ '(single-float double-float))
+ (cond ((floatp host-object)
+ (warn-about-possible-float-info-loss)
+ (values (typep host-object target-type) t))
+ (t
+ (values nil t))))
+ (;; Complexes suffer the same kind of problems as arrays
+ (and (not (unknown-type-p (values-specifier-type target-type)))
+ (sb!xc:subtypep target-type 'cl:complex))
+ (if (complexp host-object)
+ (warn-and-give-up) ; general-case complexes being way too hard
+ (values nil t))) ; but "obviously not a complex" being easy
+ ;; Some types require translation between the cross-compilation
+ ;; host Common Lisp and the target SBCL.
+ ((target-type-is-in '(classoid))
+ (values (typep host-object 'classoid) t))
+ ((target-type-is-in '(fixnum))
+ (values (fixnump host-object) t))
+ ;; Some types are too hard to handle in the positive
+ ;; case, but at least we can be confident in a large
+ ;; fraction of the negative cases..
+ ((target-type-is-in
+ '(base-string simple-base-string simple-string))
+ (if (stringp host-object)
+ (warn-and-give-up)
+ (values nil t)))
+ ((target-type-is-in '(character base-char))
+ (cond ((typep host-object 'standard-char)
+ (values t t))
+ ((not (characterp host-object))
+ (values nil t))
+ (t
+ (warn-and-give-up))))
+ ((target-type-is-in '(stream instance))
+ ;; Neither target CL:STREAM nor target SB!KERNEL:INSTANCE
+ ;; is implemented as a STRUCTURE-OBJECT, so they'll fall
+ ;; through the tests above. We don't want to assume too
+ ;; much about them here, but at least we know enough
+ ;; about them to say that neither T nor NIL nor indeed
+ ;; any other symbol in the cross-compilation host is one.
+ ;; That knowledge suffices to answer so many of the
+ ;; questions that the cross-compiler asks that it's well
+ ;; worth special-casing it here.
+ (if (symbolp host-object)
+ (values nil t)
+ (warn-and-give-up)))
+ ;; various hacks for composite types..
+ ((consp target-type)
+ (let ((first (first target-type))
+ (rest (rest target-type)))
+ (case first
+ ;; Many complex types are guaranteed to correspond exactly
+ ;; between any host ANSI Common Lisp and the target SBCL.
+ ((integer member mod rational real signed-byte unsigned-byte)
+ (values (typep host-object target-type) t))
+ ;; Floating point types are guaranteed to correspond,
+ ;; too, but less exactly.
+ ((single-float double-float)
+ (cond ((floatp host-object)
+ (warn-about-possible-float-info-loss)
+ (values (typep host-object target-type) t))
+ (t
+ (values nil t))))
+ ;; Some complex types have translations that are less
+ ;; trivial.
+ (and (every/type #'cross-typep host-object rest))
+ (or (any/type #'cross-typep host-object rest))
+ ;; If we want to work with the KEYWORD type, we need
+ ;; to grok (SATISFIES KEYWORDP).
+ (satisfies
+ (destructuring-bind (predicate-name) rest
+ (if (and (in-cl-package-p predicate-name)
+ (fboundp predicate-name))
+ ;; Many predicates like KEYWORDP, ODDP, PACKAGEP,
+ ;; and NULL correspond between host and target.
+ ;; But we still need to handle errors, because
+ ;; the code which calls us may not understand
+ ;; that a type is unreachable. (E.g. when compiling
+ ;; (AND STRING (SATISFIES ARRAY-HAS-FILL-POINTER-P))
+ ;; CTYPEP may be called on the SATISFIES expression
+ ;; even for non-STRINGs.)
+ (multiple-value-bind (result error?)
+ (ignore-errors (funcall predicate-name
+ host-object))
+ (if error?
+ (values nil nil)
+ (values result t)))
+ ;; For symbols not in the CL package, it's not
+ ;; in general clear how things correspond
+ ;; between host and target, so we punt.
+ (warn-and-give-up))))
+ ;; Some complex types are too hard to handle in the
+ ;; positive case, but at least we can be confident in
+ ;; a large fraction of the negative cases..
+ ((base-string simple-base-string simple-string)
+ (if (stringp host-object)
+ (warn-and-give-up)
+ (values nil t)))
+ ((vector simple-vector)
+ (if (vectorp host-object)
+ (warn-and-give-up)
+ (values nil t)))
+ ((array simple-array)
+ (if (arrayp host-object)
+ (warn-and-give-up)
+ (values nil t)))
+ (function
+ (if (functionp host-object)
+ (warn-and-give-up)
+ (values nil t)))
+ ;; And the Common Lisp type system is complicated,
+ ;; and we don't try to implement everything.
+ (otherwise (warn-and-give-up)))))
+ ;; And the Common Lisp type system is complicated, and
+ ;; we don't try to implement everything.
+ (t
+ (warn-and-give-up))))))