Add a function list that's used for searching functions by name.

This commit is contained in:
Danila Fedorin 2018-04-26 19:16:20 -07:00
parent c46b82584d
commit 785a362f97
5 changed files with 66 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 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)

17
include/function_list.h Normal file
View File

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

View File

@ -6,6 +6,7 @@
#include "parsetype.h"
#include "result.h"
#include "table.h"
#include "function_list.h"
#include <string.h>
/**
@ -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

14
src/function_list.c Normal file
View File

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

View File

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