mie: type: move all function pointers from mie_type to mie_dialect_type

This commit is contained in:
2026-01-08 19:00:13 +00:00
parent f4d374288f
commit 344626f207
7 changed files with 17 additions and 14 deletions

View File

@@ -60,9 +60,8 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
}
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;
type->f_width = bit_width;
mie_id_map_put(&ctx->ctx_types, &type->f_base.ty_id, &type_name);
return (struct mie_type *)type;
@@ -82,8 +81,9 @@ static enum mie_status parse(
}
MIE_DIALECT_TYPE_BEGIN(mie_arith_float, "float")
MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
// 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_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()

View File

@@ -52,9 +52,8 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
}
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;
type->i_width = bit_width;
mie_id_map_put(&ctx->ctx_types, &type->i_base.ty_id, &type_name);
return (struct mie_type *)type;
@@ -74,8 +73,9 @@ static enum mie_status parse(
}
MIE_DIALECT_TYPE_BEGIN(mie_arith_int, "int")
MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
// 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_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()

View File

@@ -17,7 +17,6 @@ static void value_print(
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(
@@ -38,4 +37,5 @@ MIE_DIALECT_TYPE_BEGIN(mie_builtin_string, "string")
MIE_DIALECT_TYPE_INIT(type_init);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()

View File

@@ -22,7 +22,6 @@ static void value_print(
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(
@@ -43,6 +42,7 @@ MIE_DIALECT_TYPE_BEGIN(mie_index_index, "index")
MIE_DIALECT_TYPE_INIT(type_init);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()
MIE_DIALECT_BEGIN(mie_index, "index")

View File

@@ -7,6 +7,7 @@
#include <mie/status.h>
struct mie_type;
struct mie_value;
struct mie_parser;
struct mie_dialect;
@@ -22,9 +23,14 @@ struct mie_dialect_type {
size_t ty_data_size;
void (*ty_init)(const struct mie_dialect_type *, struct mie_type *);
void (*ty_cleanup)(const struct mie_dialect_type *, struct mie_type *);
void (*ty_instance_cleanup)(const struct mie_type *, struct mie_value *);
enum mie_status (*ty_print)(
const struct mie_dialect_type *, const struct mie_type *,
b_stream *);
void (*ty_value_print)(
const struct mie_type *, const struct mie_value *, b_stream *);
enum mie_status (*ty_parse)(
const struct mie_dialect_type *, struct mie_parser *,
struct mie_type **);

View File

@@ -28,10 +28,6 @@ struct mie_type {
* 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);

View File

@@ -1,9 +1,10 @@
#include <mie/dialect/type.h>
#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);
if (value->v_type && value->v_type->ty_def->ty_value_print) {
value->v_type->ty_def->ty_value_print(value->v_type, value, dest);
}
}