(in-package "SB!KERNEL")
-(file-comment
- "$Header$")
-
(!begin-collecting-cold-init-forms)
;;; Define the translation from a type-specifier to a type structure for
;;; some particular type. Syntax is identical to DEFTYPE.
-(defmacro def-type-translator (name arglist &body body)
+(defmacro !def-type-translator (name arglist &body body)
(check-type name symbol)
;; FIXME: Now that the T%CL hack is ancient history and we just use CL
;; instead, we can probably return to using PARSE-DEFMACRO here.
;; package!)
(multiple-value-bind (whole wholeless-arglist)
(if (eq '&whole (car arglist))
- (values (cadr arglist) (cddr arglist))
- (values (gensym) arglist))
+ (values (cadr arglist) (cddr arglist))
+ (values (gensym) arglist))
(multiple-value-bind (forms decls) (parse-body body nil)
`(progn
(!cold-init-forms
;;; DEFVARs for these come later, after we have enough stuff defined.
(declaim (special *wild-type* *universal-type* *empty-type*))
\f
-;;; The XXX-Type structures include the CTYPE structure for some slots that
-;;; apply to all types.
+;;; the base class for the internal representation of types
(def!struct (ctype (:conc-name type-)
(:constructor nil)
(:make-load-form-fun make-type-load-form)
\f
;;;; utilities
-;;; Like ANY and EVERY, except that we handle two-arg uncertain predicates.
-;;; If the result is uncertain, then we return Default from the block PUNT.
-;;; If LIST-FIRST is true, then the list element is the first arg, otherwise
-;;; the second.
-(defmacro any-type-op (op thing list &key (default '(values nil nil))
- list-first)
- (let ((n-this (gensym))
- (n-thing (gensym))
- (n-val (gensym))
- (n-win (gensym))
- (n-uncertain (gensym)))
- `(let ((,n-thing ,thing)
- (,n-uncertain nil))
- (dolist (,n-this ,list
- (if ,n-uncertain
- (return-from PUNT ,default)
- nil))
- (multiple-value-bind (,n-val ,n-win)
- ,(if list-first
- `(,op ,n-this ,n-thing)
- `(,op ,n-thing ,n-this))
- (unless ,n-win (setq ,n-uncertain t))
- (when ,n-val (return t)))))))
-(defmacro every-type-op (op thing list &key (default '(values nil nil))
- list-first)
- (let ((n-this (gensym))
- (n-thing (gensym))
- (n-val (gensym))
- (n-win (gensym)))
- `(let ((,n-thing ,thing))
- (dolist (,n-this ,list t)
- (multiple-value-bind (,n-val ,n-win)
- ,(if list-first
- `(,op ,n-this ,n-thing)
- `(,op ,n-thing ,n-this))
- (unless ,n-win (return-from PUNT ,default))
- (unless ,n-val (return nil)))))))
+;;; 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).)
+;;; * 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)
+ (unless sub-certain? (setf certain? nil))
+ (when sub-value (return (values t t)))))))
+(defun every/type (op thing list)
+ (declare (type function op))
+ (dolist (i list (values t t))
+ (multiple-value-bind (sub-value sub-certain?)
+ (funcall op thing i)
+ (unless sub-certain? (return (values nil nil)))
+ (unless sub-value (return (values nil t))))))
+
+;;; Return a function like FUN, but expecting its (two) arguments in
+;;; the opposite order that FUN does.
+;;;
+;;; (This looks like a sort of general utility, but currently it's
+;;; used only in the implementation of the type system, so it's
+;;; internal to SB-KERNEL. -- WHN 2001-02-13)
+(declaim (inline swapped-args-fun))
+(defun swapped-args-fun (fun)
+ (declare (type function fun))
+ (lambda (x y)
+ (funcall fun y x)))
;;; Compute the intersection for types that intersect only when one is a
;;; hierarchical subtype of the other.