diff --git a/include/impl.h b/include/impl.h new file mode 100644 index 0000000..d4f31c8 --- /dev/null +++ b/include/impl.h @@ -0,0 +1,16 @@ +#ifndef LIBABACUS_IMPL_H +#define LIBABACUS_IMPL_H + +/** + * Implementation functions for things like numbers. + */ +struct libab_impl_s { + /** + * Function to parse a number from a string. + */ + void* (*parse_num)(const char*); +}; + +typedef struct libab_impl_s libab_impl; + +#endif diff --git a/include/interpreter.h b/include/interpreter.h index 62bd817..f0eee73 100644 --- a/include/interpreter.h +++ b/include/interpreter.h @@ -3,15 +3,18 @@ #include "table.h" #include "tree.h" +#include "impl.h" struct libab_interpreter_s { libab_ref base_table; + libab_impl* impl; }; typedef struct libab_interpreter_s libab_interpreter; void libab_interpreter_init(libab_interpreter* intr, - libab_ref* table); + libab_ref* table, + libab_impl* impl); libab_result libab_interpreter_run(libab_interpreter* intr, libab_tree* tree, libab_ref* into); void libab_interpreter_free(libab_interpreter* intr); diff --git a/include/libabacus.h b/include/libabacus.h index 998a79b..4c425a0 100644 --- a/include/libabacus.h +++ b/include/libabacus.h @@ -8,6 +8,7 @@ #include "interpreter.h" #include "result.h" #include "table.h" +#include "impl.h" /** * The main struct of libabacus, @@ -35,6 +36,11 @@ struct libab_s { * things like functions and operators. */ libab_ref table; + + /** + * The allocator used to construct number instances. + */ + libab_impl impl; }; typedef struct libab_s libab; diff --git a/src/interpreter.c b/src/interpreter.c index 2fa5a82..cc496ff 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -2,18 +2,22 @@ #include "util.h" void libab_interpreter_init(libab_interpreter* intr, - libab_ref* table) { + libab_ref* table, + libab_impl* impl) { libab_ref_copy(table, &intr->base_table); + intr->impl = impl; } struct interpreter_state { libab_ref num_ref; + libab_impl* impl; }; libab_result _interpreter_init(struct interpreter_state* state, libab_interpreter* intr) { libab_result result = LIBAB_SUCCESS; libab_basetype* num_type; libab_ref_null(&state->num_ref); + state->impl = intr->impl; num_type = libab_table_search_basetype(libab_ref_get(&intr->base_table), "num"); if(num_type != NULL) { diff --git a/src/libabacus.c b/src/libabacus.c index 9956686..6283853 100644 --- a/src/libabacus.c +++ b/src/libabacus.c @@ -12,7 +12,7 @@ libab_result libab_init(libab* ab) { if(result == LIBAB_SUCCESS) { libab_parser_init(&ab->parser, &ab->table); - libab_interpreter_init(&ab->intr, &ab->table); + libab_interpreter_init(&ab->intr, &ab->table, &ab->impl); result = libab_lexer_init(&ab->lexer); }