mie: ctx: add int, string, and index value caches

This commit is contained in:
2026-01-04 18:58:04 +00:00
parent 9d80d94244
commit 5b06934e85
2 changed files with 35 additions and 9 deletions

View File

@@ -1,8 +1,12 @@
#include <blue/core/bstr.h>
#include <blue/ds/hashmap.h>
#include <blue/ds/list.h>
#include <blue/ds/string.h>
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/index.h>
#include <mie/dialect/type.h>
#include <mie/ir/op.h>
#include <mie/type/type.h>
@@ -312,6 +316,10 @@ struct mie_ctx *mie_ctx_create(void)
mie_id types_ns = TYPE_NS_ID;
mie_id_map_init(&out->ctx_types, &types_ns);
out->ctx_ints = mie_int_cache_create();
out->ctx_indices = mie_index_cache_create();
out->ctx_strings = mie_string_cache_create();
return out;
}
@@ -439,3 +447,19 @@ struct mie_type *mie_ctx_get_type(
return type;
}
struct mie_value *mie_ctx_get_int(struct mie_ctx *ctx, long long val, size_t nr_bits)
{
return (struct mie_value *)mie_int_cache_get(
ctx->ctx_ints, ctx, val, nr_bits);
}
struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
{
return (struct mie_value *)mie_string_cache_get(ctx->ctx_strings, ctx, s);
}
struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
{
return (struct mie_value *)mie_index_cache_get(ctx->ctx_indices, ctx, val);
}

View File

@@ -6,6 +6,10 @@
#include <mie/id.h>
struct mie_op;
struct mie_int_cache;
struct mie_index_cache;
struct mie_string_cache;
;
struct mie_ctx {
#if 0
@@ -17,9 +21,10 @@ struct mie_ctx {
#endif
struct mie_id_map ctx_dialects;
struct mie_id_map ctx_types;
b_btree ctx_int_cache;
b_btree ctx_float_cache;
b_btree ctx_index_cache;
struct mie_int_cache *ctx_ints;
struct mie_index_cache *ctx_indices;
struct mie_string_cache *ctx_strings;
};
MIE_API struct mie_ctx *mie_ctx_create(void);
@@ -34,15 +39,12 @@ MIE_API struct mie_dialect_type *mie_ctx_get_dialect_type(
MIE_API struct mie_type *mie_ctx_get_type(
struct mie_ctx *ctx, const char *dialect_name, const char *type_name);
MIE_API struct mie_type *mie_ctx_get_int_type(
struct mie_ctx *ctx, unsigned int nr_bits);
MIE_API struct mie_type *mie_ctx_get_float_type(
struct mie_ctx *ctx, unsigned int nr_bits);
MIE_API struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx);
MIE_API struct mie_value *mie_ctx_get_int(
struct mie_ctx *ctx, long long val, unsigned int nr_bits);
struct mie_ctx *ctx, long long val, size_t nr_bits);
MIE_API struct mie_value *mie_ctx_get_float(
struct mie_ctx *ctx, double val, unsigned int nr_bits);
struct mie_ctx *ctx, double val, size_t nr_bits);
MIE_API struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s);
MIE_API struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val);
#endif