;; 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-TYPE-METHOD. If LIST-FIRST is true, then the
-;;; list element is the first arg, otherwise the second.
+;;; 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.
;;;
-;;; FIXME: The way that we return from PUNT-TYPE-METHOD rather ruins
-;;; the analogy with SOME and EVERY, and completely surprised me (WHN)
-;;; when I was trying to maintain code which uses these macros. I
-;;; think it would be a good idea to redo these so that they really
-;;; are analogous to EVERY and SOME. And then, while we're at it, we
-;;; could also make them functions (perhaps inline) instead of macros.
-(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-type-method ,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-type-method ,default))
- (unless ,n-val (return nil)))))))
+;;; (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.