diff --git a/CMakeLists.txt b/CMakeLists.txt index 4547d95..b630868 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) +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) add_executable(libabacus src/main.c) add_subdirectory(external/liblex) diff --git a/include/basetype.h b/include/basetype.h new file mode 100644 index 0000000..1ccbade --- /dev/null +++ b/include/basetype.h @@ -0,0 +1,65 @@ +#ifndef LIBABACUS_BASETYPE_H +#define LIBABACUS_BASETYPE_H + +#include "vec.h" +#include "result.h" + +/** + * An enum that represents the various + * types of the basetype parameters. + */ +enum libab_basetype_variant_e { + BT_EMPTY, + BT_NAME, + BT_LIST +}; + +/** + * A struct that holds information about the basetype + * parameter, such as a type name or a "..." (called a list). + */ +struct libab_basetype_param_s { + /** + * The variant of this type parameter. + */ + enum libab_basetype_variant_e variant; + /** + * The name of the parameter, if one is appropriate. + */ + const char* name; +}; + +/** + * A struct that holds all the information about a base type. + */ +struct libab_basetype_s { + /** + * The function used to free the value. + */ + void (*free_function)(void*); + /** + * The parameters of the type. This is a constant array, and + * doesn't need memory allocation. + */ + const struct libab_basetype_param_s* params; + /** + * The size of the param aray. + */ + int count; +}; + +typedef enum libab_basetype_variant_e libab_basetype_variant; +typedef struct libab_basetype_param_s libab_basetype_param; +typedef struct libab_basetype_s libab_basetype; + +/** + * Initializes a base type, including all the parameters that it needs + * to take. + * @param basetype the type that is being initialized. + * @param n the number of type parameters it has. + * @param params the parameters this basetype accepts. + */ +void libab_basetype_init(libab_basetype* basetype, int n, + const libab_basetype_param params[]); + +#endif diff --git a/src/basetype.c b/src/basetype.c new file mode 100644 index 0000000..2b121a1 --- /dev/null +++ b/src/basetype.c @@ -0,0 +1,10 @@ +#include "basetype.h" +#include "util.h" +#include + +void libab_basetype_init(libab_basetype* basetype, + int n, const libab_basetype_param params[]) { + basetype->params = params; + basetype->count = n; +} +