5.1.5 Array Manipulation

Common Lisp arrays have many manifestations in CMU Common Lisp. The CMU Common Lisp data types Bit-Vector, Integer-Vector, String, General-Vector, and Array are used to implement the collection of data types the Common Lisp manual calls “arrays.”

In the following miscop descriptions, “simple-array” means an array implemented in CMU Common Lisp as a Bit-Vector, I-Vector, String, or G-Vector. “Complex-array” means an array implemented as a CMU Common Lisp Array object. “Complex-bit-vector” means a bit-vector implemented as a CMU Common Lisp array; similar remarks apply for “complex-string” and so forth.

Vector-Length (Vector)

returns the length of the one-dimensional Common Lisp array Vector. G-Vector-Length, Simple-String-Length, and Simple-Bit-Vector-Length return the lengths of G-Vectors, CMU Common Lisp strings, and CMU Common Lisp Bit-Vectors respectively. Vector should be a vector of the appropriate type.

Get-Vector-Subtype (Vector)

returns the subtype field of the vector Vector as an integer. Vector should be a vector of some sort.

Set-Vector-Subtype (Vector A)

sets the subtype field of the vector Vector to A, which must be a fixnum.

Get-Vector-Access-Code (Vector)

returns the access code of the I-Vector (or Bit-Vector) Vector as a fixnum.

Shrink-Vector (Vector Length)

sets the length field and the number-of-entries field of the vector Vector to Length. If the vector contains Lisp objects, entries beyond the new end are set to Trap. Returns the shortened vector. Length should be a fixnum. One cannot shrink array headers or function headers.

Typed-Vref (A Vector I)

returns the I’th element of the I-Vector Vector by indexing into it as if its access-code were A. A and I should be fixnums.

Typed-Vset (A Vector I Value)

sets the I’th element of the I-Vector Vector to Value indexing into Vector as if its access-code were A. A, I, and Value should be fixnums. Value is returned.

Header-Length (Object)

returns the number of Lisp objects in the header of the function or array Object. This is used to find the number of dimensions of an array or the number of constants in a function.

Header-Ref (Object I)

returns the I’th element of the function or array header Object. I must be a fixnum.

Header-Set (Object I Value)

sets the I’th element of the function of array header Object to Value, and pushes Value. I must be a fixnum.

The names of the miscops used to reference and set elements of arrays are based somewhat on the Common Lisp function names. The SVref, SBit, and SChar miscops perform the same operation as their Common Lisp namesakes — referencing elements of simple-vectors, simple-bit-vectors, and simple-strings respectively. Aref1 references any kind of one dimensional array. The names of setting functions are derived by replacing “ref” with “set”, “char” with “charset”, and “bit” with “bitset.”

Aref1, SVref, SChar, SBit (Array I)

returns the I’th element of the one-dimensional array Array. SVref pushes an element of a G-Vector; SChar an element of a string; Sbit an element of a Bit-Vector. I should be a fixnum.

Aset1, SVset, SCharset, SBitset (Array I Value)

sets the I’th element of the one-dimensional array Array to Value. SVset sets an element of a G-Vector; SCharset an element of a string; SBitset an element of a Bit-Vector. I should be a fixnum and Value is returned.

CAref2, CAref3 (Array I1 I2)

returns the element (I1, I2) of the two-dimensional array Array. I1 and I2 should be fixnums. CAref3 pushes the element (I1, I2, I3).

CAset2, CAset3 (Array I1 I2 Value)

sets the element (I1, I2) of the two-dimensional array Array to Value and returns Value. I1 and I2 should be fixnums. CAset3 sets the element (I1, I2, I3).

Bit-Bash (V1 V2 V3 Op)

V1, V2, and V3 should be bit-vectors and Op should be a fixnum. The elements of the bit vector V3 are filled with the result of Op’ing the corresponding elements of V1 and V2. Op should be a Boole-style number (see the Boole miscop in section Boole-Section).

The rest of the miscops in this section implement special cases of sequence or string operations. Where an operand is referred to as a string, it may actually be an 8-bit I-Vector or system area pointer.

Byte-BLT (Src-String Src-Start Dst-String Dst-Start Dst-End)

moves bytes from Src-String into Dst-String between Dst-Start (inclusive) and Dst-End (exclusive). Dst-Start - Dst-End bytes are moved. If the substrings specified overlap, “the right thing happens,” i.e. all the characters are moved to the right place. This miscop corresponds to the Common Lisp function REPLACE when the sequences are simple-strings.

Find-Character (String Start End Character)

searches String for the Character from Start to End. If the character is found, the corresponding index into String is returned, otherwise NIL is returned. This miscop corresponds to the Common Lisp function FIND when the sequence is a simple-string.

Find-Character-With-Attribute (String Start End Table Mask)

The codes of the characters of String from Start to End are used as indices into the Table, which is an I-Vector of 8-bit bytes. When the number picked up from the table bitwise ANDed with Mask is non-zero, the current index into the String is returned.

SXHash-Simple-String (String Length)

Computes the hash code of the first Length characters of String and pushes it on the stack. This corresponds to the Common Lisp function SXHASH when the object is a simple-string. The Length operand can be Nil, in which case the length of the string is calculated in assembler.