Fix make-array transforms.
[sbcl.git] / doc / internals / string-types.texinfo
1 @node Character and String Types
2 @comment  node-name,  next,  previous,  up
3 @chapter Character and String Types
4
5 @menu
6 * Memory Layout::
7 * Reader and Printer::
8 @end menu
9
10 The @code{:SB-UNICODE} feature implies support for all 1114112 potential
11 characters in the character space defined by the Unicode consortium,
12 with the identity mapping between lisp @code{char-code} and Unicode code
13 point.  SBCL releases before version 0.8.17, and those without the
14 @code{:SB-UNICODE} feature, support only 256 characters, with the
15 identity mapping between @code{char-code} and Latin1 (or, equivalently,
16 the first 256 Unicode) code point.
17
18 In the absence of the @code{:SB-UNICODE} feature, the types
19 @code{base-char} and @code{character} are identical, and encompass the
20 set of all 256 characters supported by the implementation.  With the
21 @code{:SB-UNICODE} on @code{*features*} (the default), however,
22 @code{base-char} and @code{character} are distinct: @code{character}
23 encompasses the set of all 1114112 characters, while @code{base-char}
24 represents the set of the first 128 characters.
25
26 The effect of this on string types is that an SBCL configured with
27 @code{:SB-UNICODE} has three disjoint @code{string} types: @code{(vector
28 nil)}, @code{base-string} and @code{(vector character)}.  In a build
29 without @code{:SB-UNICODE}, there are two such disjoint types:
30 @code{(vector nil)} and @code{(vector character)}; @code{base-string} is
31 identically equal to @code{(vector character)}.
32
33 The @code{SB-KERNEL:CHARACTER-SET-TYPE} represents possibly
34 noncontiguous sets of characters as lists of range pairs: for example,
35 the type @code{standard-char} is represented as the type
36 @code{(sb-kernel:character-set '((10 . 10) (32 . 126)))}
37
38 @node Memory Layout
39 @comment  node-name,  next,  previous,  up
40 @section Memory Layout
41
42 Characters are immediate objects (that is, they require no heap
43 allocation) in all permutations of build-time options.  Even on a 32-bit
44 platform with @code{:SB-UNICODE}, there are three bits to spare after
45 allocating 8 bits for the character widetag and 21 for the character
46 code.  There is only one such layout, and consequently only one widetag
47 is needed: the difference between @code{base-char} and @code{character}
48 is purely on the magnitude of the @code{char-code}.
49
50 Objects of type @code{(simple-array nil (*))} are represented in memory
51 as two words: the first is the object header, with the appropriate
52 widetag, and the second is the length field.  No memory is needed for
53 elements of these objects, as they can have none.
54
55 Objects of type @code{simple-base-string} have the header word
56 with widetag, then a word for the length, and after that a sequence of
57 8-bit @code{char-code} bytes.  The system arranges for there to be a
58 null byte after the sequence of lisp character codes.
59
60 Objects of type @code{(simple-array character (*))}, where this is a
61 distinct type from @code{simple-base-string}, have the header word with
62 widetag, length, and then a sequence of 32-bit @code{char-code} bytes.
63 Again, the system arranges for there to be a null word after the
64 sequence of character codes.
65
66 Non-simple character arrays, and simple character arrays of non-unit
67 dimensionality, have an array header with a reference to an underlying
68 data array of the appropriate form from the above representations.
69
70 @node Reader and Printer
71 @comment  node-name,  next,  previous,  up
72 @section Reader and Printer
73
74 The @code{"} reader macro always constructs an object of type
75 @code{(simple-array character)}, even if all of the characters within
76 the quotation marks are of type @code{base-char}.  This implies that
77 only strings of type @code{(vector character)} will be able to be
78 printed when @code{*print-readably*} is true: attempting to print
79 strings of other types will cause an error of type
80 @code{print-not-readable}.
81