(warn-about-possible-float-info-loss ()
(warn-possible-cross-type-float-info-loss
`(cross-typep ,host-object ,target-type))))
- (cond (;; Handle various SBCL-specific types which can't exist on the
- ;; ANSI cross-compilation host. KLUDGE: This code will need to be
- ;; tweaked by hand if the names of these types ever change, ugh!
+ (cond (;; Handle various SBCL-specific types which can't exist on
+ ;; the ANSI cross-compilation host. KLUDGE: This code will
+ ;; need to be tweaked by hand if the names of these types
+ ;; ever change, ugh!
(if (consp target-type)
(member (car target-type)
'(sb!alien:alien))
funcallable-instance
sb!alien-internals:alien-value)))
(values nil t))
- (;; special case when TARGET-TYPE isn't a type spec, but instead
- ;; a CLASS object
+ (;; special case when TARGET-TYPE isn't a type spec, but
+ ;; instead a CLASS object
(typep target-type 'sb!xc::structure-class)
- ;; SBCL-specific types which have an analogue specially created
- ;; on the host system
+ ;; SBCL-specific types which have an analogue specially
+ ;; created on the host system
(if (sb!xc:subtypep (sb!xc:class-name target-type)
'sb!kernel::structure!object)
(values (typep host-object (sb!xc:class-name target-type)) t)
;; 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.
+ ;; 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
- ;; Note: This could be implemented as a real test, just the way
- ;; that OR is; I just haven't bothered. -- WHN 19990706
- (warn-and-give-up))
- (or (let ((opinion nil)
- (certain-p t))
- (dolist (i rest)
- (multiple-value-bind (sub-opinion sub-certain-p)
- (cross-typep host-object i)
- (cond (sub-opinion (setf opinion t
- certain-p t)
- (return))
- ((not sub-certain-p) (setf certain-p nil))))
- (if certain-p
- (values opinion t)
- (warn-and-give-up)))))
+ ;; 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))
;; 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..
(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.
+ ;; And the Common Lisp type system is complicated, and
+ ;; we don't try to implement everything.
(otherwise (warn-and-give-up)))))
(t
(case target-type
;; between any host ANSI Common Lisp and the target
;; Common Lisp. (Some array types are too, but they
;; were picked off earlier.)
- ((bit character complex cons float function integer list nil
- null number rational real signed-byte symbol t unsigned-byte)
+ ((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.
+ ;; 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)
;; host Common Lisp and the target SBCL.
(sb!xc:class (values (typep host-object 'sb!xc:class) t))
(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..
+ ;; 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)
(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
+ ;; 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.
+ ;; And the Common Lisp type system is complicated, and we
+ ;; don't try to implement everything.
(otherwise (warn-and-give-up)))))))
;;; An incomplete TYPEP which runs at cross-compile time to tell whether OBJECT
(lambda (x y)
(funcall fun y x)))
\f
+;;;; utilities for two-VALUES predicates
+
+;;; sort of like ANY and EVERY, except:
+;;; * We handle two-VALUES predicate functions like SUBTYPEP. (And
+;;; if the result is uncertain, then we return (VALUES NIL NIL),
+;;; just like SUBTYPEP.)
+;;; * THING is just an atom, and we apply OP (an arity-2 function)
+;;; successively to THING and each element of LIST.
+(defun any/type (op thing list)
+ (declare (type function op))
+ (let ((certain? t))
+ (dolist (i list (values nil certain?))
+ (multiple-value-bind (sub-value sub-certain?) (funcall op thing i)
+ (if sub-certain?
+ (when sub-value (return (values t t)))
+ (setf certain? nil))))))
+(defun every/type (op thing list)
+ (declare (type function op))
+ (let ((certain? t))
+ (dolist (i list (if certain? (values t t) (values nil nil)))
+ (multiple-value-bind (sub-value sub-certain?) (funcall op thing i)
+ (if sub-certain?
+ (unless sub-value (return (values nil t)))
+ (setf certain? nil))))))
+\f
;;;; DEFPRINTER
;;; These functions are called by the expansion of the DEFPRINTER
(declare (type ctype type))
`(specifier-type ',(type-specifier type)))
\f
-;;;; utilities
-
-;;; sort of like ANY and EVERY, except:
-;;; * We handle two-VALUES predicate functions like SUBTYPEP. (And
-;;; if the result is uncertain, then we return (VALUES NIL NIL),
-;;; just like SUBTYPEP.)
-;;; * THING is just an atom, and we apply OP (an arity-2 function)
-;;; successively to THING and each element of LIST.
-(defun any/type (op thing list)
- (declare (type function op))
- (let ((certain? t))
- (dolist (i list (values nil certain?))
- (multiple-value-bind (sub-value sub-certain?) (funcall op thing i)
- (if sub-certain?
- (when sub-value (return (values t t)))
- (setf certain? nil))))))
-(defun every/type (op thing list)
- (declare (type function op))
- (let ((certain? t))
- (dolist (i list (if certain? (values t t) (values nil nil)))
- (multiple-value-bind (sub-value sub-certain?) (funcall op thing i)
- (if sub-certain?
- (unless sub-value (return (values nil t)))
- (setf certain? nil))))))
+;;;; miscellany
;;; Look for nice relationships for types that have nice relationships
;;; only when one is a hierarchical subtype of the other.
(assert (null (type-intersection2 (specifier-type 'symbol)
(specifier-type '(satisfies foo)))))
(assert (intersection-type-p (specifier-type '(and symbol (satisfies foo)))))
-;; FIXME: As of sbcl-0.6.11.17, the system doesn't know how to do the
-;; type simplifications which would let these tests work. (bug 88)
-#|
(let* ((type1 (specifier-type '(member :x86)))
(type2 (specifier-type '(or keyword null)))
(isect (type-intersection type1 type2)))
+ (assert (type= isect type1))
(assert (type= isect (type-intersection type2 type1)))
+ (assert (type= isect (type-intersection type2 type1 type2)))
+ (assert (type= isect (type-intersection type1 type1 type2 type1)))
+ (assert (type= isect (type-intersection type1 type2 type1 type2))))
+;;; FIXME: As of sbcl-0.6.11.19, the system doesn't know how to do the
+;;; type simplifications which would let these tests work. (bug 89)
+#|
+(let* ((type1 (specifier-type 'keyword))
+ (type2 (specifier-type '(or keyword null)))
+ (isect (type-intersection type1 type2)))
(assert (type= isect type1))
+ (assert (type= isect (type-intersection type2 type1)))
(assert (type= isect (type-intersection type2 type1 type2)))
(assert (type= isect (type-intersection type1 type1 type2 type1)))
(assert (type= isect (type-intersection type1 type2 type1 type2))))