- (ltype (specifier-type 'list))
- (mtype (find-if #'member-type-p types)))
- (cond ((and mtype (csubtypep ltype type))
- (let ((members (member-type-members mtype)))
- (once-only ((n-obj object))
- `(if (listp ,n-obj)
- t
- (typep ,n-obj
- '(or ,@(mapcar #'type-specifier
- (remove (specifier-type 'cons)
- (remove mtype types)))
- (member ,@(remove nil members))))))))
- (t
- (once-only ((n-obj object))
- `(or ,@(mapcar #'(lambda (x)
- `(typep ,n-obj ',(type-specifier x)))
- types)))))))
+ (type-cons (specifier-type 'cons))
+ (mtype (find-if #'member-type-p types))
+ (members (when mtype (member-type-members mtype))))
+ (if (and mtype
+ (memq nil members)
+ (memq type-cons types))
+ (once-only ((n-obj object))
+ `(or (listp ,n-obj)
+ (typep ,n-obj
+ '(or ,@(mapcar #'type-specifier
+ (remove type-cons
+ (remove mtype types)))
+ (member ,@(remove nil members))))))
+ (once-only ((n-obj object))
+ `(or ,@(mapcar (lambda (x)
+ `(typep ,n-obj ',(type-specifier x)))
+ types))))))
+
+;;; Do source transformation for TYPEP of a known intersection type.
+(defun source-transform-intersection-typep (object type)
+ (once-only ((n-obj object))
+ `(and ,@(mapcar (lambda (x)
+ `(typep ,n-obj ',(type-specifier x)))
+ (intersection-type-types type)))))
+
+;;; If necessary recurse to check the cons type.
+(defun source-transform-cons-typep (object type)
+ (let* ((car-type (cons-type-car-type type))
+ (cdr-type (cons-type-cdr-type type)))
+ (let ((car-test-p (not (type= car-type *universal-type*)))
+ (cdr-test-p (not (type= cdr-type *universal-type*))))
+ (if (and (not car-test-p) (not cdr-test-p))
+ `(consp ,object)
+ (once-only ((n-obj object))
+ `(and (consp ,n-obj)
+ ,@(if car-test-p
+ `((typep (car ,n-obj)
+ ',(type-specifier car-type))))
+ ,@(if cdr-test-p
+ `((typep (cdr ,n-obj)
+ ',(type-specifier cdr-type))))))))))
+
+(defun source-transform-character-set-typep (object type)
+ (let ((pairs (character-set-type-pairs type)))
+ (if (and (= (length pairs) 1)
+ (= (caar pairs) 0)
+ (= (cdar pairs) (1- sb!xc:char-code-limit)))
+ `(characterp ,object)
+ (once-only ((n-obj object))
+ (let ((n-code (gensym "CODE")))
+ `(and (characterp ,n-obj)
+ (let ((,n-code (sb!xc:char-code ,n-obj)))
+ (or
+ ,@(loop for pair in pairs
+ collect
+ `(<= ,(car pair) ,n-code ,(cdr pair)))))))))))