mie: implement an interface system for ops

this system allows dialects to register named interfaces, which are collections of function
pointers. an op can then implement this interface, providing callbacks for the interface's
virtual function pointers.

C code can request a pointer to an op's implementation of a given interface and call
virtual functions with no knowledge required about the op itself. this functonality
will also be extended to types, attributes, and dialects themselves.
This commit is contained in:
2026-01-14 18:17:34 +00:00
parent 50f4be621b
commit 11fc7a6ca9
14 changed files with 261 additions and 3 deletions

View File

@@ -19,6 +19,10 @@
MIE_ID(0x86, 0x76, 0xcb, 0xfb, 0xc8, 0xe5, 0x40, 0x7d, 0xa3, 0x84, \
0x93, 0xe3, 0xa5, 0x29, 0x74, 0xfe)
#define INTERFACE_NS_ID \
MIE_ID(0xc5, 0x85, 0x7f, 0x8a, 0x7d, 0xe4, 0x4d, 0x03, 0x88, 0x8d, \
0x34, 0x32, 0xbf, 0x29, 0x5c, 0x72)
struct mie_dialect *mie_dialect_create(
struct mie_ctx *ctx, const char *name, size_t size)
{
@@ -51,6 +55,9 @@ struct mie_dialect *mie_dialect_create(
mie_id attribute_ns = ATTRIBUTE_NS_ID;
mie_id_map_init(&out->d_attributes, &attribute_ns);
mie_id interface_ns = INTERFACE_NS_ID;
mie_id_map_init(&out->d_interfaces, &interface_ns);
b_rope name_rope = B_ROPE_CSTR(name);
mie_id_map_put(&ctx->ctx_dialects, &out->d_id, &name_rope);

View File

@@ -1,4 +1,8 @@
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/interface/interface-definition.h>
#include <mie/interface/interface.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
@@ -15,4 +19,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
MIE_OP_DEFINITION_BEGIN(mie_func_func, "func")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_INTERFACE_BEGIN("builtin", "symbol", struct mie_symbol)
MIE_OP_INTERFACE_FUNC(sym_get_name) = NULL;
MIE_OP_INTERFACE_END()
MIE_OP_DEFINITION_END()