From 22ed67f0a4f0628c5df14bc937fa78553679663d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 21 Apr 2018 13:54:28 -0700 Subject: [PATCH] Add a description of the internal array data structure. --- CMakeLists.txt | 2 +- include/types.h | 38 ++++++++++++++++++++++++++++++++++++++ src/types.c | 13 +++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 include/types.h create mode 100644 src/types.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c113045..b4278e6 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) +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/types.c) add_executable(libabacus src/main.c) add_subdirectory(external/liblex) diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..0c6bc3a --- /dev/null +++ b/include/types.h @@ -0,0 +1,38 @@ +#ifndef LIBABACUS_TYPES_H +#define LIBABACUS_TYPES_H + +#include "ref_vec.h" + +/** + * A struct that represents an array + * in libab. + */ +struct libab_array_s { + /** + * The elements in the array. + */ + libab_ref_vec elems; +}; + +typedef struct libab_array_s libab_array; + +/** + * Initializes the array. + * @param array the array to initialize. + * @return the result of the initialization. + */ +libab_result libab_array_init(libab_array* array); +/** + * Inserts an element into the array. + * @param array the array to insert. + * @param value the interpreter value to insert. + * @return the result of the insertion. + */ +libab_result libab_array_insert(libab_array* array, libab_ref* value); +/** + * Frees the given array. + * @param array the array to free. + */ +void libab_array_free(libab_array* array); + +#endif diff --git a/src/types.c b/src/types.c new file mode 100644 index 0000000..c523354 --- /dev/null +++ b/src/types.c @@ -0,0 +1,13 @@ +#include "types.h" + +libab_result libab_array_init(libab_array* array) { + return libab_ref_vec_init(&array->elems); +} + +libab_result libab_array_insert(libab_array* array, libab_ref* value) { + return libab_ref_vec_insert(&array->elems, value); +} + +void libab_array_free(libab_array* array) { + libab_ref_vec_free(&array->elems); +}