0.8.0.78.vector-nil-string.7:
[sbcl.git] / src / compiler / generic / vm-array.lisp
1 ;;;; this file centralizes information about the array types
2 ;;;; implemented by the system, where previously such information was
3 ;;;; spread over several files.
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!VM")
15
16 (defstruct (specialized-array-element-type-properties
17             (:conc-name saetp-)
18             (:constructor
19              !make-saetp
20              (specifier
21               initial-element-default
22               n-bits
23               primitive-type-name
24               &key (n-pad-elements 0)
25               &aux (typecode
26                     (eval (symbolicate primitive-type-name "-WIDETAG")))))
27             (:copier nil))
28   ;; the element specifier, e.g. BASE-CHAR or (UNSIGNED-BYTE 4)
29   (specifier (missing-arg) :type type-specifier :read-only t)
30   ;; the element type, e.g. #<BUILT-IN-CLASS BASE-CHAR (sealed)> or
31   ;; #<SB-KERNEL:NUMERIC-TYPE (UNSIGNED-BYTE 4)>
32   (ctype nil :type (or ctype null))
33   ;; what we get when the low-level vector-creation logic zeroes all
34   ;; the bits (which also serves as the default value of MAKE-ARRAY's
35   ;; :INITIAL-ELEMENT keyword)
36   (initial-element-default (missing-arg) :read-only t)
37   ;; how many bits per element
38   (n-bits (missing-arg) :type index :read-only t)
39   ;; the low-level type code (aka "widetag")
40   (typecode (missing-arg) :type index :read-only t)
41   ;; the name of the primitive type of data vectors specialized on
42   ;; this type
43   (primitive-type-name (missing-arg) :type symbol :read-only t)
44   ;; the number of extra elements we use at the end of the array for
45   ;; low level hackery (e.g., one element for arrays of BASE-CHAR,
46   ;; which is used for a fixed #\NULL so that when we call out to C
47   ;; we don't need to cons a new copy)
48   (n-pad-elements (missing-arg) :type index :read-only t))
49
50 (defparameter *specialized-array-element-type-properties*
51   (map 'simple-vector
52        (lambda (args)
53          (apply #'!make-saetp args))
54        `(;; Erm.  Yeah.  There aren't a lot of things that make sense
55          ;; for an initial element for (ARRAY NIL). -- CSR, 2002-03-07
56          (nil #:mu 0 simple-array-nil)
57          (base-char ,(code-char 0) 8 simple-base-string
58                     ;; (SIMPLE-BASE-STRINGs are stored with an extra
59                     ;; trailing #\NULL for convenience in calling out
60                     ;; to C.)
61                     :n-pad-elements 1)
62          (single-float 0.0f0 32 simple-array-single-float)
63          (double-float 0.0d0 64 simple-array-double-float)
64          #!+long-float
65          (long-float 0.0l0 #!+x86 96 #!+sparc 128 simple-array-long-float)
66          (bit 0 1 simple-bit-vector)
67          ;; KLUDGE: The fact that these UNSIGNED-BYTE entries come
68          ;; before their SIGNED-BYTE partners is significant in the
69          ;; implementation of the compiler; some of the cross-compiler
70          ;; code (see e.g. COERCE-TO-SMALLEST-ELTYPE in
71          ;; src/compiler/debug-dump.lisp) attempts to create an array
72          ;; specialized on (UNSIGNED-BYTE FOO), where FOO could be 7;
73          ;; (UNSIGNED-BYTE 7) is SUBTYPEP (SIGNED-BYTE 8), so if we're
74          ;; not careful we could get the wrong specialized array when
75          ;; we try to FIND-IF, below. -- CSR, 2002-07-08
76          ((unsigned-byte 2) 0 2 simple-array-unsigned-byte-2)
77          ((unsigned-byte 4) 0 4 simple-array-unsigned-byte-4)
78          ((unsigned-byte 8) 0 8 simple-array-unsigned-byte-8)
79          ((unsigned-byte 16) 0 16 simple-array-unsigned-byte-16)
80          ((unsigned-byte 32) 0 32 simple-array-unsigned-byte-32)
81          ((signed-byte 8) 0 8 simple-array-signed-byte-8)
82          ((signed-byte 16) 0 16 simple-array-signed-byte-16)
83          ;; KLUDGE: See the comment in PRIMITIVE-TYPE-AUX,
84          ;; compiler/generic/primtype.lisp, for why this is FIXNUM and
85          ;; not (SIGNED-BYTE 30)
86          (fixnum 0 32 simple-array-signed-byte-30)
87          ((signed-byte 32) 0 32 simple-array-signed-byte-32)
88          ((complex single-float) #C(0.0f0 0.0f0) 64
89           simple-array-complex-single-float)
90          ((complex double-float) #C(0.0d0 0.0d0) 128
91           simple-array-complex-double-float)
92          #!+long-float
93          ((complex long-float) #C(0.0l0 0.0l0) #!+x86 192 #!+sparc 256
94           simple-array-complex-long-float)
95          (t 0 32 simple-vector))))
96
97 (defvar sb!kernel::*specialized-array-element-types*
98   (map 'list
99        #'saetp-specifier
100        *specialized-array-element-type-properties*))
101
102 #-sb-xc-host
103 (defun !vm-type-cold-init ()
104   (setf sb!kernel::*specialized-array-element-types*
105         '#.sb!kernel::*specialized-array-element-types*))
106
107 (defvar *simple-array-primitive-types*
108   (map 'list
109        (lambda (saetp)
110          (cons (saetp-specifier saetp)
111                (saetp-primitive-type-name saetp)))
112        *specialized-array-element-type-properties*)
113   #!+sb-doc
114   "An alist for mapping simple array element types to their
115 corresponding primitive types.")