#include #include #include #include static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx) { return MIE_TYPE(v); } const struct mie_value_type type_value_type = { .t_id = MIE_VALUE_TYPE, .t_get_type = get_type, }; struct mie_type *mie_type_create(void) { struct mie_type *out = malloc(sizeof *out); if (!out) { return NULL; } memset(out, 0x0, sizeof *out); out->t_base.v_type = &type_value_type; return out; } void mie_type_to_string(const struct mie_type *type, char *out, size_t max) { if (!type) { snprintf(out, max, "no-type"); return; } switch (type->t_id) { case MIE_TYPE_PTR: snprintf(out, max, "ptr"); break; case MIE_TYPE_VOID: snprintf(out, max, "void"); break; case MIE_TYPE_INT: snprintf(out, max, "i%u", type->t_width); break; case MIE_TYPE_ID: snprintf(out, max, "id"); break; case MIE_TYPE_STR: snprintf(out, max, "str"); break; case MIE_TYPE_ATOM: snprintf(out, max, "atom"); break; case MIE_TYPE_LABEL: snprintf(out, max, "label"); break; case MIE_TYPE_ARRAY: snprintf(out, max, "array"); break; case MIE_TYPE_FUNC: snprintf(out, max, "func"); break; case MIE_TYPE_GLUE: snprintf(out, max, "glue"); break; case MIE_TYPE_SELECTOR: snprintf(out, max, ""); break; default: snprintf(out, max, "unknown-type"); break; } } bool mie_type_compare(const struct mie_type *a, const struct mie_type *b) { if (a->t_id != b->t_id) { return false; } if (a->t_count != b->t_count) { return false; } if (a->t_width != b->t_width) { return false; } /* TODO compare complex types */ return true; }