Changeset 318
- Timestamp:
- Jan 17, 2004, 7:50:44 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-typesys.lisp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-typesys.lisp
r297 r318 137 137 arglist)) 138 138 139 (eval-when (:compile-toplevel)140 (warn "Fix EVAL-WHEN in EXPAND-TYPE-MACRO"))141 139 142 140 (defun expand-type-macro (definer name arglist body env) … … 144 142 (multiple-value-bind (lambda doc) 145 143 (parse-macro-internal name arglist body env '*) 146 `(eval-when ( #|:compile-toplevel|#:load-toplevel :execute)144 `(eval-when (:compile-toplevel :load-toplevel :execute) 147 145 (,definer ',name 148 146 (nfunction ,name ,lambda) … … 1930 1928 (deftype float-format () `(member ,@float-formats)) 1931 1929 1930 (defun type-bound-number (x) 1931 (if (consp x) 1932 (destructuring-bind (result) x result) 1933 x)) 1934 1932 1935 (defun make-numeric-ctype (&key class 1933 1936 format … … 1937 1940 enumerable 1938 1941 predicate) 1939 (let ((ctype (%istruct 'numeric-ctype 1940 (type-class-or-lose 'number) 1941 enumerable 1942 class 1943 format 1944 complexp 1945 low 1946 high 1947 predicate))) 1948 ctype)) 1942 ;; if interval is empty 1943 (if (and low 1944 high 1945 (if (or (consp low) (consp high)) ; if either bound is exclusive 1946 (>= (type-bound-number low) (type-bound-number high)) 1947 (> low high))) 1948 *empty-type* 1949 (multiple-value-bind (canonical-low canonical-high) 1950 (case class 1951 (integer 1952 ;; INTEGER types always have their LOW and HIGH bounds 1953 ;; represented as inclusive, not exclusive values. 1954 (values (if (consp low) 1955 (1+ (type-bound-number low)) 1956 low) 1957 (if (consp high) 1958 (1- (type-bound-number high)) 1959 high))) 1960 (t 1961 ;; no canonicalization necessary 1962 (values low high))) 1963 (when (and (eq class 'rational) 1964 (integerp canonical-low) 1965 (integerp canonical-high) 1966 (= canonical-low canonical-high)) 1967 (setf class 'integer)) 1968 (%istruct 'numeric-ctype 1969 (type-class-or-lose 'number) 1970 enumerable 1971 class 1972 format 1973 complexp 1974 canonical-low 1975 canonical-high 1976 predicate)))) 1949 1977 1950 1978 … … 1976 2004 1977 2005 (define-type-method (number :unparse) (type) 1978 (let* ((complexp (numeric-ctype-complexp type))1979 (low (numeric-ctype-low type))1980 (high (numeric-ctype-high type))1981 (base (case (numeric-ctype-class type)1982 (integer 'integer)1983 (rational 'rational)1984 (float (or (numeric-ctype-format type) 'float))1985 (t 'real))))2006 (let* ((complexp (numeric-ctype-complexp type)) 2007 (low (numeric-ctype-low type)) 2008 (high (numeric-ctype-high type)) 2009 (base (case (numeric-ctype-class type) 2010 (integer 'integer) 2011 (rational 'rational) 2012 (float (or (numeric-ctype-format type) 'float)) 2013 (t 'real)))) 1986 2014 (let ((base+bounds 1987 (cond ((and (eq base 'integer) high low)1988 (let ((high-count (logcount high))1989 (high-length (integer-length high)))1990 (cond ((= low 0)1991 (cond ((= high 0) '(integer 0 0))1992 ((= high 1) 'bit)1993 ((and (= high-count high-length)1994 (plusp high-length))1995 `(unsigned-byte ,high-length))1996 (t1997 `(mod ,(1+ high)))))1998 ((and (= low most-negative-fixnum)1999 (= high most-positive-fixnum))2000 'fixnum)2001 ((and (= low (lognot high))2002 (= high-count high-length)2003 (> high-count 0))2004 `(signed-byte ,(1+ high-length)))2005 (t2006 `(integer ,low ,high)))))2007 (high `(,base ,(or low '*) ,high))2008 (low2009 (if (and (eq base 'integer) (= low 0))2010 'unsigned-byte2011 `(,base ,low)))2012 (t base))))2015 (cond ((and (eq base 'integer) high low) 2016 (let ((high-count (logcount high)) 2017 (high-length (integer-length high))) 2018 (cond ((= low 0) 2019 (cond ((= high 0) '(integer 0 0)) 2020 ((= high 1) 'bit) 2021 ((and (= high-count high-length) 2022 (plusp high-length)) 2023 `(unsigned-byte ,high-length)) 2024 (t 2025 `(mod ,(1+ high))))) 2026 ((and (= low most-negative-fixnum) 2027 (= high most-positive-fixnum)) 2028 'fixnum) 2029 ((and (= low (lognot high)) 2030 (= high-count high-length) 2031 (> high-count 0)) 2032 `(signed-byte ,(1+ high-length))) 2033 (t 2034 `(integer ,low ,high))))) 2035 (high `(,base ,(or low '*) ,high)) 2036 (low 2037 (if (and (eq base 'integer) (= low 0)) 2038 'unsigned-byte 2039 `(,base ,low))) 2040 (t base)))) 2013 2041 (ecase complexp 2014 (:real2015 base+bounds)2016 (:complex2017 (if (eq base+bounds 'real)2042 (:real 2043 base+bounds) 2044 (:complex 2045 (if (eq base+bounds 'real) 2018 2046 'complex 2019 2047 `(complex ,base+bounds))) 2020 ((nil)2021 (assert (eq base+bounds 'real))2022 'number)))))2048 ((nil) 2049 (assert (eq base+bounds 'real)) 2050 'number))))) 2023 2051 2024 2052 ;;; Numeric-Bound-Test -- Internal … … 2076 2104 (defmacro numeric-bound-max (x y closed open max-p) 2077 2105 (once-only ((n-x x) 2078 (n-y y)) 2079 `(cond ((not ,n-x) ,(if max-p nil n-y)) 2080 ((not ,n-y) ,(if max-p nil n-x)) 2081 ((consp ,n-x) 2082 (if (consp ,n-y) 2083 (if (,closed (car ,n-x) (car ,n-y)) ,n-x ,n-y) 2084 (if (,open (car ,n-x) ,n-y) ,n-x ,n-y))) 2085 (t 2086 (if (consp ,n-y) 2087 (if (,open (car ,n-y) ,n-x) ,n-y ,n-x) 2088 (if (,closed ,n-y ,n-x) ,n-y ,n-x)))))) 2106 (n-y y)) 2107 `(cond 2108 ((not ,n-x) ,(if max-p nil n-y)) 2109 ((not ,n-y) ,(if max-p nil n-x)) 2110 ((consp ,n-x) 2111 (if (consp ,n-y) 2112 (if (,closed (car ,n-x) (car ,n-y)) ,n-x ,n-y) 2113 (if (,open (car ,n-x) ,n-y) ,n-x ,n-y))) 2114 (t 2115 (if (consp ,n-y) 2116 (if (,open (car ,n-y) ,n-x) ,n-y ,n-x) 2117 (if (,closed ,n-y ,n-x) ,n-y ,n-x)))))) 2089 2118 2090 2119 … … 2132 2161 (defun numeric-types-adjacent (low high) 2133 2162 (let ((low-bound (numeric-ctype-high low)) 2134 (high-bound (numeric-ctype-low high)))2163 (high-bound (numeric-ctype-low high))) 2135 2164 (cond ((not (and low-bound high-bound)) nil) 2136 2165 ((consp low-bound) … … 2144 2173 nil)))) 2145 2174 2146 ;;; NUMBER :SIMPLE-UNION method -- Internal 2147 ;;; 2148 ;;; Return the a numeric type that is a supertype for both type1 and type2. 2175 ;;; 2176 ;;; Return a numeric type that is a supertype for both type1 and type2. 2149 2177 ;;; 2150 ;;; ### Note: we give up early, so keep from dropping lots of information on2151 ;;; the floor by returning overly general types.2152 ;;;2153 2178 (define-type-method (number :simple-union) (type1 type2) 2154 2179 (declare (type numeric-ctype type1 type2)) 2155 2180 (cond ((csubtypep type1 type2) type2) 2156 ((csubtypep type2 type1) type1)2157 (t2158 (let ((class1 (numeric-ctype-class type1))2159 (format1 (numeric-ctype-format type1))2160 (complexp1 (numeric-ctype-complexp type1))2161 (class2 (numeric-ctype-class type2))2162 (format2 (numeric-ctype-format type2))2163 (complexp2 (numeric-ctype-complexp type2)))2164 (when (and (eq class1 class2)2165 (eq format1 format2)2166 (eq complexp1 complexp2)2167 (or (numeric-types-intersect type1 type2)2168 (numeric-types-adjacent type1 type2)2169 (numeric-types-adjacent type2 type1)))2181 ((csubtypep type2 type1) type1) 2182 (t 2183 (let ((class1 (numeric-ctype-class type1)) 2184 (format1 (numeric-ctype-format type1)) 2185 (complexp1 (numeric-ctype-complexp type1)) 2186 (class2 (numeric-ctype-class type2)) 2187 (format2 (numeric-ctype-format type2)) 2188 (complexp2 (numeric-ctype-complexp type2))) 2189 (when (and (eq class1 class2) 2190 (eq format1 format2) 2191 (eq complexp1 complexp2) 2192 (or (numeric-types-intersect type1 type2) 2193 (numeric-types-adjacent type1 type2) 2194 (numeric-types-adjacent type2 type1))) 2170 2195 (make-numeric-ctype 2171 2196 :class class1 … … 2173 2198 :complexp complexp1 2174 2199 :low (numeric-bound-max (numeric-ctype-low type1) 2175 (numeric-ctype-low type2)2176 < <=t)2200 (numeric-ctype-low type2) 2201 <= < t) 2177 2202 :high (numeric-bound-max (numeric-ctype-high type1) 2178 (numeric-ctype-high type2)2179 > >=t)))))))2203 (numeric-ctype-high type2) 2204 >= > t))))))) 2180 2205 2181 2206 (setf (info-type-kind 'number) :primitive … … 2534 2559 (bit 'bit-vector) 2535 2560 (base-char 'base-string) 2536 #|(character 'string)|#2537 2561 (* 'vector) 2538 2562 (t `(vector ,eltype))) … … 2540 2564 (bit `(bit-vector ,(car dims))) 2541 2565 (base-char `(base-string ,(car dims))) 2542 (character `(string ,(car dims)))2543 2566 (t `(vector ,eltype ,(car dims))))) 2544 2567 (if (eq (car dims) '*) … … 2546 2569 (bit 'simple-bit-vector) 2547 2570 (base-char 'simple-base-string) 2548 (character 'simple-base-string)2549 2571 ((t) 'simple-vector) 2550 2572 (t `(simple-array ,eltype (*)))) … … 2552 2574 (bit `(simple-bit-vector ,(car dims))) 2553 2575 (base-char `(simple-base-string ,(car dims))) 2554 (character `(simple-base-string ,(car dims)))2555 2576 ((t) `(simple-vector ,(car dims))) 2556 2577 (t `(simple-array ,eltype ,dims)))))) … … 2641 2662 (mapcar #'(lambda (x y) (if (eq x '*) y x)) 2642 2663 dims1 dims2))) 2643 :complexp (if (eq complexp1 '*) complexp2 complexp1)2664 :complexp (if (eq complexp1 :maybe) complexp2 complexp1) 2644 2665 :element-type (if (eq eltype1 *wild-type*) eltype2 eltype1)))) 2645 2666 *empty-type*)) … … 2696 2717 (dolist (stype-name specialized-array-element-types 2697 2718 (specifier-type 't)) 2698 (let ((stype (specifier-type stype-name)))2699 (when (csubtypep eltype stype)2700 (return stype))))))2719 (let ((stype (specifier-type stype-name))) 2720 (when (csubtypep eltype stype) 2721 (return stype)))))) 2701 2722 2702 2723 type)) … … 2710 2731 ;;; and intersection are well defined. 2711 2732 2712 (defun make-member-ctype (&keymembers)2733 (defun %make-member-ctype (members) 2713 2734 (%istruct 'member-ctype 2714 2735 (type-class-or-lose 'member) 2715 2736 t 2716 2737 members)) 2738 2739 (defun make-member-ctype (&key members) 2740 (let* ((singlep (subsetp '(-0.0f0 0.0f0) members)) 2741 (doublep (subsetp '(-0.0d0 0.0d0) members)) 2742 (union-types 2743 (if singlep 2744 (if doublep 2745 (list *ctype-of-single-float-0* *ctype-of-double-float-0*) 2746 (list *ctype-of-single-float-0*)) 2747 (if doublep 2748 (list *ctype-of-single-float-0*))))) 2749 (if union-types 2750 (progn 2751 (if singlep 2752 (setq members (set-difference '(-0.0f0 0.0f0) members))) 2753 (if doublep 2754 (setq members (set-difference '(-0.d00 0.0d0) members))) 2755 (make-union-ctype (if (null members) 2756 union-types 2757 (cons (%make-member-ctype members) union-types)))) 2758 (%make-member-ctype members)))) 2759 2717 2760 2718 2761 (defun member-ctype-p (x) (istruct-typep x 'member-ctype)) … … 3249 3292 ;;; -could- try to find all such classes, but 3250 3293 ;;; punt instead. 3251 (t (if (and (typep class1 'standard-class) 3252 (typep class2 'standard-class)) 3253 (find-class-intersection class1 class2) 3294 (t (or (find-class-intersection class1 class2) 3254 3295 *empty-type*))) 3255 3296 nil))) … … 3417 3458 (float 3418 3459 (ecase (numeric-ctype-format type) 3419 (short-float (typep num 'short-float))3420 3460 (single-float (typep num 'single-float)) 3421 3461 (double-float (typep num 'double-float)) 3422 (long-float (typep num 'long-float))3423 3462 ((nil) (floatp num)))) 3424 3463 ((nil) t))) … … 3542 3581 (rational 'rational) 3543 3582 (float 'float)) 3544 :format (and (floatp num) (float-format-name num)) 3583 :format (and (floatp num) 3584 (if (typep num 'double-float) 3585 'double-float 3586 'single-float)) 3545 3587 :complexp complexp 3546 3588 :low low … … 3562 3604 (%class.ctype (class-of x))))) 3563 3605 3606 (defvar *ctype-of-double-float-0* (ctype-of 0.0d0)) 3607 (defvar *ctype-of-single-float-0* (ctype-of 0.0f0)) 3608 3609 3564 3610 3565 3611 … … 3604 3650 3605 3651 (deftype string (&optional size) 3606 `( base-string ,size))3652 `(array character (,size))) 3607 3653 3608 3654 (deftype simple-string (&optional size) 3609 `(simple- base-string ,size))3655 `(simple-array character (,size))) 3610 3656 3611 3657 (deftype extended-string (&optional size) … … 3703 3749 `(simple-array single-float (,size))) 3704 3750 3751 (deftype short-float (&optional low high) 3752 `(single-float ,low ,high)) 3753 3754 (deftype long-float (&optional low high) 3755 `(double-float ,low ,high)) 3756 3757 ;;; As empty a type as you're likely to find ... 3758 (deftype extended-char () 3759 nil) 3705 3760 ) 3761 3706 3762 3707 3763 (let* ((builtin-translations … … 3725 3781 (double-float . double-float) 3726 3782 (long-float . double-float) 3727 (s hort-float . short-float)3728 (single-float . short-float)3729 (rational . rational) ; why not (or ratio integer)? 3730 (ratio . (and rational (not integer))) ; why not ratio3783 (single-float . single-float) 3784 (short-float . single-float) 3785 3786 (rational . rational) 3731 3787 (integer . integer) 3788 (ratio . (and rational (not integer))) 3732 3789 (fixnum . (integer ,most-negative-fixnum ,most-positive-fixnum)) 3733 3790 (bignum . (or (integer * (,most-negative-fixnum)) … … 3739 3796 (info-type-builtin (car spec)) (specifier-type (cdr spec))))) 3740 3797 3798 3799 3800 3801 3741 3802 3742 3803 (precompute-types '((mod 2) (mod 4) (mod 16) (mod #x100) (mod #x10000) … … 3748 3809 )) 3749 3810 3811 3750 3812 (precompute-types *cl-types*) 3813 3814 ;;; Treat CHARACTER and BASE-CHAR as equivalent. 3815 (setf (info-type-builtin 'character) (info-type-builtin 'base-char)) 3816 ;;; And EXTENDED-CHAR as empty. 3817 (setf (info-type-builtin 'extended-char) *empty-type*) 3818 3751 3819 (defparameter *null-type* (specifier-type 'null)) 3752 3820
Note:
See TracChangeset
for help on using the changeset viewer.
