85 lines
2.0 KiB
C
85 lines
2.0 KiB
C
#include <mie/data.h>
|
|
#include <mie/func.h>
|
|
#include <mie/module.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
struct mie_module *mie_module_create(void)
|
|
{
|
|
struct mie_module *out = malloc(sizeof *out);
|
|
if (!out) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(out, 0x0, sizeof *out);
|
|
|
|
mie_value_init(&out->m_base, MIE_VALUE_MODULE);
|
|
|
|
return out;
|
|
}
|
|
|
|
void mie_module_add_function(struct mie_module *mod, struct mie_func *func)
|
|
{
|
|
b_queue_push_back(&mod->m_func, &func->f_base.v_entry);
|
|
}
|
|
|
|
struct mie_data *mie_module_get_data(struct mie_module *mod, const char *name)
|
|
{
|
|
b_queue_iterator it;
|
|
b_queue_foreach (&it, &mod->m_data) {
|
|
struct mie_data *data = (struct mie_data *)b_unbox(
|
|
struct mie_value, it.entry, v_entry);
|
|
if (!strcmp(data->d_base.v_name.n_str, name)) {
|
|
return data;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
enum b_status mie_module_put_data(struct mie_module *mod, struct mie_data *data)
|
|
{
|
|
/* TODO enforce unique names */
|
|
b_queue_push_back(&mod->m_data, &data->d_base.v_entry);
|
|
return B_SUCCESS;
|
|
}
|
|
|
|
static void cleanup(struct mie_value *value)
|
|
{
|
|
struct mie_module *module = MIE_MODULE(value);
|
|
|
|
b_queue_iterator it;
|
|
b_queue_iterator_begin(&module->m_records, &it);
|
|
while (b_queue_iterator_is_valid(&it)) {
|
|
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
|
b_queue_iterator_erase(&it);
|
|
mie_value_destroy(v);
|
|
}
|
|
|
|
b_queue_iterator_begin(&module->m_data, &it);
|
|
while (b_queue_iterator_is_valid(&it)) {
|
|
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
|
b_queue_iterator_erase(&it);
|
|
mie_value_destroy(v);
|
|
}
|
|
|
|
b_queue_iterator_begin(&module->m_types, &it);
|
|
while (b_queue_iterator_is_valid(&it)) {
|
|
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
|
b_queue_iterator_erase(&it);
|
|
mie_value_destroy(v);
|
|
}
|
|
|
|
b_queue_iterator_begin(&module->m_func, &it);
|
|
while (b_queue_iterator_is_valid(&it)) {
|
|
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
|
b_queue_iterator_erase(&it);
|
|
mie_value_destroy(v);
|
|
}
|
|
}
|
|
|
|
const struct mie_value_type module_value_type = {
|
|
.t_id = MIE_VALUE_MODULE,
|
|
.t_cleanup = cleanup,
|
|
};
|