mie: implemented array value type; restructure const value structures
there are now separate structs for all const types (int, string, etc), rather than a single mie_const union.
This commit is contained in:
49
mie/ctx.c
49
mie/ctx.c
@@ -1,4 +1,5 @@
|
||||
#include <blue/object/hashmap.h>
|
||||
#include <blue/object/list.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <mie/const.h>
|
||||
#include <mie/ctx.h>
|
||||
@@ -13,7 +14,7 @@ struct ctx_int_cache_entry {
|
||||
|
||||
struct ctx_int_value_cache_entry {
|
||||
b_btree_node i_node;
|
||||
struct mie_const i_value;
|
||||
struct mie_int i_value;
|
||||
};
|
||||
|
||||
B_BTREE_DEFINE_SIMPLE_INSERT(
|
||||
@@ -23,10 +24,10 @@ B_BTREE_DEFINE_SIMPLE_GET(
|
||||
get_cached_int_type)
|
||||
|
||||
B_BTREE_DEFINE_SIMPLE_INSERT(
|
||||
struct ctx_int_value_cache_entry, i_node, i_value.c_v.v_int,
|
||||
struct ctx_int_value_cache_entry, i_node, i_value.i_value,
|
||||
put_cached_int_value)
|
||||
B_BTREE_DEFINE_SIMPLE_GET(
|
||||
struct ctx_int_value_cache_entry, int64_t, i_node, i_value.c_v.v_int,
|
||||
struct ctx_int_value_cache_entry, int64_t, i_node, i_value.i_value,
|
||||
get_cached_int_value)
|
||||
|
||||
struct mie_ctx *mie_ctx_create(void)
|
||||
@@ -172,9 +173,8 @@ struct mie_value *mie_ctx_get_int(
|
||||
|
||||
memset(value, 0x0, sizeof *value);
|
||||
|
||||
mie_value_init(&value->i_value.c_base, MIE_VALUE_CONST);
|
||||
value->i_value.c_type = &entry->i_type;
|
||||
value->i_value.c_v.v_int = val;
|
||||
mie_const_init(&value->i_value.i_base, &entry->i_type);
|
||||
value->i_value.i_value = val;
|
||||
|
||||
put_cached_int_value(&entry->i_values, value);
|
||||
|
||||
@@ -195,16 +195,16 @@ struct mie_value *mie_ctx_get_selector(struct mie_ctx *ctx, const char *sel)
|
||||
return cache_entry->value_data;
|
||||
}
|
||||
|
||||
struct mie_const *sel_value = malloc(sizeof *sel_value);
|
||||
struct mie_selector *sel_value = malloc(sizeof *sel_value);
|
||||
if (!sel_value) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_value_init(&sel_value->c_base, MIE_VALUE_CONST);
|
||||
sel_value->c_type = mie_ctx_get_type(ctx, MIE_TYPE_SELECTOR);
|
||||
sel_value->c_v.v_selector = b_strdup(sel);
|
||||
struct mie_type *sel_type = mie_ctx_get_type(ctx, MIE_TYPE_SELECTOR);
|
||||
mie_const_init(&sel_value->sel_base, sel_type);
|
||||
sel_value->sel_value = b_strdup(sel);
|
||||
|
||||
key.key_data = sel_value->c_v.v_selector;
|
||||
key.key_data = sel_value->sel_value;
|
||||
|
||||
b_hashmap_value hashmap_value = {
|
||||
.value_data = sel_value,
|
||||
@@ -230,16 +230,16 @@ struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
|
||||
return cache_entry->value_data;
|
||||
}
|
||||
|
||||
struct mie_const *string_value = malloc(sizeof *string_value);
|
||||
struct mie_string *string_value = malloc(sizeof *string_value);
|
||||
if (!string_value) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_value_init(&string_value->c_base, MIE_VALUE_CONST);
|
||||
string_value->c_type = mie_ctx_get_type(ctx, MIE_TYPE_STR);
|
||||
string_value->c_v.v_str = b_strdup(s);
|
||||
struct mie_type *string_type = mie_ctx_get_type(ctx, MIE_TYPE_STR);
|
||||
mie_const_init(&string_value->s_base, string_type);
|
||||
string_value->s_value = b_strdup(s);
|
||||
|
||||
key.key_data = string_value->c_v.v_str;
|
||||
key.key_data = string_value->s_value;
|
||||
|
||||
b_hashmap_value hashmap_value = {
|
||||
.value_data = string_value,
|
||||
@@ -250,3 +250,20 @@ struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
|
||||
|
||||
return MIE_VALUE(string_value);
|
||||
}
|
||||
|
||||
struct mie_value *mie_ctx_create_array(struct mie_ctx *ctx)
|
||||
{
|
||||
struct mie_type *array_type = mie_ctx_get_type(ctx, MIE_TYPE_ARRAY);
|
||||
struct mie_array *array = malloc(sizeof *array);
|
||||
|
||||
if (!array) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(array, 0x0, sizeof *array);
|
||||
mie_const_init(&array->a_base, array_type);
|
||||
|
||||
array->a_values = b_list_create();
|
||||
|
||||
return MIE_VALUE(array);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user