maug
Quick and dirty C mini-augmentation library.
mlisps.h
Go to the documentation of this file.
1
2#ifndef MLISPS_H
3#define MLISPS_H
4
13#ifndef MLISP_TRACE_LVL
14# define MLISP_TRACE_LVL 0
15#endif /* !MLISP_TRACE_LVL */
16
17#ifndef MLISP_EXEC_ENV_FRAME_CT_MAX
18# define MLISP_EXEC_ENV_FRAME_CT_MAX 10
19#endif /* !MLISP_EXEC_ENV_FRAME_CT_MAX */
20
21#ifndef MLISP_TRACE_SIGIL
22# define MLISP_TRACE_SIGIL "TRACE"
23#endif /* !MLISP_TRACE_SIGIL */
24
25#ifndef MLISP_AST_IDX_CHILDREN_MAX
26# define MLISP_AST_IDX_CHILDREN_MAX 10
27#endif /* !MLISP_AST_IDX_CHILDREN_MAX */
28
34#define MLISP_EXEC_FLAG_TRANSIENT_MASK 0x0f
35
41#define MLISP_EXEC_FLAG_DEF_TERM 0x20
42
43#define MLISP_EXEC_FLAG_INITIALIZED 0x08
44
50typedef ssize_t mlisp_lambda_t;
51
52typedef mlisp_lambda_t mlisp_args_t;
53typedef mlisp_lambda_t mlisp_arge_t;
54typedef mlisp_lambda_t mlisp_if_t;
55typedef mlisp_lambda_t mlisp_begin_t;
56
57typedef uint8_t mlisp_bool_t;
58
64#define MLISP_NUM_TYPE_TABLE( f ) \
65 f( 1, int16_t, integer, INT, "%d" ) \
66 f( 2, float, floating, FLOAT, "%f" ) \
67 f( 3, mlisp_bool_t, boolean, BOOLEAN, "%u" )
68
74#define MLISP_TYPE_TABLE( f ) \
75 MLISP_NUM_TYPE_TABLE( f ) \
76 f( 4, mdata_strpool_idx_t, strpool_idx, STR, SIZE_T_FMT ) \
77 f( 5, mlisp_env_cb_t, cb, CB, "%p" ) \
78 f( 6, mlisp_lambda_t, lambda, LAMBDA, SSIZE_T_FMT ) \
79 f(10, mlisp_begin_t, begin, BEGIN, SSIZE_T_FMT )
80 /* mlisp_types */
82
83struct MLISP_PARSER;
84struct MLISP_EXEC_STATE;
85
93 struct MLISP_PARSER* parser, struct MLISP_EXEC_STATE* exec, size_t n_idx,
94 size_t args_c, uint8_t* cb_data, uint8_t flags );
95
96#define _MLISP_TYPE_TABLE_FIELDS( idx, ctype, name, const_name, fmt ) \
97 ctype name;
98
99/* We need to ignore this since it builds the fields with the preprocessor and
100 * the meta-serializer doesn't support that.
101 */
102/* mserial_ignore_until_next_cbrace */
104 MLISP_TYPE_TABLE( _MLISP_TYPE_TABLE_FIELDS )
105};
106
108 uint8_t flags;
109 uint8_t type;
110 union MLISP_VAL value;
111};
112
114 uint8_t type;
115 union MLISP_VAL value;
116};
117
119 uint8_t flags;
120 mdata_strpool_idx_t token_idx;
121 size_t token_sz;
122 ssize_t ast_idx_parent;
123 ssize_t env_idx_op;
124 ssize_t ast_idx_children[MLISP_AST_IDX_CHILDREN_MAX];
127};
128
137 /* serial_prepare_cb mlisp_deserialize_prepare_EXEC_STATE */
138 uint16_t uid;
140 uint8_t flags;
142 /* vector_type size_t */
150 /* vector_type size_t */
153 /* vector_type struct MLISP_STACK_NODE */
170 /* table_type struct MLISP_ENV_NODE */
171 struct MDATA_TABLE env[MLISP_EXEC_ENV_FRAME_CT_MAX];
178 int8_t no_serial;
183 /* vector_type size_t */
190 union MAUG_MHANDLEPTR cb_attachment;
191#ifdef MLISP_DEBUG_TRACE
192 size_t trace[MLISP_DEBUG_TRACE];
193 size_t trace_depth;
194#endif /* MLISP_DEBUG_TRACE */
195 /* table_type struct MLISP_ENV_NODE */
196 struct MDATA_TABLE* global_env;
197};
198
200 struct MPARSER base;
201 struct MDATA_STRPOOL strpool;
202 struct MDATA_VECTOR ast;
208};
209 /* mlisp */
211
212#endif /* !MLISPS_H */
213
uint16_t MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition: merror.h:19
#define MLISP_TYPE_TABLE(f)
Table of other types.
Definition: mlisps.h:74
MERROR_RETVAL(* mlisp_env_cb_t)(struct MLISP_PARSER *parser, struct MLISP_EXEC_STATE *exec, size_t n_idx, size_t args_c, uint8_t *cb_data, uint8_t flags)
A callback to attach to an mlisp command with mlisp_env_set() with MLISP_TYPE_CB.
Definition: mlisps.h:92
A pool of immutable text strings. Deduplicates strings to save memory.
Definition: mdata.h:68
Definition: mdata.h:127
A vector of uniformly-sized objects, stored contiguously.
Definition: mdata.h:93
Definition: mlisps.h:118
size_t ast_idx_children_sz
Number of children in MLISP_AST_NODE::ast_idx_children.
Definition: mlisps.h:126
Definition: mlisps.h:107
Current execution state to associate with a MLISP_PARSER.
Definition: mlisps.h:136
struct MDATA_VECTOR lambda_trace
Path through any lambdas the execution has entered during this heartbeat cycle. Used to detect tail c...
Definition: mlisps.h:184
int8_t no_serial
Dummy field; do not serialize fields after this!
Definition: mlisps.h:178
struct MDATA_VECTOR per_node_child_idx
The hild index that will be visited on next visit of each node.
Definition: mlisps.h:151
struct MDATA_VECTOR per_node_visit_ct
The number of times each node has been visited ever.
Definition: mlisps.h:143
struct MDATA_VECTOR stack
A stack of data values resulting from evaluating statements.
Definition: mlisps.h:154
uint8_t flags
Flags which dictate the behavior of this object.
Definition: mlisps.h:140
union MAUG_MHANDLEPTR cb_attachment
Handle/pointer for use by addtional native callbacks. This is not used within mlisp or its builtin ca...
Definition: mlisps.h:190
struct MDATA_TABLE env[MLISP_EXEC_ENV_FRAME_CT_MAX]
Environment in which statements are defined if ::MLISP_.
Definition: mlisps.h:171
int8_t env_select
The current topmost frame of MLISP_EXEC_STATE::env. Please see that for more information.
Definition: mlisps.h:176
Definition: mlisps.h:199
ssize_t ast_node_iter
Definitions to use if MLISP_EXEC_FLAG_DEF_TERM is defined on the accompanying MLISP_EXEC_STATE::flags...
Definition: mlisps.h:207
Definition: mlisps.h:113
Definition: mlisps.h:103