diff --git a/include/table.h b/include/table.h index 8164231..aae5415 100644 --- a/include/table.h +++ b/include/table.h @@ -3,6 +3,7 @@ #include "ht.h" #include "result.h" +#include "custom.h" /** * A struct that represents a structure @@ -29,6 +30,7 @@ struct libab_table_s { enum libab_table_entry_variant_e { ENTRY_VALUE, ENTRY_TYPE, + ENTRY_OPERATOR, ENTRY_FUNCTION }; @@ -40,6 +42,14 @@ struct libab_table_entry_s { * The type of this entry. */ enum libab_table_entry_variant_e variant; + /** + * Union that holds the various types of + * data that this entry could hold. + */ + union { + libab_operator op; + libab_function function; + } data_u; }; typedef struct libab_table_s libab_table; @@ -58,6 +68,14 @@ void libab_table_init(libab_table* table); * @return the table entry, or NULL if an entry was not found. */ libab_table_entry* libab_table_search(libab_table* table, const char* string); +/** + * Stores the given entry in the table under the given key. + * @param table the table to store the entry into. + * @param string the string to use as the key. + * @param entry the new entry to put into the table. + * @return the result of the insertion, which could be LIBAB_MALLOC. + */ +libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry); /** * Frees the resources allocated by the * given table. diff --git a/src/table.c b/src/table.c index adb13f3..eb9181f 100644 --- a/src/table.c +++ b/src/table.c @@ -1,5 +1,6 @@ #include "table.h" #include +#include "util.h" void table_init(libab_table* table) { ht_init(&table->table); @@ -13,6 +14,9 @@ libab_table_entry* table_search(libab_table* table, const char* string) { } while(table && to_return == NULL); return to_return; } +libab_result libab_table_put(libab_table* table, const char* string, libab_table_entry* entry) { + return libab_convert_ds_result(ht_put(&table->table, string, entry)); +} void table_free(libab_table* table) { ht_free(&table->table); }