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

Implementation of the base environment object. More...

#include "x-base.h"

Macros

#define nil   NULL
 
#define pair(X, Y)   (x_mkspair(p_base, X_OBJ_FLAG_SHARED, (X), (Y)))
 
#define atom(X)   (x_mksatom(p_base, X_OBJ_FLAG_SHARED, (X)))
 

Functions

x_obj_tx_base_make (x_obj_t *p_base, struct x_base_t base)
 
x_obj_tx_base_read (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_base_write (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Implementation of the base environment object.

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

Macro Definition Documentation

◆ atom

#define atom (   X)    (x_mksatom(p_base, X_OBJ_FLAG_SHARED, (X)))

◆ nil

#define nil   NULL

◆ pair

#define pair (   X,
 
)    (x_mkspair(p_base, X_OBJ_FLAG_SHARED, (X), (Y)))

Function Documentation

◆ x_base_make()

x_obj_t * x_base_make ( x_obj_t p_base,
struct x_base_t  base 
)

Create a new base environment object.

Allocates and assembles the nested pair tree that holds all environment state. Every node is allocated with X_OBJ_FLAG_SHARED (via the local pair/atom macros) so the base tree is immune to garbage collection. Each leaf value is wrapped as pair(atom(value), nil) to form a one-element field stack (see x-base.h). Hook values passed as NULL produce (nil . nil) leaves (hook disabled). The tree layout matches the field accessor macros: x_base_field_filein() navigates to the filein leaf, x_base_field_hook_type_name() to the type_name hook, etc.

Parameters
p_baseExisting base for allocation context, or NULL for bootstrap.
baseInitialization parameters (file descriptors, hooks, etc.).
Returns
The newly created base object.

◆ x_base_read()

x_obj_t * x_base_read ( x_obj_t p_base,
x_obj_t p_args 
)

Read data from the base's input file descriptor into an atom.

Uses the filein descriptor from the base environment, or falls back to STDIN_FILENO if the base is not initialized.

Parameters
p_baseBase (execution context).
p_argsPair list: (destination-atom byte-count).
Returns
The destination atom on success, or NULL on read failure. On failure the byte-count atom is overwritten with the raw x_sys_read() result so the caller can tell end-of-stream (0) from a read error (negative): this layer has no error channel, and conflating the two turned transient read errors into silent input truncation (x-lang#170).

◆ x_base_write()

x_obj_t * x_base_write ( x_obj_t p_base,
x_obj_t p_args 
)

Write data from an atom to the base's output or write buffer.

Checks the write_buf field first: if it holds a non-nil pair (pointer . position), data is memcpy'd into the buffer at the current position and the position is advanced. Otherwise, writes to the fileout file descriptor, falling back to STDOUT_FILENO if the base is not initialized.

Parameters
p_baseBase (execution context).
p_argsPair list: (source-atom byte-count).
Returns
The source atom on success, or NULL on write failure.