|
libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
|
Compiler for SNOBOL pattern AST to bytecode. More...


Go to the source code of this file.
Functions | |
| int | compile_ast_to_bytecode_c (ast_node_t *ast, bool case_insensitive, uint8_t **out_bc, size_t *out_len) |
| const char * | compile_ast_error (void) |
| int | compile_template_to_bytecode (const char *tpl, size_t len, uint8_t **out_bc, size_t *out_len) |
| void | compiler_free (uint8_t *bc) |
| int | snobol_template_bind_tables (uint8_t *bc, size_t bc_len, const char **names, const uint16_t *ids, size_t n) |
Compiler for SNOBOL pattern AST to bytecode.
Accepts C AST (ast_node_t*) from the C-based parser and compiles to bytecode.
Definition in file compiler.h.
| const char * compile_ast_error | ( | void | ) |
Last specific error from compile_ast_to_bytecode_c().
| int compile_ast_to_bytecode_c | ( | ast_node_t * | ast, |
| bool | case_insensitive, | ||
| uint8_t ** | out_bc, | ||
| size_t * | out_len ) |
Compile AST to bytecode
| ast | AST node to compile |
| case_insensitive | Enable case-insensitive matching |
| out_bc | Output bytecode buffer (allocated, caller must free via compiler_free()) |
| out_len | Output bytecode length |
| int compile_template_to_bytecode | ( | const char * | tpl, |
| size_t | len, | ||
| uint8_t ** | out_bc, | ||
| size_t * | out_len ) |
Compile template string to bytecode
| tpl | Template string |
| len | Template length |
| out_bc | Output bytecode buffer (allocated, caller must free via compiler_free()) |
| out_len | Output bytecode length |
| void compiler_free | ( | uint8_t * | bc | ) |
Free compiled bytecode
| bc | Bytecode buffer to free |
| int snobol_template_bind_tables | ( | uint8_t * | bc, |
| size_t | bc_len, | ||
| const char ** | names, | ||
| const uint16_t * | ids, | ||
| size_t | n ) |
Resolve symbolic table names embedded in compiled template bytecode.
Walks bc looking for OP_EMIT_TABLE instructions whose table_id equals SNBL_TABLE_ID_UNBOUND (0xFFFF). For each such instruction the embedded name is compared against the names array; on a match the table_id field is patched in-place with the corresponding entry from ids.
The function patches as many entries as it can. If any name cannot be resolved it leaves the table_id at SNBL_TABLE_ID_UNBOUND and returns -1 after processing the entire bytecode.
Binding is a one-shot operation: already-bound entries (table_id != 0xFFFF) are left unchanged. The caller is responsible for external synchronisation if bc may be shared across threads.
| bc | Mutable compiled template bytecode buffer |
| bc_len | Length of bc in bytes |
| names | Array of n C-string table names (may be NULL entries) |
| ids | Array of n table IDs corresponding to names |
| n | Number of entries in names and ids |