Add a description of the internal array data structure.

This commit is contained in:
Danila Fedorin 2018-04-21 13:54:28 -07:00
parent 30578f27da
commit 22ed67f0a4
3 changed files with 52 additions and 1 deletions

View File

@ -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)

38
include/types.h Normal file
View File

@ -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

13
src/types.c Normal file
View File

@ -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);
}