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

Character type implementation. More...

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

Macros

#define sym(S)   x_mksymbol(p_base, (x_char_t *)(S))
 
#define num(N)   x_mkint(p_base, (N))
 
#define entry(S, N)   x_mkspair(p_base, X_OBJ_FLAG_NONE, sym(S), num(N))
 
#define pair(A, B)   x_mkspair(p_base, X_OBJ_FLAG_NONE, (A), (B))
 

Functions

x_obj_tx_make_char (x_obj_t *p_base, x_obj_flag_t flags, x_int_t cp)
 
x_int_t x_char_utf8_decode (const x_char_t *bytes, x_int_t nbytes)
 
x_obj_tx_type_char_save (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_char_struct (x_obj_t *p_base, x_obj_t *p_obj)
 
x_obj_tx_type_char_register (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_type_char_make (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_satom_t x_type_char_name = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .s = (x_char_t *)X_TYPE_CHAR_NAME })
 
x_satom_t x_type_char_make_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_char_make })
 
x_satom_t x_type_char_struct_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_char_struct })
 
x_satom_t x_type_char_save_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { (x_obj_t *)&x_type_char_save })
 

Detailed Description

Character type implementation.

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

Macro Definition Documentation

◆ entry

#define entry (   S,
 
)    x_mkspair(p_base, X_OBJ_FLAG_NONE, sym(S), num(N))

◆ num

#define num (   N)    x_mkint(p_base, (N))

◆ pair

#define pair (   A,
 
)    x_mkspair(p_base, X_OBJ_FLAG_NONE, (A), (B))

◆ sym

#define sym (   S)    x_mksymbol(p_base, (x_char_t *)(S))

Function Documentation

◆ x_char_utf8_decode()

x_int_t x_char_utf8_decode ( const x_char_t bytes,
x_int_t  nbytes 
)

Decode a UTF-8 byte sequence into a code point.

Bytes are read unsigned. The byte count is supplied by the caller (derived from the lead byte), so no bounds scanning is done here.

Parameters
bytesconst x_char_t* – Start of the UTF-8 sequence
nbytesx_int_t – Number of bytes in the sequence (1-4)
Returns
x_int_t – The decoded code point

◆ x_make_char()

x_obj_t * x_make_char ( x_obj_t p_base,
x_obj_flag_t  flags,
x_int_t  cp 
)

Allocate a heap character object with a given value.

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

Parameters
p_basex_obj_t* – Base (execution context)
flagsx_obj_flag_t – Object flags
cpx_int_t – Unicode code point
Returns
x_obj_t* – New heap-allocated character object

◆ x_type_char_make()

x_obj_t * x_type_char_make ( x_obj_t p_base,
x_obj_t p_args 
)

Type-system make callback for character objects.

Extracts the character value 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* – (char-value . (flags | nil))
Returns
x_obj_t* – New heap-allocated character object

◆ x_type_char_register()

x_obj_t * x_type_char_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register or retrieve the character 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_char_save()

x_obj_t * x_type_char_save ( x_obj_t p_base,
x_obj_t p_args 
)

Build the character type descriptor struct.

Populates name, make, analyse, read, write, and display callbacks. Also builds an alist of named character constants (alarm, backspace, delete, escape, newline, null, return, space, tab) as type data.

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

◆ x_type_char_struct()

x_obj_t * x_type_char_struct ( x_obj_t p_base,
x_obj_t p_args 
)

Build the character type descriptor struct.

Variable Documentation

◆ x_type_char_make_prim

◆ x_type_char_name

◆ x_type_char_save_prim

◆ x_type_char_struct_prim