mie: replace fixed value system with an extensible attribute interface

under this new system, dialects can define their own custom attributes,
complete with their own print() and parse() callbacks, which can then be
used as values in an op's attribute dictionary.

alongside custom dialect attributes, the former int, float, and string
constant values have been converted to attributes provided by the
arith and builtin dialects respectively. the caches for these attributes
have also been moved from mie_ctx to their respective dialect data
structures.

this system will allow new types of attributes to be implemented,
including dictionaries, arrays, and references to types themselves
(rather than just particular values of a given type).
This commit is contained in:
2026-01-13 22:37:43 +00:00
parent d19e8626da
commit da630ce382
68 changed files with 1219 additions and 450 deletions

10
mie/print/attribute.c Normal file
View File

@@ -0,0 +1,10 @@
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
void mie_printer_print_attribute(
struct mie_printer *printer, const struct mie_attribute *attrib)
{
if (attrib->a_def && attrib->a_def->a_print) {
attrib->a_def->a_print(attrib, printer);
}
}

View File

@@ -108,27 +108,34 @@ static void print_region_list(struct mie_printer *printer, const struct mie_op *
}
static void print_attribute(
struct mie_printer *printer, const struct mie_op_attribute *attrib)
struct mie_printer *printer, const struct mie_attribute_map_iterator *attrib)
{
b_stream_write_fmt(printer->p_stream, NULL, "%s = ", attrib->attrib_name);
mie_printer_print_value(printer, attrib->attrib_value);
b_stream_write_fmt(printer->p_stream, NULL, "%s = ", attrib->it_name);
mie_printer_print_attribute(printer, attrib->it_value);
}
static void print_attribute_list(
struct mie_printer *printer, const struct mie_op *op)
{
if (!MIE_VECTOR_COUNT(op->op_attrib)) {
if (mie_attribute_map_empty(&op->op_attrib)) {
return;
}
b_stream_write_string(printer->p_stream, " { ", NULL);
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_attrib); i++) {
struct mie_attribute_map_iterator it;
enum mie_status status
= mie_attribute_map_iterator_begin(&it, &op->op_attrib);
size_t i = 0;
while (status == MIE_SUCCESS) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
print_attribute(printer, &op->op_attrib.items[i]);
print_attribute(printer, &it);
status = mie_attribute_map_iterator_move_next(&it);
i++;
}
b_stream_write_string(printer->p_stream, " }", NULL);

View File

@@ -1,11 +0,0 @@
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
void mie_printer_print_value(
struct mie_printer *printer, const struct mie_value *value)
{
if (value->v_type && value->v_type->ty_def->ty_value_print) {
value->v_type->ty_def->ty_value_print(value, printer);
}
}