From 3c4af9c26e53c02cc28eda8ae16af998b12a54cb Mon Sep 17 00:00:00 2001 From: Max Wash Date: Wed, 14 Jan 2026 18:21:25 +0000 Subject: [PATCH] mie: builtin: initial implementation of a symbol system the symbol system will allow ops to reference each other via symbolic names, rather than just via their SSA output registers. this will allow for links between ops that are less strict than SSA. the two parts of the system are: - the symbol-table trait. ops with this trait can contain symbol ops. - the symbol interface. ops with this interface have the necessary attributes to be treated as symbols. --- mie/dialect/builtin/builtin.c | 2 ++ mie/dialect/builtin/interface/symbol.c | 7 +++++++ mie/dialect/builtin/trait/symbol-table.c | 21 +++++++++++++++++++++ mie/include/mie/dialect/builtin.h | 12 ++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 mie/dialect/builtin/interface/symbol.c create mode 100644 mie/dialect/builtin/trait/symbol-table.c diff --git a/mie/dialect/builtin/builtin.c b/mie/dialect/builtin/builtin.c index 5b8f870..f4a9d49 100644 --- a/mie/dialect/builtin/builtin.c +++ b/mie/dialect/builtin/builtin.c @@ -92,4 +92,6 @@ MIE_DIALECT_BEGIN(mie_builtin, struct builtin_dialect, "builtin") MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_int); MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_float); MIE_DIALECT_ADD_TRAIT(mie_builtin_isolated_from_above); + MIE_DIALECT_ADD_TRAIT(mie_builtin_symbol_table); + MIE_DIALECT_ADD_INTERFACE(mie_builtin_symbol); MIE_DIALECT_END() diff --git a/mie/dialect/builtin/interface/symbol.c b/mie/dialect/builtin/interface/symbol.c new file mode 100644 index 0000000..e9a845b --- /dev/null +++ b/mie/dialect/builtin/interface/symbol.c @@ -0,0 +1,7 @@ +#include +#include +#include + +MIE_INTERFACE_DEFINITION_BEGIN(mie_builtin_symbol, "symbol") + MIE_INTERFACE_DEFINITION_STRUCT(struct mie_symbol); +MIE_INTERFACE_DEFINITION_END() diff --git a/mie/dialect/builtin/trait/symbol-table.c b/mie/dialect/builtin/trait/symbol-table.c new file mode 100644 index 0000000..675ebbb --- /dev/null +++ b/mie/dialect/builtin/trait/symbol-table.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include + +static enum mie_status validate( + const struct mie_trait_definition *trait_def, + const struct mie_trait *trait, const struct mie_trait_target *target) +{ + return MIE_SUCCESS; +} + +/* builtin.isolated-from-above trait: + * regions of an op that has this trait cannot capture or reference + * values defined in the enclosing scope. */ +MIE_TRAIT_DEFINITION_BEGIN(mie_builtin_symbol_table, "symbol-table") + MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP | MIE_TRAIT_TARGET_TYPE); + MIE_TRAIT_DEFINITION_STRUCT(struct mie_symbol_table); + MIE_TRAIT_DEFINITION_VALIDATE(validate); +MIE_TRAIT_DEFINITION_END() diff --git a/mie/include/mie/dialect/builtin.h b/mie/include/mie/dialect/builtin.h index 09a43f2..ea8c2be 100644 --- a/mie/include/mie/dialect/builtin.h +++ b/mie/include/mie/dialect/builtin.h @@ -3,11 +3,14 @@ #include #include +#include #include +#include struct mie_dialect; struct mie_ctx; +struct mie_op; struct mie_int_type; struct mie_float_type; @@ -51,6 +54,15 @@ struct mie_index { size_t i_value; }; +struct mie_symbol { + struct mie_interface sym_base; + const char *(*sym_get_name)(const struct mie_op *); +}; + +struct mie_symbol_table { + struct mie_trait tab_base; +}; + struct mie_int_cache; struct mie_float_cache; struct mie_string_cache;