x-engine-c v0.2.31
The C engine for x-lang
Loading...
Searching...
No Matches
x-vector.h File Reference

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,...)
 

Detailed Description

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.

vector of 3
+---------+
| header |
+---------+ <- data start
| length | ----> atom: 3
| elem 0 |
| elem 1 |
| elem 2 |
+---------+
#define atom(X)
Definition x-eval.c:695

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.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Macro Definition Documentation

◆ x_mksvector

#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.

◆ x_vector_i

#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).

◆ x_vector_length_obj

#define x_vector_length_obj (   N)    ((x_obj_t *)x_vector_length_objs[(N)])

The static atom holding the length N.

◆ X_VECTOR_LENGTH_STATIC_LEN

#define X_VECTOR_LENGTH_STATIC_LEN   9

The number of static length atoms: lengths 0 to X_VECTOR_LENGTH_STATIC_LEN - 1 have one.

◆ x_vector_units

#define x_vector_units (   N)    (X_VECTOR_UNITS_LENGTH + (N))

Number of data units in a vector of N elements.

◆ X_VECTOR_UNITS_LENGTH

#define X_VECTOR_UNITS_LENGTH   1

Data units consumed by a vector's length.

◆ x_vectorfn

#define x_vectorfn (   V,
  I 
)    x_fn(x_vector_i((V), (I)))

Element I of vector V, as a function pointer (an lvalue).

◆ x_vectorlength

#define x_vectorlength (   V)    x_atomint(x_vectorlengthobj((V)))

The length of vector V.

◆ x_vectorlengthobj

#define x_vectorlengthobj (   V)    x_obj(x_obj_data_i((V), 0))

The length atom of vector V (an lvalue).

◆ x_vectorobj

#define x_vectorobj (   V,
  I 
)    x_obj(x_vector_i((V), (I)))

Element I of vector V, as an object (an lvalue).

Function Documentation

◆ x_vector_make()

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.

Parameters
p_baseBase (allocation context).
p_typeThe type object to assign, or NULL.
flagsInitial object flags.
lengthThe number of elements.
...The elements, length of them, each an x_obj_t *.
Returns
The new vector, or NULL on allocation failure.

Variable Documentation

◆ x_vector_length_objs

x_satom_t x_vector_length_objs[X_VECTOR_LENGTH_STATIC_LEN]
extern

Static atoms holding the lengths 0 to X_VECTOR_LENGTH_STATIC_LEN - 1.