Compare commits
10 Commits
79ab1c175b
...
5b06934e85
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b06934e85 | |||
| 9d80d94244 | |||
| 3c2ca0f70e | |||
| aad2cad0a8 | |||
| 8b3093411a | |||
| 7c7e5e7af0 | |||
| 9126edfd57 | |||
| 3c9506256d | |||
| add09d4958 | |||
| 7b6ce3bf6e |
72
mie/ctx.c
72
mie/ctx.c
@@ -1,10 +1,15 @@
|
||||
#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>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -311,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;
|
||||
}
|
||||
|
||||
@@ -391,3 +400,66 @@ struct mie_dialect_type *mie_ctx_get_dialect_type(
|
||||
|
||||
return b_unbox(struct mie_dialect_type, target, ty_id);
|
||||
}
|
||||
|
||||
struct mie_type *mie_ctx_get_type(
|
||||
struct mie_ctx *ctx, const char *dialect_name, const char *type_name)
|
||||
{
|
||||
char full_name[256];
|
||||
snprintf(full_name, sizeof full_name, "%s.%s", dialect_name, dialect_name);
|
||||
b_rope full_name_rope = B_ROPE_CSTR(full_name);
|
||||
|
||||
mie_id id;
|
||||
mie_id_init_ns(&id, mie_id_map_get_ns(&ctx->ctx_types), &full_name_rope);
|
||||
|
||||
mie_id *target = mie_id_map_get(&ctx->ctx_types, &id);
|
||||
struct mie_type *type = b_unbox(struct mie_type, target, ty_id);
|
||||
if (type) {
|
||||
return type;
|
||||
}
|
||||
|
||||
struct mie_dialect_type *type_info
|
||||
= mie_ctx_get_dialect_type(ctx, dialect_name, type_name);
|
||||
if (!type_info || (type_info->ty_flags & MIE_DIALECT_TYPE_PARAMETISED)) {
|
||||
/* cannot initialise unknown or parametised types */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type_info->ty_data_size < sizeof(struct mie_type)) {
|
||||
/* invalid type info */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type = malloc(type_info->ty_data_size);
|
||||
if (!type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(type, 0x0, sizeof *type);
|
||||
|
||||
type->ty_def = type_info;
|
||||
type->ty_name = b_bstr_fmt("%s.%s", dialect_name, type_name);
|
||||
|
||||
if (type_info->ty_init) {
|
||||
type_info->ty_init(type_info, type);
|
||||
}
|
||||
|
||||
mie_id_map_put(&ctx->ctx_types, &type->ty_id, &full_name_rope);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
18
mie/dialect/arith/addf.c
Normal file
18
mie/dialect/arith/addf.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_arith_addf, "addf")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
18
mie/dialect/arith/addi.c
Normal file
18
mie/dialect/arith/addi.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_arith_addi, "addi")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
9
mie/dialect/arith/arith.c
Normal file
9
mie/dialect/arith/arith.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_arith, "arith")
|
||||
MIE_DIALECT_ADD_TYPE(mie_arith_int);
|
||||
MIE_DIALECT_ADD_TYPE(mie_arith_float);
|
||||
MIE_DIALECT_ADD_OP(mie_arith_addi);
|
||||
MIE_DIALECT_ADD_OP(mie_arith_addf);
|
||||
MIE_DIALECT_END()
|
||||
89
mie/dialect/arith/float.c
Normal file
89
mie/dialect/arith/float.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <blue/core/bstr.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
struct float_type {
|
||||
struct mie_type f_base;
|
||||
size_t f_width;
|
||||
};
|
||||
|
||||
static void value_print(
|
||||
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
|
||||
{
|
||||
struct float_type *float_ty = (struct float_type *)ty;
|
||||
struct mie_float *float_val = (struct mie_float *)value;
|
||||
switch (float_ty->f_width) {
|
||||
case MIE_FLOAT_32:
|
||||
b_stream_write_fmt(
|
||||
out, NULL, "%f : f%zu", float_val->f_val.v_32,
|
||||
float_ty->f_width);
|
||||
break;
|
||||
case MIE_FLOAT_64:
|
||||
b_stream_write_fmt(
|
||||
out, NULL, "%lf : f%zu", float_val->f_val.v_64,
|
||||
float_ty->f_width);
|
||||
break;
|
||||
default:
|
||||
b_stream_write_fmt(out, NULL, "NaN : f%zu", float_ty->f_width);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
{
|
||||
struct mie_dialect_type *type_info
|
||||
= mie_ctx_get_dialect_type(ctx, "arith", "float");
|
||||
if (!type_info) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_rope rope_i = B_ROPE_CHAR('f'), rope_width = B_ROPE_UINT(bit_width);
|
||||
b_rope type_name;
|
||||
b_rope_concat(&type_name, &rope_i, &rope_width);
|
||||
|
||||
mie_id id;
|
||||
mie_id_init_ns(&id, mie_id_map_get_ns(&ctx->ctx_types), &type_name);
|
||||
|
||||
mie_id *target = mie_id_map_get(&ctx->ctx_types, &id);
|
||||
if (target) {
|
||||
return b_unbox(struct mie_type, target, ty_id);
|
||||
}
|
||||
|
||||
struct float_type *type = (struct float_type *)mie_type_create(type_info);
|
||||
if (!type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->f_base.ty_name = b_bstr_fmt("arith.float<%zu>", bit_width);
|
||||
type->f_width = bit_width;
|
||||
type->f_base.ty_instance_size = sizeof(struct mie_float);
|
||||
type->f_base.ty_value_print = value_print;
|
||||
|
||||
mie_id_map_put(&ctx->ctx_types, &type->f_base.ty_id, &type_name);
|
||||
return (struct mie_type *)type;
|
||||
}
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
const struct mie_dialect_type *def, struct mie_parser *parser,
|
||||
struct mie_type **out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_TYPE_BEGIN(mie_arith_float, "float")
|
||||
MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
|
||||
MIE_DIALECT_TYPE_STRUCT(struct float_type);
|
||||
MIE_DIALECT_TYPE_PRINT(print);
|
||||
MIE_DIALECT_TYPE_PARSE(parse);
|
||||
MIE_DIALECT_TYPE_END()
|
||||
139
mie/dialect/arith/int-cache.c
Normal file
139
mie/dialect/arith/int-cache.c
Normal file
@@ -0,0 +1,139 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct int_width_cache_entry {
|
||||
b_btree_node e_node;
|
||||
struct mie_int e_value;
|
||||
};
|
||||
|
||||
struct int_width_cache {
|
||||
b_btree_node c_node;
|
||||
size_t c_width;
|
||||
b_btree c_ints;
|
||||
};
|
||||
|
||||
struct mie_int_cache {
|
||||
b_btree c_widths;
|
||||
};
|
||||
|
||||
static B_BTREE_DEFINE_SIMPLE_INSERT(
|
||||
struct int_width_cache, c_node, c_width, put_width_cache);
|
||||
static B_BTREE_DEFINE_SIMPLE_GET(
|
||||
struct int_width_cache, size_t, c_node, c_width, get_width_cache);
|
||||
|
||||
static B_BTREE_DEFINE_SIMPLE_INSERT(
|
||||
struct int_width_cache_entry, e_node, e_value.i_val.v_small, put_int);
|
||||
static B_BTREE_DEFINE_SIMPLE_GET(
|
||||
struct int_width_cache_entry, uint64_t, e_node, e_value.i_val.v_small,
|
||||
get_int);
|
||||
|
||||
static struct int_width_cache *int_width_cache_create(size_t width)
|
||||
{
|
||||
struct int_width_cache *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->c_width = width;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void int_width_cache_destroy(struct int_width_cache *cache)
|
||||
{
|
||||
b_btree_node *cur = b_btree_first(&cache->c_ints);
|
||||
while (cur) {
|
||||
b_btree_node *next = b_btree_next(cur);
|
||||
b_btree_delete(&cache->c_ints, cur);
|
||||
|
||||
struct int_width_cache_entry *entry
|
||||
= b_unbox(struct int_width_cache_entry, cur, e_node);
|
||||
free(entry);
|
||||
|
||||
cur = next;
|
||||
}
|
||||
|
||||
free(cache);
|
||||
}
|
||||
|
||||
static struct int_width_cache_entry *int_width_cache_entry_create(
|
||||
struct mie_ctx *ctx, size_t width, size_t value)
|
||||
{
|
||||
struct int_width_cache_entry *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->e_value.i_val.v_small = value;
|
||||
out->e_value.i_base.v_type = mie_arith_int_get_type(ctx, width);
|
||||
if (!out->e_value.i_base.v_type) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
struct mie_int_cache *mie_int_cache_create(void)
|
||||
{
|
||||
struct mie_int_cache *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void mie_int_cache_destroy(struct mie_int_cache *cache)
|
||||
{
|
||||
b_btree_node *cur = b_btree_first(&cache->c_widths);
|
||||
while (cur) {
|
||||
b_btree_node *next = b_btree_next(cur);
|
||||
b_btree_delete(&cache->c_widths, cur);
|
||||
|
||||
struct int_width_cache *width_cache
|
||||
= b_unbox(struct int_width_cache, cur, c_node);
|
||||
int_width_cache_destroy(width_cache);
|
||||
|
||||
cur = next;
|
||||
}
|
||||
|
||||
free(cache);
|
||||
}
|
||||
|
||||
struct mie_int *mie_int_cache_get(
|
||||
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
|
||||
size_t bit_width)
|
||||
{
|
||||
struct int_width_cache *width_cache
|
||||
= get_width_cache(&cache->c_widths, bit_width);
|
||||
if (!width_cache) {
|
||||
width_cache = int_width_cache_create(bit_width);
|
||||
|
||||
if (!width_cache) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
put_width_cache(&cache->c_widths, width_cache);
|
||||
}
|
||||
|
||||
struct int_width_cache_entry *entry = get_int(&width_cache->c_ints, value);
|
||||
if (!entry) {
|
||||
entry = int_width_cache_entry_create(ctx, bit_width, value);
|
||||
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
put_int(&width_cache->c_ints, entry);
|
||||
}
|
||||
|
||||
return &entry->e_value;
|
||||
}
|
||||
81
mie/dialect/arith/int.c
Normal file
81
mie/dialect/arith/int.c
Normal file
@@ -0,0 +1,81 @@
|
||||
#include <blue/core/bstr.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
struct int_type {
|
||||
struct mie_type i_base;
|
||||
size_t i_width;
|
||||
};
|
||||
|
||||
static void value_print(
|
||||
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
|
||||
{
|
||||
struct int_type *int_ty = (struct int_type *)ty;
|
||||
struct mie_int *int_val = (struct mie_int *)value;
|
||||
if (int_ty->i_width <= 64) {
|
||||
b_stream_write_fmt(
|
||||
out, NULL, "%zu : i%zu", int_val->i_val.v_small,
|
||||
int_ty->i_width);
|
||||
} else {
|
||||
b_stream_write_fmt(out, NULL, "INF : i%zu", int_ty->i_width);
|
||||
}
|
||||
}
|
||||
|
||||
struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
{
|
||||
struct mie_dialect_type *type_info
|
||||
= mie_ctx_get_dialect_type(ctx, "arith", "int");
|
||||
if (!type_info) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_rope rope_i = B_ROPE_CHAR('i'), rope_width = B_ROPE_UINT(bit_width);
|
||||
b_rope type_name;
|
||||
b_rope_concat(&type_name, &rope_i, &rope_width);
|
||||
|
||||
mie_id id;
|
||||
mie_id_init_ns(&id, mie_id_map_get_ns(&ctx->ctx_types), &type_name);
|
||||
|
||||
mie_id *target = mie_id_map_get(&ctx->ctx_types, &id);
|
||||
if (target) {
|
||||
return b_unbox(struct mie_type, target, ty_id);
|
||||
}
|
||||
|
||||
struct int_type *type = (struct int_type *)mie_type_create(type_info);
|
||||
if (!type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->i_base.ty_name = b_bstr_fmt("arith.int<%zu>", bit_width);
|
||||
type->i_width = bit_width;
|
||||
type->i_base.ty_instance_size = sizeof(struct mie_int);
|
||||
type->i_base.ty_value_print = value_print;
|
||||
|
||||
mie_id_map_put(&ctx->ctx_types, &type->i_base.ty_id, &type_name);
|
||||
return (struct mie_type *)type;
|
||||
}
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
const struct mie_dialect_type *def, struct mie_parser *parser,
|
||||
struct mie_type **out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_TYPE_BEGIN(mie_arith_int, "int")
|
||||
MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
|
||||
MIE_DIALECT_TYPE_STRUCT(struct int_type);
|
||||
MIE_DIALECT_TYPE_PRINT(print);
|
||||
MIE_DIALECT_TYPE_PARSE(parse);
|
||||
MIE_DIALECT_TYPE_END()
|
||||
6
mie/dialect/builtin/builtin.c
Normal file
6
mie/dialect/builtin/builtin.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_builtin, "builtin")
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_string);
|
||||
MIE_DIALECT_END()
|
||||
84
mie/dialect/builtin/string-cache.c
Normal file
84
mie/dialect/builtin/string-cache.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/ds/hashmap.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct mie_string_cache {
|
||||
b_hashmap *c_entries;
|
||||
};
|
||||
|
||||
static struct mie_string *mie_string_create(
|
||||
struct mie_ctx *ctx, const char *s, size_t len)
|
||||
{
|
||||
struct mie_string *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->str_base.v_type = mie_ctx_get_type(ctx, "builtin", "string");
|
||||
if (!out->str_base.v_type) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->str_val = b_strdup(s);
|
||||
if (!out->str_val) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->str_len = len;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void mie_string_destroy(struct mie_string *str)
|
||||
{
|
||||
}
|
||||
|
||||
struct mie_string_cache *mie_string_cache_create(void)
|
||||
{
|
||||
struct mie_string_cache *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->c_entries = b_hashmap_create(
|
||||
NULL, (b_hashmap_value_destructor)mie_string_destroy);
|
||||
if (!out->c_entries) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void mie_string_cache_destroy(struct mie_string_cache *cache)
|
||||
{
|
||||
b_hashmap_unref(cache->c_entries);
|
||||
free(cache);
|
||||
}
|
||||
|
||||
struct mie_string *mie_string_cache_get(
|
||||
struct mie_string_cache *cache, struct mie_ctx *ctx, const char *s)
|
||||
{
|
||||
size_t s_len = strlen(s);
|
||||
b_hashmap_key key = {.key_data = s, .key_size = s_len};
|
||||
const b_hashmap_value *value = b_hashmap_get(cache->c_entries, &key);
|
||||
if (value) {
|
||||
return value->value_data;
|
||||
}
|
||||
|
||||
struct mie_string *str = mie_string_create(ctx, s, s_len);
|
||||
if (!str) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_hashmap_value new_val = {.value_data = str, .value_size = sizeof *str};
|
||||
b_hashmap_put(cache->c_entries, &key, &new_val);
|
||||
|
||||
return str;
|
||||
}
|
||||
41
mie/dialect/builtin/string.c
Normal file
41
mie/dialect/builtin/string.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <blue/core/bstr.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
static void value_print(
|
||||
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
|
||||
{
|
||||
const struct mie_string *str = (const struct mie_string *)value;
|
||||
b_stream_write_fmt(out, NULL, "\"%s\"", str->str_val);
|
||||
}
|
||||
|
||||
static void type_init(const struct mie_dialect_type *type_info, struct mie_type *type)
|
||||
{
|
||||
type->ty_instance_size = sizeof(struct mie_string);
|
||||
type->ty_value_print = value_print;
|
||||
}
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
const struct mie_dialect_type *def, struct mie_parser *parser,
|
||||
struct mie_type **out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_TYPE_BEGIN(mie_builtin_string, "string")
|
||||
MIE_DIALECT_TYPE_STRUCT(struct mie_type);
|
||||
MIE_DIALECT_TYPE_INIT(type_init);
|
||||
MIE_DIALECT_TYPE_PRINT(print);
|
||||
MIE_DIALECT_TYPE_PARSE(parse);
|
||||
MIE_DIALECT_TYPE_END()
|
||||
18
mie/dialect/cf/br-cond.c
Normal file
18
mie/dialect/cf/br-cond.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_cf_br_cond, "br-cond")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
18
mie/dialect/cf/br.c
Normal file
18
mie/dialect/cf/br.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_cf_br, "br")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
7
mie/dialect/cf/cf.c
Normal file
7
mie/dialect/cf/cf.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_cf, "cf")
|
||||
MIE_DIALECT_ADD_OP(mie_cf_br);
|
||||
MIE_DIALECT_ADD_OP(mie_cf_br_cond);
|
||||
MIE_DIALECT_END()
|
||||
61
mie/dialect/dialect.c
Normal file
61
mie/dialect/dialect.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/dialect/type.h>
|
||||
|
||||
#define TYPE_NS_ID \
|
||||
MIE_ID(0xe4, 0x99, 0x42, 0x58, 0x2b, 0xdb, 0x45, 0xa3, 0xbd, 0x4b, \
|
||||
0x17, 0xe3, 0xc4, 0xa9, 0xbc, 0x30)
|
||||
#define OP_NS_ID \
|
||||
MIE_ID(0xb9, 0x97, 0xcf, 0xd3, 0x81, 0xd4, 0x45, 0x06, 0x9b, 0x44, \
|
||||
0x05, 0x9f, 0xb4, 0x76, 0xf1, 0x2d)
|
||||
|
||||
struct mie_dialect *mie_dialect_create(struct mie_ctx *ctx, const char *name)
|
||||
{
|
||||
struct mie_dialect *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->d_name = b_strdup(name);
|
||||
if (!out->d_name) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_id op_ns = OP_NS_ID;
|
||||
mie_id_map_init(&out->d_ops, &op_ns);
|
||||
|
||||
mie_id type_ns = TYPE_NS_ID;
|
||||
mie_id_map_init(&out->d_types, &type_ns);
|
||||
|
||||
b_rope name_rope = B_ROPE_CSTR(name);
|
||||
mie_id_map_put(&ctx->ctx_dialects, &out->d_id, &name_rope);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const struct mie_dialect_op *mie_dialect_get_op(
|
||||
const struct mie_dialect *dialect, const char *name)
|
||||
{
|
||||
b_rope name_rope = B_ROPE_CSTR(name);
|
||||
mie_id id;
|
||||
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_ops), &name_rope);
|
||||
|
||||
mie_id *target = mie_id_map_get(&dialect->d_ops, &id);
|
||||
return b_unbox(struct mie_dialect_op, target, op_id);
|
||||
}
|
||||
|
||||
const struct mie_dialect_type *mie_dialect_get_type(
|
||||
const struct mie_dialect *dialect, const char *name)
|
||||
{
|
||||
b_rope name_rope = B_ROPE_CSTR(name);
|
||||
mie_id id;
|
||||
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_types), &name_rope);
|
||||
|
||||
mie_id *target = mie_id_map_get(&dialect->d_types, &id);
|
||||
return b_unbox(struct mie_dialect_type, target, ty_id);
|
||||
}
|
||||
0
mie/dialect/dialect.h
Normal file
0
mie/dialect/dialect.h
Normal file
22
mie/dialect/func/func.c
Normal file
22
mie/dialect/func/func.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_func_func, "func")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_func, "func")
|
||||
MIE_DIALECT_ADD_OP(mie_func_func);
|
||||
MIE_DIALECT_END()
|
||||
82
mie/dialect/index/index-cache.c
Normal file
82
mie/dialect/index/index-cache.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct index_cache_entry {
|
||||
b_btree_node e_node;
|
||||
struct mie_index e_value;
|
||||
};
|
||||
|
||||
struct mie_index_cache {
|
||||
b_btree c_entries;
|
||||
};
|
||||
|
||||
static B_BTREE_DEFINE_SIMPLE_INSERT(
|
||||
struct index_cache_entry, e_node, e_value.i_value, put_index);
|
||||
static B_BTREE_DEFINE_SIMPLE_GET(
|
||||
struct index_cache_entry, size_t, e_node, e_value.i_value, get_index);
|
||||
|
||||
static struct index_cache_entry *index_cache_entry_create(
|
||||
struct mie_ctx *ctx, size_t val)
|
||||
{
|
||||
struct index_cache_entry *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->e_value.i_value = val;
|
||||
out->e_value.i_base.v_type = mie_ctx_get_type(ctx, "index", "index");
|
||||
if (!out->e_value.i_base.v_type) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
struct mie_index_cache *mie_index_cache_create(void)
|
||||
{
|
||||
struct mie_index_cache *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void mie_index_cache_destroy(struct mie_index_cache *cache)
|
||||
{
|
||||
b_btree_node *cur = b_btree_first(&cache->c_entries);
|
||||
while (cur) {
|
||||
b_btree_node *next = b_btree_next(cur);
|
||||
b_btree_delete(&cache->c_entries, cur);
|
||||
|
||||
struct index_cache_entry *entry
|
||||
= b_unbox(struct index_cache_entry, cur, e_node);
|
||||
free(entry);
|
||||
|
||||
cur = next;
|
||||
}
|
||||
|
||||
free(cache);
|
||||
}
|
||||
|
||||
struct mie_index *mie_index_cache_get(
|
||||
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value)
|
||||
{
|
||||
struct index_cache_entry *entry = get_index(&cache->c_entries, value);
|
||||
if (!entry) {
|
||||
entry = index_cache_entry_create(ctx, value);
|
||||
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
put_index(&cache->c_entries, entry);
|
||||
}
|
||||
|
||||
return &entry->e_value;
|
||||
}
|
||||
50
mie/dialect/index/index.c
Normal file
50
mie/dialect/index/index.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
struct index_type {
|
||||
struct mie_type i_base;
|
||||
};
|
||||
|
||||
static void value_print(
|
||||
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
|
||||
{
|
||||
struct index_type *index_ty = (struct index_type *)ty;
|
||||
struct mie_index *index_val = (struct mie_index *)value;
|
||||
b_stream_write_fmt(
|
||||
out, NULL, "%zu : %s", index_val->i_value,
|
||||
index_ty->i_base.ty_def->ty_name);
|
||||
}
|
||||
|
||||
static void type_init(const struct mie_dialect_type *type_info, struct mie_type *type)
|
||||
{
|
||||
type->ty_instance_size = sizeof(struct mie_index);
|
||||
type->ty_value_print = value_print;
|
||||
}
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
const struct mie_dialect_type *def, struct mie_parser *parser,
|
||||
struct mie_type **out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_TYPE_BEGIN(mie_index_index, "index")
|
||||
MIE_DIALECT_TYPE_STRUCT(struct index_type);
|
||||
MIE_DIALECT_TYPE_INIT(type_init);
|
||||
MIE_DIALECT_TYPE_PRINT(print);
|
||||
MIE_DIALECT_TYPE_PARSE(parse);
|
||||
MIE_DIALECT_TYPE_END()
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_index, "index")
|
||||
MIE_DIALECT_ADD_TYPE(mie_index_index);
|
||||
MIE_DIALECT_END()
|
||||
6
mie/dialect/meta/meta.c
Normal file
6
mie/dialect/meta/meta.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_meta, "meta")
|
||||
MIE_DIALECT_ADD_OP(mie_meta_source_filename);
|
||||
MIE_DIALECT_END()
|
||||
18
mie/dialect/meta/source-filename.c
Normal file
18
mie/dialect/meta/source-filename.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_meta_source_filename, "source-filename")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
25
mie/dialect/op.c
Normal file
25
mie/dialect/op.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
|
||||
struct mie_dialect_op *mie_dialect_op_create(
|
||||
struct mie_dialect *parent, const char *name)
|
||||
{
|
||||
struct mie_dialect_op *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->op_name = b_strdup(name);
|
||||
if (!out->op_name) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->op_parent = parent;
|
||||
|
||||
b_rope name_rope = B_ROPE_CSTR(name);
|
||||
mie_id_map_put(&parent->d_ops, &out->op_id, &name_rope);
|
||||
|
||||
return out;
|
||||
}
|
||||
18
mie/dialect/ptr/load.c
Normal file
18
mie/dialect/ptr/load.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_ptr_load, "load")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
32
mie/dialect/ptr/ptr.c
Normal file
32
mie/dialect/ptr/ptr.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
struct ptr_type {
|
||||
struct mie_dialect_type ptr_base;
|
||||
};
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
const struct mie_dialect_type *def, struct mie_parser *parser,
|
||||
struct mie_type **out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_TYPE_BEGIN(mie_ptr_ptr, "ptr")
|
||||
MIE_DIALECT_TYPE_STRUCT(struct ptr_type);
|
||||
MIE_DIALECT_TYPE_PRINT(print);
|
||||
MIE_DIALECT_TYPE_PARSE(parse);
|
||||
MIE_DIALECT_TYPE_END()
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_ptr, "ptr")
|
||||
MIE_DIALECT_ADD_OP(mie_ptr_load);
|
||||
MIE_DIALECT_ADD_OP(mie_ptr_store);
|
||||
MIE_DIALECT_ADD_TYPE(mie_ptr_ptr);
|
||||
MIE_DIALECT_END()
|
||||
18
mie/dialect/ptr/store.c
Normal file
18
mie/dialect/ptr/store.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_ptr_store, "store")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
18
mie/dialect/scf/for.c
Normal file
18
mie/dialect/scf/for.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_scf_for, "for")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
18
mie/dialect/scf/if.c
Normal file
18
mie/dialect/scf/if.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_scf_if, "if")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
10
mie/dialect/scf/scf.c
Normal file
10
mie/dialect/scf/scf.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "scf.h"
|
||||
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_scf, "scf")
|
||||
MIE_DIALECT_ADD_OP(mie_scf_if);
|
||||
MIE_DIALECT_ADD_OP(mie_scf_for);
|
||||
MIE_DIALECT_ADD_OP(mie_scf_yield);
|
||||
MIE_DIALECT_END()
|
||||
7
mie/dialect/scf/scf.h
Normal file
7
mie/dialect/scf/scf.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef MIE_DIALECT_SCF_H_
|
||||
#define MIE_DIALECT_SCF_H_
|
||||
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
|
||||
#endif
|
||||
18
mie/dialect/scf/yield.c
Normal file
18
mie/dialect/scf/yield.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/op.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_DIALECT_OP_BEGIN(mie_scf_yield, "yield")
|
||||
MIE_DIALECT_OP_PRINT(print);
|
||||
MIE_DIALECT_OP_PARSE(parse);
|
||||
MIE_DIALECT_OP_END()
|
||||
25
mie/dialect/type.c
Normal file
25
mie/dialect/type.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/type.h>
|
||||
|
||||
struct mie_dialect_type *mie_dialect_type_create(
|
||||
struct mie_dialect *parent, const char *name)
|
||||
{
|
||||
struct mie_dialect_type *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->ty_name = b_strdup(name);
|
||||
if (!out->ty_name) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out->ty_parent = parent;
|
||||
|
||||
b_rope name_rope = B_ROPE_CSTR(name);
|
||||
mie_id_map_put(&parent->d_types, &out->ty_id, &name_rope);
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -31,16 +36,15 @@ MIE_API struct mie_dialect *mie_ctx_get_dialect(
|
||||
const struct mie_ctx *ctx, const char *name);
|
||||
MIE_API struct mie_dialect_type *mie_ctx_get_dialect_type(
|
||||
const struct mie_ctx *ctx, const char *dialect_name, const char *type_name);
|
||||
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
|
||||
|
||||
53
mie/include/mie/dialect/arith.h
Normal file
53
mie/include/mie/dialect/arith.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef MIE_DIALECT_ARITH_H_
|
||||
#define MIE_DIALECT_ARITH_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
#include <mie/value.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
enum mie_float_width {
|
||||
MIE_FLOAT_32 = 32,
|
||||
MIE_FLOAT_64 = 64,
|
||||
};
|
||||
|
||||
struct mie_int {
|
||||
struct mie_value i_base;
|
||||
union {
|
||||
int64_t v_small;
|
||||
|
||||
struct {
|
||||
long *a_parts;
|
||||
size_t a_nr_parts;
|
||||
} v_arbitrary;
|
||||
} i_val;
|
||||
};
|
||||
|
||||
struct mie_float {
|
||||
struct mie_value f_base;
|
||||
|
||||
union {
|
||||
float v_32;
|
||||
double v_64;
|
||||
} f_val;
|
||||
};
|
||||
|
||||
struct mie_int_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_arith_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
MIE_API struct mie_type *mie_arith_int_get_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
MIE_API struct mie_type *mie_arith_float_get_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
|
||||
MIE_API struct mie_int_cache *mie_int_cache_create(void);
|
||||
MIE_API void mie_int_cache_destroy(struct mie_int_cache *cache);
|
||||
MIE_API struct mie_int *mie_int_cache_get(
|
||||
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
|
||||
size_t bit_width);
|
||||
|
||||
#endif
|
||||
29
mie/include/mie/dialect/builtin.h
Normal file
29
mie/include/mie/dialect/builtin.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef MIE_DIALECT_BUILTIN_H_
|
||||
#define MIE_DIALECT_BUILTIN_H_
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
struct mie_dialect;
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_int_type;
|
||||
struct mie_float_type;
|
||||
|
||||
struct mie_string {
|
||||
struct mie_value str_base;
|
||||
char *str_val;
|
||||
size_t str_len;
|
||||
};
|
||||
|
||||
struct mie_string_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_builtin_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
MIE_API struct mie_string_cache *mie_string_cache_create(void);
|
||||
MIE_API void mie_string_cache_destroy(struct mie_string_cache *cache);
|
||||
MIE_API struct mie_string *mie_string_cache_get(
|
||||
struct mie_string_cache *cache, struct mie_ctx *ctx, const char *val);
|
||||
|
||||
#endif
|
||||
11
mie/include/mie/dialect/cf.h
Normal file
11
mie/include/mie/dialect/cf.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef MIE_DIALECT_CF_H_
|
||||
#define MIE_DIALECT_CF_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
MIE_API struct mie_dialect *mie_cf_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
31
mie/include/mie/dialect/dialect.h
Normal file
31
mie/include/mie/dialect/dialect.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef MIE_DIALECT_DIALECT_H_
|
||||
#define MIE_DIALECT_DIALECT_H_
|
||||
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/queue.h>
|
||||
#include <mie/id.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_ctx;
|
||||
|
||||
struct mie_dialect_op;
|
||||
struct mie_dialect_type;
|
||||
|
||||
struct mie_dialect {
|
||||
mie_id d_id;
|
||||
char *d_name;
|
||||
|
||||
struct mie_id_map d_ops;
|
||||
struct mie_id_map d_types;
|
||||
};
|
||||
|
||||
MIE_API struct mie_dialect *mie_dialect_create(
|
||||
struct mie_ctx *ctx, const char *name);
|
||||
|
||||
MIE_API const struct mie_dialect_op *mie_dialect_get_op(
|
||||
const struct mie_dialect *dialect, const char *name);
|
||||
MIE_API const struct mie_dialect_type *mie_dialect_get_type(
|
||||
const struct mie_dialect *dialect, const char *name);
|
||||
|
||||
#endif
|
||||
11
mie/include/mie/dialect/func.h
Normal file
11
mie/include/mie/dialect/func.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef MIE_DIALECT_FUNC_H_
|
||||
#define MIE_DIALECT_FUNC_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
MIE_API struct mie_dialect *mie_func_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
26
mie/include/mie/dialect/index.h
Normal file
26
mie/include/mie/dialect/index.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef MIE_DIALECT_INDEX_H_
|
||||
#define MIE_DIALECT_INDEX_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
#include <mie/value.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
struct mie_index {
|
||||
struct mie_value i_base;
|
||||
size_t i_value;
|
||||
};
|
||||
|
||||
struct mie_index_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_index_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
MIE_API struct mie_index_cache *mie_index_cache_create(void);
|
||||
MIE_API void mie_index_cache_destroy(struct mie_index_cache *cache);
|
||||
MIE_API struct mie_index *mie_index_cache_get(
|
||||
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value);
|
||||
|
||||
#endif
|
||||
11
mie/include/mie/dialect/meta.h
Normal file
11
mie/include/mie/dialect/meta.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef MIE_DIALECT_META_H_
|
||||
#define MIE_DIALECT_META_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
MIE_API struct mie_dialect *mie_meta_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
25
mie/include/mie/dialect/op.h
Normal file
25
mie/include/mie/dialect/op.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef MIE_DIALECT_OP_H_
|
||||
#define MIE_DIALECT_OP_H_
|
||||
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <mie/id.h>
|
||||
#include <mie/status.h>
|
||||
|
||||
struct mie_op;
|
||||
struct mie_parser;
|
||||
struct mie_dialect;
|
||||
|
||||
struct mie_dialect_op {
|
||||
mie_id op_id;
|
||||
struct mie_dialect *op_parent;
|
||||
char *op_name;
|
||||
|
||||
enum mie_status (*op_print)(const struct mie_op *, b_stream *);
|
||||
enum mie_status (*op_parse)(struct mie_parser *, struct mie_op *);
|
||||
};
|
||||
|
||||
MIE_API struct mie_dialect_op *mie_dialect_op_create(
|
||||
struct mie_dialect *parent, const char *name);
|
||||
|
||||
#endif
|
||||
11
mie/include/mie/dialect/ptr.h
Normal file
11
mie/include/mie/dialect/ptr.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef MIE_DIALECT_PTR_H_
|
||||
#define MIE_DIALECT_PTR_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
MIE_API struct mie_dialect *mie_ptr_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
11
mie/include/mie/dialect/scf.h
Normal file
11
mie/include/mie/dialect/scf.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef MIE_DIALECT_SCF_H_
|
||||
#define MIE_DIALECT_SCF_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
MIE_API struct mie_dialect *mie_scf_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
38
mie/include/mie/dialect/type.h
Normal file
38
mie/include/mie/dialect/type.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef MIE_DIALECT_TYPE_H_
|
||||
#define MIE_DIALECT_TYPE_H_
|
||||
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <mie/id.h>
|
||||
#include <mie/status.h>
|
||||
|
||||
struct mie_type;
|
||||
struct mie_parser;
|
||||
struct mie_dialect;
|
||||
|
||||
enum mie_dialect_type_flags {
|
||||
MIE_DIALECT_TYPE_PARAMETISED = 0x01u,
|
||||
};
|
||||
|
||||
struct mie_dialect_type {
|
||||
mie_id ty_id;
|
||||
enum mie_dialect_type_flags ty_flags;
|
||||
struct mie_dialect *ty_parent;
|
||||
char *ty_name;
|
||||
|
||||
size_t ty_data_size;
|
||||
|
||||
enum mie_status (*ty_print)(
|
||||
const struct mie_dialect_type *, const struct mie_type *,
|
||||
b_stream *);
|
||||
enum mie_status (*ty_parse)(
|
||||
const struct mie_dialect_type *, struct mie_parser *,
|
||||
struct mie_type **);
|
||||
void (*ty_init)(const struct mie_dialect_type *, struct mie_type *);
|
||||
void (*ty_cleanup)(const struct mie_dialect_type *, struct mie_type *);
|
||||
};
|
||||
|
||||
MIE_API struct mie_dialect_type *mie_dialect_type_create(
|
||||
struct mie_dialect *parent, const char *name);
|
||||
|
||||
#endif
|
||||
@@ -61,7 +61,9 @@
|
||||
#define MIE_DIALECT_TYPE_BEGIN(c_sym, type) \
|
||||
__MIE_DIALECT_TYPE_BEGIN(c_sym, type)
|
||||
#define MIE_DIALECT_TYPE_END() __MIE_DIALECT_TYPE_END()
|
||||
#define MIE_DIALECT_TYPE_FLAGS(flags) type->ty_flags = flags
|
||||
#define MIE_DIALECT_TYPE_STRUCT(name) type->ty_data_size = sizeof(name)
|
||||
#define MIE_DIALECT_TYPE_INIT(func) type->ty_init = (func)
|
||||
#define MIE_DIALECT_TYPE_PRINT(func) type->ty_print = (func)
|
||||
#define MIE_DIALECT_TYPE_PARSE(func) type->ty_parse = (func)
|
||||
#define MIE_DIALECT_TYPE_INIT(func) type->ty_init = (func)
|
||||
|
||||
20
mie/include/mie/type/function.h
Normal file
20
mie/include/mie/type/function.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef MIE_TYPE_FUNCTION_H_
|
||||
#define MIE_TYPE_FUNCTION_H_
|
||||
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_function_type {
|
||||
struct mie_type func_base;
|
||||
|
||||
MIE_VECTOR_DECLARE(struct mie_type *, func_in);
|
||||
MIE_VECTOR_DECLARE(struct mie_type *, func_out);
|
||||
};
|
||||
|
||||
MIE_API struct mie_function_type *mie_function_type_create(void);
|
||||
MIE_API void mie_function_type_add_in_part(
|
||||
struct mie_function_type *ty, struct mie_type *part);
|
||||
MIE_API void mie_function_type_add_out_part(
|
||||
struct mie_function_type *ty, struct mie_type *part);
|
||||
|
||||
#endif
|
||||
17
mie/include/mie/type/storage.h
Normal file
17
mie/include/mie/type/storage.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef MIE_TYPE_STORAGE_H_
|
||||
#define MIE_TYPE_STORAGE_H_
|
||||
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_storage_type {
|
||||
struct mie_type st_base;
|
||||
|
||||
MIE_VECTOR_DECLARE(struct mie_type *, st_parts);
|
||||
};
|
||||
|
||||
MIE_API struct mie_storage_type *mie_storage_type_create(void);
|
||||
MIE_API void mie_storage_type_add_part(
|
||||
struct mie_storage_type *ty, struct mie_type *part);
|
||||
|
||||
#endif
|
||||
39
mie/include/mie/type/type.h
Normal file
39
mie/include/mie/type/type.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef MIE_TYPE_TYPE_H_
|
||||
#define MIE_TYPE_TYPE_H_
|
||||
|
||||
#include <mie/id.h>
|
||||
#include <mie/misc.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mie_dialect;
|
||||
struct mie_dialect_type;
|
||||
|
||||
struct mie_value;
|
||||
|
||||
/* a mie_type is an instance of mie_dialect_type.
|
||||
* if the mie_dialect_type is a parametised type, the resulting mie_type
|
||||
* will have those parameters baked in.
|
||||
* this is a base struct. dialects that defined their own types do so by
|
||||
* inheriting from this struct. */
|
||||
struct mie_type {
|
||||
/* this is NOT the same as ty_def->ty_id */
|
||||
mie_id ty_id;
|
||||
|
||||
/* this pointer is optional. if it is NULL, the name of the type can
|
||||
* be found in ty_def */
|
||||
char *ty_name;
|
||||
struct mie_dialect_type *ty_def;
|
||||
|
||||
/* for types that can be instantiated in C (i.e. an instance that can
|
||||
* be represented by a mie_value), this is the total size of the
|
||||
* instance data. */
|
||||
size_t ty_instance_size;
|
||||
|
||||
void (*ty_instance_cleanup)(const struct mie_type *, struct mie_value *);
|
||||
void (*ty_value_print)(
|
||||
const struct mie_type *, const struct mie_value *, b_stream *);
|
||||
};
|
||||
|
||||
MIE_API struct mie_type *mie_type_create(struct mie_dialect_type *type);
|
||||
|
||||
#endif
|
||||
15
mie/include/mie/value.h
Normal file
15
mie/include/mie/value.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef MIE_VALUE_VALUE_H_
|
||||
#define MIE_VALUE_VALUE_H_
|
||||
|
||||
#include <blue/core/stream.h>
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_type;
|
||||
|
||||
struct mie_value {
|
||||
struct mie_type *v_type;
|
||||
};
|
||||
|
||||
MIE_API void mie_value_print(const struct mie_value *value, b_stream *dest);
|
||||
|
||||
#endif
|
||||
19
mie/type/type.c
Normal file
19
mie/type/type.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <mie/dialect/type.h>
|
||||
#include <mie/type/type.h>
|
||||
|
||||
struct mie_type *mie_type_create(struct mie_dialect_type *type)
|
||||
{
|
||||
if (type->ty_data_size < sizeof(struct mie_type)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_type *out = malloc(type->ty_data_size);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
out->ty_def = type;
|
||||
|
||||
return out;
|
||||
}
|
||||
9
mie/value.c
Normal file
9
mie/value.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <mie/type/type.h>
|
||||
#include <mie/value.h>
|
||||
|
||||
void mie_value_print(const struct mie_value *value, b_stream *dest)
|
||||
{
|
||||
if (value->v_type && value->v_type->ty_value_print) {
|
||||
value->v_type->ty_value_print(value->v_type, value, dest);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user