X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fearly-type.lisp;h=16404c784033a9fea27cea935da95667b7315b80;hb=2034cb134af58c5998f4e305673af6e2c75bc179;hp=6679a42b7e2e59f9a6d9ceed354c30e89a1d6a91;hpb=dc78da1842ccba35e49ca8ca91fd0ab88b1a08b3;p=sbcl.git diff --git a/src/code/early-type.lisp b/src/code/early-type.lisp index 6679a42..16404c7 100644 --- a/src/code/early-type.lisp +++ b/src/code/early-type.lisp @@ -11,10 +11,6 @@ (!begin-collecting-cold-init-forms) -;;; Has the type system been properly initialized? (I.e. is it OK to -;;; use it?) -(defvar *type-system-initialized* #+sb-xc-host nil) ; (set in cold load) - ;;;; representations of types ;;; A HAIRY-TYPE represents anything too weird to be described @@ -334,6 +330,34 @@ :high high :enumerable enumerable)) +(defstruct (character-set-type + (:include ctype + (class-info (type-class-or-lose 'character-set))) + (:constructor %make-character-set-type) + (:copier nil)) + (pairs (missing-arg) :type list :read-only t)) +(defun make-character-set-type (&key pairs) + (aver (equal (mapcar #'car pairs) + (sort (mapcar #'car pairs) #'<))) + (let ((pairs (let (result) + (do ((pairs pairs (cdr pairs))) + ((null pairs) (nreverse result)) + (destructuring-bind (low . high) (car pairs) + (loop for (low1 . high1) in (cdr pairs) + if (<= low1 (1+ high)) + do (progn (setf high (max high high1)) + (setf pairs (cdr pairs))) + else do (return nil)) + (cond + ((>= low sb!xc:char-code-limit)) + ((< high 0)) + (t (push (cons (max 0 low) + (min high (1- sb!xc:char-code-limit))) + result)))))))) + (if (null pairs) + *empty-type* + (%make-character-set-type :pairs pairs)))) + ;;; An ARRAY-TYPE is used to represent any array type, including ;;; things such as SIMPLE-BASE-STRING. (defstruct (array-type (:include ctype @@ -460,6 +484,24 @@ (eq cdr-type *empty-type*)) *empty-type* (%make-cons-type car-type cdr-type))) + +(defun cons-type-length-info (type) + (declare (type cons-type type)) + (do ((min 1 (1+ min)) + (cdr (cons-type-cdr-type type) (cons-type-cdr-type cdr))) + ((not (cons-type-p cdr)) + (cond + ((csubtypep cdr (specifier-type 'null)) + (values min t)) + ((csubtypep *universal-type* cdr) + (values min nil)) + ((type/= (type-intersection (specifier-type 'cons) cdr) *empty-type*) + (values min nil)) + ((type/= (type-intersection (specifier-type 'null) cdr) *empty-type*) + (values min t)) + (t (values min :maybe)))) + ())) + ;;;; type utilities @@ -499,8 +541,9 @@ (fun (info :type :translator (car lspec)))) (cond (fun (funcall fun lspec)) - ((or (and (consp spec) (symbolp (car spec))) - (symbolp spec)) + ((or (and (consp spec) (symbolp (car spec)) + (not (info :type :builtin (car spec)))) + (and (symbolp spec) (not (info :type :builtin spec)))) (when (and *type-system-initialized* (not (eq (info :type :kind spec) :forthcoming-defclass-type))) @@ -534,7 +577,7 @@ (let ((def (cond ((symbolp form) (info :type :expander form)) ((and (consp form) (symbolp (car form))) - (info :type :expander (car form))) + (info :type :expander (car form))) (t nil)))) (if def (type-expand (funcall def (if (consp form) form (list form))))