cheax
Lisp dialect with C API
|
Functions and datastructures to create, examine and manipulate cheax expressions and their types. More...
Data Structures | |
struct | chx_value |
Represents a value in the cheax environment. More... | |
struct | chx_id |
Identifier type. More... | |
struct | chx_quote |
Quoted value type. More... | |
struct | chx_list |
List type. More... | |
struct | chx_func |
Function or macro type. More... | |
union | chx_eval_out |
struct | chx_ext_func |
Cheax external/user function expression. More... | |
struct | chx_sym |
Custom symbol. More... | |
Macros | |
#define | CHX_INT_MIN INT_LEAST64_MIN |
Minimum value for chx_int. More... | |
#define | CHX_INT_MAX INT_LEAST64_MAX |
Maximum value for chx_int. More... | |
#define | PRIdCHX PRIdLEAST64 |
Conversion specifier to print chx_int (decimal). More... | |
#define | PRIiCHX PRIiLEAST64 |
Conversion specifier to print chx_int (decimal). More... | |
#define | SCNdCHX SCNdLEAST64 |
Conversion specifier to scan chx_int (decimal). More... | |
#define | SCNiCHX SCNiLEAST64 |
Conversion specifier to scan chx_int (decimal). More... | |
#define | CHEAX_NIL ((struct chx_value){ 0 }) |
The nil value. More... | |
#define | cheax_id_value(X) ((struct chx_value){ .type = CHEAX_ID, .data.as_id = (X) }) |
Turns chx_id into chx_value. More... | |
#define | cheax_int(X) ((struct chx_value){ .type = CHEAX_INT, .data.as_int = (X) }) |
Creates a chx_value of type CHEAX_INT. More... | |
#define | cheax_true() ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = 1 }) |
Creates chx_value true . More... | |
#define | cheax_false() ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = 0 }) |
Creates chx_value false . More... | |
#define | cheax_bool(X) ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = (X) ? 1 : 0 }) |
Creates chx_value of type CHEAX_BOOL. More... | |
#define | cheax_double(X) ((struct chx_value){ .type = CHEAX_DOUBLE, .data.as_double = (X) }) |
Creates a chx_value of type CHEAX_DOUBLE. More... | |
#define | cheax_list_value(X) ((struct chx_value){ .type = CHEAX_LIST, .data.as_list = (X) }) |
Turns chx_list into chx_value. More... | |
#define | cheax_func_value(X) ((struct chx_value){ .type = CHEAX_FUNC, .data.as_func = (X) }) |
#define | cheax_ext_func_value(X) ((struct chx_value){ .type = CHEAX_EXT_FUNC, .data.as_ext_func = (X) }) |
#define | cheax_quote_value(X) ((struct chx_value){ .type = CHEAX_QUOTE, .data.as_quote = (X) }) |
#define | cheax_backquote_value(X) ((struct chx_value){ .type = CHEAX_BACKQUOTE, .data.as_quote = (X) }) |
#define | cheax_comma_value(X) ((struct chx_value){ .type = CHEAX_COMMA, .data.as_quote = (X) }) |
#define | cheax_splice_value(X) ((struct chx_value){ .type = CHEAX_SPLICE, .data.as_quote = (X) }) |
#define | cheax_string_value(X) ((struct chx_value){ .type = CHEAX_STRING, .data.as_string = (X) }) |
#define | cheax_env_value(X) ((struct chx_value){ .type = CHEAX_ENV, .data.as_env = (X) }) |
Typedefs | |
typedef int_least64_t | chx_int |
Integer type. More... | |
typedef double | chx_double |
Floating point type. More... | |
typedef struct chx_value(* | chx_func_ptr) (CHEAX *c, struct chx_list *args, void *info) |
Type for C functions to be invoked from cheax. More... | |
typedef int(* | chx_tail_func_ptr) (CHEAX *c, struct chx_list *args, void *info, struct chx_env *pop_stop, union chx_eval_out *out) |
typedef struct chx_value(* | chx_getter) (CHEAX *c, struct chx_sym *sym) |
typedef void(* | chx_setter) (CHEAX *c, struct chx_sym *sym, struct chx_value value) |
typedef void(* | chx_finalizer) (CHEAX *c, struct chx_sym *sym) |
typedef int | chx_ref |
Enumerations | |
enum | { CHEAX_LIST , CHEAX_INT , CHEAX_BOOL , CHEAX_DOUBLE , CHEAX_USER_PTR , CHEAX_ID , CHEAX_FUNC , CHEAX_EXT_FUNC , CHEAX_SPECIAL_OP , CHEAX_QUOTE , CHEAX_BACKQUOTE , CHEAX_COMMA , CHEAX_SPLICE , CHEAX_STRING , CHEAX_ENV , CHEAX_LAST_BASIC_TYPE = CHEAX_ENV , CHEAX_TYPESTORE_BIAS , CHEAX_TYPECODE = CHEAX_TYPESTORE_BIAS + 0 , CHEAX_ERRORCODE } |
Types of expressions within cheax. More... | |
enum | { CHEAX_VALUE_OUT , CHEAX_TAIL_OUT } |
Functions | |
struct chx_value | cheax_nil (void) CHX_CONST |
Creates a nil value. More... | |
bool | cheax_is_nil (struct chx_value v) CHX_CONST |
Tests whether given value is nil . More... | |
struct chx_value | cheax_id (CHEAX *c, const char *id) CHX_PURE |
Creates a chx_value of type CHEAX_ID. More... | |
struct chx_value | cheax_id_value_proc (struct chx_id *id) CHX_CONST |
Turns chx_id into chx_value. Like cheax_id_value(), but a function and not a macro. More... | |
struct chx_value | cheax_int_proc (chx_int value) CHX_CONST |
Creates a chx_value of type CHEAX_INT. Like cheax_int(), but a function and not a macro. More... | |
struct chx_value | cheax_bool_proc (bool value) CHX_CONST |
Creates a chx_value of type CHEAX_BOOL. Like cheax_bool(), but a function and not a macro. More... | |
struct chx_value | cheax_double_proc (chx_double value) CHX_CONST |
Creates a chx_value of type CHEAX_DOUBLE. Like cheax_double(), but a function and not a macro. More... | |
struct chx_value | cheax_list (CHEAX *c, struct chx_value car, struct chx_list *cdr) |
Creates a list. More... | |
struct chx_value | cheax_list_value_proc (struct chx_list *list) CHX_CONST |
Turns chx_list into chx_value. Like cheax_list_value(), but a function and not a macro. More... | |
struct chx_value | cheax_func_value_proc (struct chx_func *fn) CHX_CONST |
struct chx_value | cheax_ext_func (CHEAX *c, const char *name, chx_func_ptr perform, void *info) |
Creates a cheax external/user function expression. More... | |
struct chx_value | cheax_ext_func_value_proc (struct chx_ext_func *sf) CHX_CONST |
struct chx_value | cheax_quote (CHEAX *c, struct chx_value value) |
Creates a quoted cheax expression. More... | |
struct chx_value | cheax_quote_value_proc (struct chx_quote *quote) CHX_CONST |
struct chx_value | cheax_backquote (CHEAX *c, struct chx_value value) |
Creates a backquoted cheax expression. More... | |
struct chx_value | cheax_backquote_value_proc (struct chx_quote *bkquote) CHX_CONST |
struct chx_value | cheax_comma (CHEAX *c, struct chx_value value) |
Creates a cheax comma expression. More... | |
struct chx_value | cheax_comma_value_proc (struct chx_quote *comma) CHX_CONST |
struct chx_value | cheax_splice (CHEAX *c, struct chx_value value) |
Creates a cheax comma splice expression. More... | |
struct chx_value | cheax_splice_value_proc (struct chx_quote *splice) CHX_CONST |
size_t | cheax_strlen (CHEAX *c, struct chx_string *str) CHX_PURE |
Size of string in number of bytes. More... | |
struct chx_value | cheax_string (CHEAX *c, const char *value) |
Creates a cheax string expression. More... | |
struct chx_value | cheax_nstring (CHEAX *c, const char *value, size_t len) |
Creates a cheax string expression of given length. More... | |
struct chx_value | cheax_string_value_proc (struct chx_string *string) CHX_CONST |
struct chx_value | cheax_substr (CHEAX *c, struct chx_string *str, size_t pos, size_t len) |
Takes substring of given cheax string. More... | |
char * | cheax_strdup (struct chx_string *str) |
Allocates a null-terminated copy of given chx_string. More... | |
struct chx_value | cheax_user_ptr (CHEAX *c, void *value, int type) |
Creates a cheax user pointer expression. More... | |
struct chx_value | cheax_env (CHEAX *c) |
Currently active chx_env. More... | |
struct chx_value | cheax_env_value_proc (struct chx_env *env) CHX_CONST |
chx_ref | cheax_ref (CHEAX *c, struct chx_value value) |
Increase reference count on cheax value, preventing it from gc deletion when cheax_eval() is called. More... | |
chx_ref | cheax_ref_ptr (CHEAX *c, void *obj) |
void | cheax_unref (CHEAX *c, struct chx_value value, chx_ref ref) |
Decrease reference count on cheax value, potentially allowing it to be deleted by gc when cheax_eval() is called. More... | |
void | cheax_unref_ptr (CHEAX *c, void *obj, chx_ref ref) |
int | cheax_new_type (CHEAX *c, const char *name, int base_type) |
Creates a new type code as an alias for another. More... | |
int | cheax_find_type (CHEAX *c, const char *name) |
Looks up the type code of a named type. More... | |
bool | cheax_is_valid_type (CHEAX *c, int type) CHX_PURE |
Checks whether a given type code is valid. More... | |
bool | cheax_is_basic_type (CHEAX *c, int type) CHX_PURE |
Checks whether a given type code is a basic type. More... | |
bool | cheax_is_user_type (CHEAX *c, int type) CHX_PURE |
Checks whether a given type code is a user-defined type code. More... | |
int | cheax_get_base_type (CHEAX *c, int type) |
Gets the base type for a given type. More... | |
int | cheax_resolve_type (CHEAX *c, int type) |
Resolves the basic type to which a given type code refers. More... | |
Functions and datastructures to create, examine and manipulate cheax expressions and their types.
#define CHX_INT_MIN INT_LEAST64_MIN |
Minimum value for chx_int.
#define CHX_INT_MAX INT_LEAST64_MAX |
Maximum value for chx_int.
#define PRIdCHX PRIdLEAST64 |
Conversion specifier to print chx_int (decimal).
inttypes.h
to use this macro. #define PRIiCHX PRIiLEAST64 |
Conversion specifier to print chx_int (decimal).
inttypes.h
to use this macro. #define SCNdCHX SCNdLEAST64 |
Conversion specifier to scan chx_int (decimal).
inttypes.h
to use this macro. #define SCNiCHX SCNiLEAST64 |
Conversion specifier to scan chx_int (decimal).
inttypes.h
to use this macro. #define CHEAX_NIL ((struct chx_value){ 0 }) |
The nil
value.
Creates a chx_value of type CHEAX_INT.
value | Integral value for the object. |
#define cheax_true | ( | ) | ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = 1 }) |
Creates chx_value true
.
#define cheax_false | ( | ) | ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = 0 }) |
Creates chx_value false
.
#define cheax_bool | ( | X | ) | ((struct chx_value){ .type = CHEAX_BOOL, .data.as_int = (X) ? 1 : 0 }) |
Creates chx_value of type CHEAX_BOOL.
value | Boolean value for the object. |
#define cheax_double | ( | X | ) | ((struct chx_value){ .type = CHEAX_DOUBLE, .data.as_double = (X) }) |
Creates a chx_value of type CHEAX_DOUBLE.
value | Floating point value for the object. |
#define cheax_list_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_LIST, .data.as_list = (X) }) |
Turns chx_list into chx_value.
#define cheax_func_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_FUNC, .data.as_func = (X) }) |
#define cheax_ext_func_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_EXT_FUNC, .data.as_ext_func = (X) }) |
#define cheax_quote_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_QUOTE, .data.as_quote = (X) }) |
#define cheax_backquote_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_BACKQUOTE, .data.as_quote = (X) }) |
#define cheax_comma_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_COMMA, .data.as_quote = (X) }) |
#define cheax_splice_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_SPLICE, .data.as_quote = (X) }) |
#define cheax_string_value | ( | X | ) | ((struct chx_value){ .type = CHEAX_STRING, .data.as_string = (X) }) |
typedef int_least64_t chx_int |
Integer type.
typedef double chx_double |
Floating point type.
Type for C functions to be invoked from cheax.
args | The argument list as the function was invoked. The arguments are given as is, not pre-evaluated. E.g. if cheax passes an identifier to the function as an argument, it will apear as an identifier in the argument list, not as the value of the symbol it may represent. |
info | User-provided data. |
typedef int(* chx_tail_func_ptr) (CHEAX *c, struct chx_list *args, void *info, struct chx_env *pop_stop, union chx_eval_out *out) |
typedef int chx_ref |
anonymous enum |
Types of expressions within cheax.
Enumerator | |
---|---|
CHEAX_LIST | List type code. |
CHEAX_INT | Integral type code. |
CHEAX_BOOL | Boolean type code. |
CHEAX_DOUBLE | Floating point type code. |
CHEAX_USER_PTR | Type of user pointers defined from outside the cheax environment.
|
CHEAX_ID | Identifier type code. |
CHEAX_FUNC | Function type code. |
CHEAX_EXT_FUNC | Type code for functions defined through the C API. |
CHEAX_SPECIAL_OP | Type code for special operations, defined through the C API. |
CHEAX_QUOTE | Type for quoted expressions. |
CHEAX_BACKQUOTE | Type for backquoted expressions. |
CHEAX_COMMA | Type for comma expressions. |
CHEAX_SPLICE | Type for comma splice (i.e. ,@) expressions. |
CHEAX_STRING | String type. |
CHEAX_ENV | Environment type. |
CHEAX_LAST_BASIC_TYPE | |
CHEAX_TYPESTORE_BIAS | |
CHEAX_TYPECODE | The type of type codes themselves. A type alias of CHEAX_INT. |
CHEAX_ERRORCODE | Error code type. A type alias of CHEAX_INT. |
struct chx_value cheax_nil | ( | void | ) |
Creates a nil
value.
bool cheax_is_nil | ( | struct chx_value | v | ) |
Tests whether given value is nil
.
NULL
. Creates a chx_value of type CHEAX_ID.
id | Identifier value for the expression. |
Turns chx_id into chx_value. Like cheax_id_value(), but a function and not a macro.
Creates a chx_value of type CHEAX_INT. Like cheax_int(), but a function and not a macro.
struct chx_value cheax_bool_proc | ( | bool | value | ) |
Creates a chx_value of type CHEAX_BOOL. Like cheax_bool(), but a function and not a macro.
struct chx_value cheax_double_proc | ( | chx_double | value | ) |
Creates a chx_value of type CHEAX_DOUBLE. Like cheax_double(), but a function and not a macro.
Turns chx_list into chx_value. Like cheax_list_value(), but a function and not a macro.
struct chx_value cheax_ext_func | ( | CHEAX * | c, |
const char * | name, | ||
chx_func_ptr | perform, | ||
void * | info | ||
) |
Creates a cheax external/user function expression.
External functions, unlike special operators, have their arguments pre-evaluated.
perform | Function pointer to be invoked. |
name | Function name as will be used by cheax_print(). |
info | Callback info to be passed upon invocation. |
struct chx_value cheax_ext_func_value_proc | ( | struct chx_ext_func * | sf | ) |
Creates a quoted cheax expression.
value | Expression to be quoted. |
Creates a backquoted cheax expression.
value | Expression to be backquoted. |
Creates a cheax comma expression.
value | Expression following comma. |
Creates a cheax comma splice expression.
value | Expression following comma splice. |
size_t cheax_strlen | ( | CHEAX * | c, |
struct chx_string * | str | ||
) |
Size of string in number of bytes.
str | String. |
NULL
. Creates a cheax string expression.
value | Null-terminated value for the string. |
Creates a cheax string expression of given length.
value | Value for the string. |
len | Length of the string. |
struct chx_value cheax_string_value_proc | ( | struct chx_string * | string | ) |
Takes substring of given cheax string.
Sets cheax_errno() to CHEAX_EINDEX if substring is out of bounds.
str | Initial string. |
pos | Substring starting offset in number of bytes. |
len | Substring length in number of bytes. |
char* cheax_strdup | ( | struct chx_string * | str | ) |
Allocates a null-terminated copy of given chx_string.
Make sure to free() result after use.
str | String. |
NULL
if str is NULL
. Creates a cheax user pointer expression.
value | Pointer value for the expression. |
type | Type alias for the expression. Must not be a basic type, and must resolve to CHEAX_USER_PTR. |
Currently active chx_env.
NULL
if currently running in the global scope. struct chx_value cheax_env_value_proc | ( | struct chx_env * | env | ) |
Increase reference count on cheax value, preventing it from gc deletion when cheax_eval() is called.
Decrease reference count on cheax value, potentially allowing it to be deleted by gc when cheax_eval() is called.
int cheax_new_type | ( | CHEAX * | c, |
const char * | name, | ||
int | base_type | ||
) |
Creates a new type code as an alias for another.
Sets cheax_errno() to CHEAX_EAPI if
NULL
; name | Name for the new type code in the cheax environment. |
base_type | Base type code to create an alias for. |
int cheax_find_type | ( | CHEAX * | c, |
const char * | name | ||
) |
Looks up the type code of a named type.
Sets cheax_errno() to CHEAX_EAPI if name is NULL.
name | Type name. |
bool cheax_is_valid_type | ( | CHEAX * | c, |
int | type | ||
) |
Checks whether a given type code is valid.
type | Code to check. |
bool cheax_is_basic_type | ( | CHEAX * | c, |
int | type | ||
) |
Checks whether a given type code is a basic type.
type | Type code to check. |
bool cheax_is_user_type | ( | CHEAX * | c, |
int | type | ||
) |
Checks whether a given type code is a user-defined type code.
type | Type code to check. |
int cheax_get_base_type | ( | CHEAX * | c, |
int | type | ||
) |
Gets the base type for a given type.
The base type of a given type is either the type itself for basic types, or the type for which a user-defined type is an alias. Note that this operation is only applied once, and hence the return value is not necessarily a basic type.
Sets cheax_errno() to CHEAX_EEVAL if type could not be resolved.
type | Type code to get the base type of. |
int cheax_resolve_type | ( | CHEAX * | c, |
int | type | ||
) |
Resolves the basic type to which a given type code refers.
Progressively applies cheax_get_base_type() until a basic type is reached.
Sets cheax_errno() to CHEAX_EEVAL if type could not be resolved.
type | Type code to resolve. |