diff --git a/CMakeLists.txt b/CMakeLists.txt index b8bf799..5aff539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(libabacus) add_compile_options(-pedantic -Wall) -add_library(abacus STATIC src/lexer.c src/util.c src/table.c src/parser.c src/libabacus.c src/tree.c src/debug.c src/parsetype.c src/reserved.c src/trie.c src/refcount.c src/ref_vec.c src/ref_trie.c src/basetype.c src/value.c src/custom.c src/interpreter.c) +add_library(abacus STATIC src/lexer.c src/util.c src/table.c src/parser.c src/libabacus.c src/tree.c src/debug.c src/parsetype.c src/reserved.c src/trie.c src/refcount.c src/ref_vec.c src/ref_trie.c src/basetype.c src/value.c src/custom.c src/interpreter.c src/function_list.c) add_executable(libabacus src/main.c) add_subdirectory(external/liblex) diff --git a/include/function_list.h b/include/function_list.h new file mode 100644 index 0000000..8e4b291 --- /dev/null +++ b/include/function_list.h @@ -0,0 +1,17 @@ +#ifndef LIBABACUS_FUNCTION_LIST_H +#define LIBABACUS_FUNCTION_LIST_H + +#include "ref_vec.h" + +struct libab_function_list_s { + libab_ref_vec functions; +}; + +typedef struct libab_function_list_s libab_function_list; + +libab_result libab_function_list_init(libab_function_list* list); +libab_result libab_function_list_insert(libab_function_list* list, + libab_ref* function_value); +void libab_function_list_free(libab_function_list* list); + +#endif diff --git a/include/util.h b/include/util.h index d1af2ac..c8f7d87 100644 --- a/include/util.h +++ b/include/util.h @@ -6,6 +6,7 @@ #include "parsetype.h" #include "result.h" #include "table.h" +#include "function_list.h" #include /** @@ -80,5 +81,12 @@ libab_result libab_create_table(libab_ref* into, libab_ref* parent); * @return the result of necessary allocations. */ libab_result libab_create_value(libab_ref* into, void* data, libab_ref* type); +/** + * Creates a function list object, storing it in to the given reference. + * @param into the reference to store into. + * @param the function_list type. + * @return the result of the allocations. + */ +libab_result libab_create_function_list(libab_ref* into, libab_ref* type); #endif diff --git a/src/function_list.c b/src/function_list.c new file mode 100644 index 0000000..4400549 --- /dev/null +++ b/src/function_list.c @@ -0,0 +1,14 @@ +#include "function_list.h" + +libab_result libab_function_list_init(libab_function_list* list) { + return libab_ref_vec_init(&list->functions); +} + +libab_result libab_function_list_insert(libab_function_list* list, + libab_ref* function) { + return libab_ref_vec_insert(&list->functions, function); +} + +void libab_function_list_free(libab_function_list* list) { + libab_ref_vec_free(&list->functions); +} diff --git a/src/util.c b/src/util.c index 2b24bca..970b8ff 100644 --- a/src/util.c +++ b/src/util.c @@ -174,3 +174,29 @@ libab_result libab_create_value(libab_ref* into, void* data, libab_ref* type) { } return result; } + +libab_result libab_create_function_list(libab_ref* into, libab_ref* type) { + libab_function_list* list; + libab_result result = LIBAB_SUCCESS; + + if((list = malloc(sizeof(*list)))) { + result = libab_function_list_init(list); + } else { + result = LIBAB_MALLOC; + } + + if(result == LIBAB_SUCCESS) { + result = libab_create_value(into, list, type); + if(result != LIBAB_SUCCESS) { + libab_function_list_free(list); + libab_ref_free(into); + } + } + + if(result != LIBAB_SUCCESS) { + free(list); + libab_ref_null(into); + } + + return result; +}