|
x-engine-c v0.2.31
The C engine for x-lang
|
The vector layout – an object whose first data unit holds its length and whose other data units are its elements. More...
#include "x-obj.h"Go to the source code of this file.
Macros | |
Vector Layout | |
| #define | X_VECTOR_UNITS_LENGTH 1 |
| #define | x_vector_units(N) (X_VECTOR_UNITS_LENGTH + (N)) |
Vector Accessors | |
| #define | x_vectorlengthobj(V) x_obj(x_obj_data_i((V), 0)) |
| #define | x_vectorlength(V) x_atomint(x_vectorlengthobj((V))) |
| #define | x_vector_i(V, I) x_obj_data_i((V), X_VECTOR_UNITS_LENGTH + (I)) |
| #define | x_vectorobj(V, I) x_obj(x_vector_i((V), (I))) |
| #define | x_vectorfn(V, I) x_fn(x_vector_i((V), (I))) |
Static Lengths | |
| #define | X_VECTOR_LENGTH_STATIC_LEN 9 |
| #define | x_vector_length_obj(N) ((x_obj_t *)x_vector_length_objs[(N)]) |
| x_satom_t | x_vector_length_objs [X_VECTOR_LENGTH_STATIC_LEN] |
Vector Constructors | |
| #define | x_mksvector(B, N, ...) x_vector_make((B), NULL, X_OBJ_FLAG_NONE, (N), __VA_ARGS__) |
| x_obj_t * | x_vector_make (x_obj_t *p_base, x_obj_t *p_type, x_obj_flag_t flags, x_int_t length,...) |
The vector layout – an object whose first data unit holds its length and whose other data units are its elements.
A vector of N elements has N + 1 data units. Unit 0 holds the length: an atom whose datum is N. Units 1 to N hold the elements, element I in unit I + 1.
This file supplies the layout and nothing more: the accessors below, the static length atoms, and a constructor with no type. The VECTOR type an object of this layout carries is x-type/vector's, and so is what its elements are: a base's slot vector holds function pointers (see x-eval-slots.h). The elements are a run of words, which is what a routine in a slot takes as its arguments.
| #define x_mksvector | ( | B, | |
| N, | |||
| ... | |||
| ) | x_vector_make((B), NULL, X_OBJ_FLAG_NONE, (N), __VA_ARGS__) |
Heap-allocate a vector with no type holding the N objects that follow. The s is the one of x_mksatom() and x_mkspair(): the built-in layout, with no type of the engine's.
| #define x_vector_i | ( | V, | |
| I | |||
| ) | x_obj_data_i((V), X_VECTOR_UNITS_LENGTH + (I)) |
Element I of vector V, as a raw datum (an lvalue).
| #define x_vector_length_obj | ( | N | ) | ((x_obj_t *)x_vector_length_objs[(N)]) |
The static atom holding the length N.
| #define X_VECTOR_LENGTH_STATIC_LEN 9 |
The number of static length atoms: lengths 0 to X_VECTOR_LENGTH_STATIC_LEN - 1 have one.
| #define x_vector_units | ( | N | ) | (X_VECTOR_UNITS_LENGTH + (N)) |
Number of data units in a vector of N elements.
| #define X_VECTOR_UNITS_LENGTH 1 |
Data units consumed by a vector's length.
| #define x_vectorfn | ( | V, | |
| I | |||
| ) | x_fn(x_vector_i((V), (I))) |
Element I of vector V, as a function pointer (an lvalue).
| #define x_vectorlength | ( | V | ) | x_atomint(x_vectorlengthobj((V))) |
The length of vector V.
| #define x_vectorlengthobj | ( | V | ) | x_obj(x_obj_data_i((V), 0)) |
The length atom of vector V (an lvalue).
| #define x_vectorobj | ( | V, | |
| I | |||
| ) | x_obj(x_vector_i((V), (I))) |
Element I of vector V, as an object (an lvalue).
| x_obj_t * x_vector_make | ( | x_obj_t * | p_base, |
| x_obj_t * | p_type, | ||
| x_obj_flag_t | flags, | ||
| x_int_t | length, | ||
| ... | |||
| ) |
Allocate a vector of type p_type holding the length objects that follow.
Allocate a vector and initialize its elements.
A vector of length elements has its length in its first data unit and its elements after it (see x-vector.h). The length is one of the static length atoms when there is one for it, and an atom of its own otherwise.
| p_base | Base (allocation context). |
| p_type | The type object to assign, or NULL. |
| flags | Initial object flags. |
| length | The number of elements. |
| ... | The elements, length of them, each an x_obj_t *. |
|
extern |
Static atoms holding the lengths 0 to X_VECTOR_LENGTH_STATIC_LEN - 1.