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

The vector layout's constructor and static lengths, and the slot vector a base holds (see x-vector.h, x-eval-slots.h). More...

#include <stdarg.h>
#include "x-vector.h"
#include "x-eval-slots.h"
#include "x-obj/prim.h"

Functions

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,...)
 
x_obj_t * x_slots_make (x_obj_t *p_base, x_int_t length)
 

Variables

x_satom_t x_vector_length_objs [X_VECTOR_LENGTH_STATIC_LEN]
 

Detailed Description

The vector layout's constructor and static lengths, and the slot vector a base holds (see x-vector.h, x-eval-slots.h).

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

Function Documentation

◆ x_slots_make()

x_obj_t * x_slots_make ( x_obj_t *  p_base,
x_int_t  length 
)

Make a slot vector of length slots, every one empty.

The slot vector is a vector: its first data unit holds its length, and its slots follow. It has no type, and must not be given one: the vector sits in the base's tree, where the collector's mark reaches it, and an object with no type is marked and not descended – its elements are function pointers, not objects. It is allocated with X_OBJ_FLAG_SHARED, so a sweep keeps it for as long as the base lives, and its length is a static atom or a SHARED one for the same reason.

Parameters
p_baseBase the vector belongs to (allocation context).
lengthThe number of slots.
Returns
The slot vector, or NULL when it could not be allocated.

◆ 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 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]
Initial value:
= {
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 0}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 1}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 2}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 3}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 4}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 5}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 6}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 7}),
x_obj_set(NULL, X_OBJ_FLAG_NONE, {.i = 8})
}
@ X_OBJ_FLAG_NONE
Definition x-obj.h:131
#define x_obj_set(T, F,...)
Definition x-obj.h:344

Static atoms holding the lengths 0 to X_VECTOR_LENGTH_STATIC_LEN - 1.