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

String type implementation. More...

#include "x-eval.h"
#include "x-type/str.h"
#include "x-token/sexp/str.h"
#include "x-type/char.h"
#include "x-type/int.h"

Functions

x_obj_tx_make_str (x_obj_t *p_base, x_obj_flag_t flags, x_char_t *s)
 
x_obj_tx_type_str_save (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_struct (x_obj_t *p_base, x_obj_t *p_obj)
 
x_obj_tx_type_str_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_make (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_length (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_str_call (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_satom_t x_type_str_name = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .s = (x_char_t *)X_TYPE_STR_NAME })
 
x_satom_t x_type_str_length_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_str_length })
 
x_satom_t x_type_str_make_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_str_make })
 
x_satom_t x_type_str_call_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_str_call })
 
x_satom_t x_type_str_struct_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_str_struct })
 
x_satom_t x_type_str_save_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_str_save })
 

Detailed Description

String type implementation.

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

Function Documentation

◆ x_make_str()

x_obj_t * x_make_str ( x_obj_t p_base,
x_obj_flag_t  flags,
x_char_t s 
)

Allocate a heap string object wrapping a C string pointer.

Builds a stack-based argument list and delegates to x_type_str_make.

Parameters
p_basex_obj_t* – Base (execution context)
flagsx_obj_flag_t – Object flags (e.g. X_OBJ_FLAG_OWN)
sx_char_t* – C string pointer to wrap
Returns
x_obj_t* – New heap-allocated string object

◆ x_type_str_call()

x_obj_t * x_type_str_call ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system call callback – string as callable.

Supports three calling conventions:

  • No args: returns the string length as an integer.
  • One arg (index): returns the character at that position. Negative indices count from the end.
  • Two args (start, len): returns a substring.
Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (string-object . evaluated-args)
Returns
x_obj_t* – Integer (length), character, or substring
See also
x_type_str_length

◆ x_type_str_length()

x_obj_t * x_type_str_length ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system length callback – returns string length as an integer.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (string-object . ...)
Returns
x_obj_t* – Integer object with string length

◆ x_type_str_make()

x_obj_t * x_type_str_make ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system make callback for string objects.

Extracts the string pointer and optional flags from p_args, then allocates a heap object via x_obj_make.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – (str-value . (flags | nil))
Returns
x_obj_t* – New heap-allocated string object

◆ x_type_str_register()

x_obj_t * x_type_str_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register or retrieve the string type on the base context.

Parameters
p_basex_obj_t* – Base (execution context)
p_argsx_obj_t* – Unused
Returns
x_obj_t* – Registered type object

◆ x_type_str_save()

x_obj_t * x_type_str_save ( x_obj_t p_base,
x_obj_t p_args 
)

Build the string type descriptor struct.

Populates name, length, make, call, analyse, read, write, and display callbacks.

Parameters
p_basex_obj_t* – Base (execution context)
p_objx_obj_t* – Unused
Returns
x_obj_t* – Type descriptor pair list

◆ x_type_str_struct()

x_obj_t * x_type_str_struct ( x_obj_t p_base,
x_obj_t p_args 
)

Build the string type descriptor struct.

Variable Documentation

◆ x_type_str_call_prim

◆ x_type_str_length_prim

◆ x_type_str_make_prim

◆ x_type_str_name

◆ x_type_str_save_prim

◆ x_type_str_struct_prim