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

Vector type – an object whose first data unit holds its length and whose other data units are its elements. More...

#include "x-type.h"
#include "x-vector.h"

Go to the source code of this file.

Macros

#define X_TYPE_VECTOR_NAME   "VECTOR"
 
#define X_TYPE_VECTOR_UNITS   (-X_VECTOR_UNITS_LENGTH)
 
Predicates
#define x_obj_type_isvector(B, X)   x_obj_is_type((B), (X), X_TYPE_VECTOR_NAME)
 
Constructors
#define x_mkvector(B, N, ...)   x_make_vector((B), X_OBJ_FLAG_NONE, (N), __VA_ARGS__)
 

Functions

x_obj_t * x_make_vector (x_obj_t *p_base, x_obj_flag_t flags, x_int_t length,...)
 
x_obj_t * x_type_vector_struct (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_t * x_type_vector_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_t * x_type_vector_length (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Vector type – an object whose first data unit holds its length and whose other data units are its elements.

The layout is x-expr's (x-vector.h); the type is this file's. A vector's elements are objects, and the collector follows them: the type declares its units as one leading unit, the length, and a payload counted by it, every unit a reference.

A base's slot vector has this layout and no type. Its elements are function pointers, which the collector must not follow: the vector sits in the base's tree, where the mark reaches it, and an object with no type is marked and not descended.

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

Macro Definition Documentation

◆ x_mkvector

#define x_mkvector (   B,
  N,
  ... 
)    x_make_vector((B), X_OBJ_FLAG_NONE, (N), __VA_ARGS__)

Create a vector of the N objects that follow, with default flags.

◆ x_obj_type_isvector

#define x_obj_type_isvector (   B,
  X 
)    x_obj_is_type((B), (X), X_TYPE_VECTOR_NAME)

Test whether X is a VECTOR object.

◆ X_TYPE_VECTOR_NAME

#define X_TYPE_VECTOR_NAME   "VECTOR"

Canonical type name.

◆ X_TYPE_VECTOR_UNITS

#define X_TYPE_VECTOR_UNITS   (-X_VECTOR_UNITS_LENGTH)

The type's declared unit count: one leading unit, and a payload whose count that unit holds (see x_type_units_count()).

Function Documentation

◆ x_make_vector()

x_obj_t * x_make_vector ( x_obj_t *  p_base,
x_obj_flag_t  flags,
x_int_t  length,
  ... 
)

Allocate a VECTOR object holding the length objects that follow.

Allocate a VECTOR object holding the objects that follow.

The length is an INTEGER object of its own, as the length of a vector x-lang makes is, so the two are read the same way.

Parameters
p_baseBase (execution context).
flagsObject flags.
lengthThe number of elements.
...The elements, length of them, each an x_obj_t *.
Returns
Newly allocated VECTOR object.

◆ x_type_vector_length()

x_obj_t * x_type_vector_length ( x_obj_t *  p_base,
x_obj_t *  p_args 
)

Type-system length handler for VECTOR objects.

Type-system length handler for VECTOR objects.

Parameters
p_baseBase (execution context).
p_argsArgument list: (vector . ...).
Returns
The vector's length object.

◆ x_type_vector_register()

x_obj_t * x_type_vector_register ( x_obj_t *  p_base,
x_obj_t *  p_args 
)

Register (or retrieve) the VECTOR type in the type alist.

Register (or retrieve) the VECTOR type in the type alist.

Calls x_type_struct_get() with the VECTOR name and struct constructor,

Parameters
p_baseBase (execution context).
p_argsUnused.
Returns
The registered VECTOR type object.

◆ x_type_vector_struct()

x_obj_t * x_type_vector_struct ( x_obj_t *  p_base,
x_obj_t *  p_args 
)

Build the VECTOR type struct descriptor.

Build the VECTOR type struct descriptor.

Populates the name, the unit count and the length handler for the type system. With no save handler of its own the type takes the default, which writes the units the count declares: the length, then the elements, each a reference.

Parameters
p_baseBase (execution context).
p_argsUnused.
Returns
Type struct pair-tree for VECTOR.