x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
Callable Binding

Bind C functions into the x-lang environment. More...

Data Structures

struct  x_callable_entry_t
 

Functions

void x_value_bind (x_obj_t *p_base, x_char_t *name, x_obj_t *p_val)
 
void x_callable_bind (x_obj_t *p_base, x_char_t *name, x_fn_t fn)
 
void x_callable_bind_table (x_obj_t *p_base, const x_callable_entry_t *table, int count)
 

Detailed Description

Bind C functions into the x-lang environment.

Function Documentation

◆ x_callable_bind()

void x_callable_bind ( x_obj_t p_base,
x_char_t name,
x_fn_t  fn 
)

Bind a single C function as a named callable in the environment.

Bind a C primitive function in the base's root environment.

Creates a symbol, wraps the C function as a prim object, and binds the pair in the root, where every environment in the base reaches it.

Parameters
p_basex_obj_t* – Base (execution context)
namex_char_t* – Symbol name to bind
fnx_fn_t – C function pointer

Symbol interning. x_make_symbol interns the name so that all references to the same name share a single symbol object. This enables O(1) pointer-identity comparison in the environment lookups.

Note
Called during interpreter bootstrap (x_prim_register) and by FFI registration. All bindings created here are permanent globals that survive scope changes.
See also
x_value_bind – lower-level helper that binds any value
x_callable_bind_table – batch registration of multiple primitives
x_env_bind – the binder, which def shares

◆ x_callable_bind_table()

void x_callable_bind_table ( x_obj_t p_base,
const x_callable_entry_t table,
int  count 
)

Bind an array of name/function entries into the environment.

Bind an array of C primitive entries into the global environment.

Iterates table and calls x_callable_bind for each entry.

Parameters
p_basex_obj_t* – Base (execution context)
tableconst x_callable_entry_t* – Array of (name, fn) entries
countint – Number of entries
See also
x_callable_bind

◆ x_value_bind()

void x_value_bind ( x_obj_t p_base,
x_char_t name,
x_obj_t p_val 
)

Bind a named symbol to an arbitrary value in the global environment.

Bind a named symbol to an arbitrary value in the base's root environment.

Parameters
p_basex_obj_t* – Base (execution context)
namex_char_t* – Symbol name to bind
p_valx_obj_t* – Value to bind
See also
x_callable_bind – convenience wrapper for binding C primitives