Files
ivy/mie/type.c

76 lines
1.4 KiB
C
Raw Normal View History

#include <mie/type.h>
2025-08-29 15:46:12 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}
2025-08-29 15:46:12 +01:00
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;
}
}