From add09d49581e076ea75779561b97f96a3474e910 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 4 Jan 2026 14:10:52 +0000 Subject: [PATCH] mie: add data structures to represent type-instances unlike values, type-instances represent specialisations of parametised types. they behave like concrete implementations of C++ template types. for example: arith.int represents an integer type of unspecified bit-width. a type-instance of this type would be arith.int<32> (or i32 for short) which has a defined width of 32 bits. --- mie/include/mie/type/function.h | 20 ++++++++++++++++++++ mie/include/mie/type/storage.h | 17 +++++++++++++++++ mie/include/mie/type/type.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 mie/include/mie/type/function.h create mode 100644 mie/include/mie/type/storage.h create mode 100644 mie/include/mie/type/type.h diff --git a/mie/include/mie/type/function.h b/mie/include/mie/type/function.h new file mode 100644 index 0000000..0dba1b2 --- /dev/null +++ b/mie/include/mie/type/function.h @@ -0,0 +1,20 @@ +#ifndef MIE_TYPE_FUNCTION_H_ +#define MIE_TYPE_FUNCTION_H_ + +#include +#include + +struct mie_function_type { + struct mie_type func_base; + + MIE_VECTOR_DECLARE(struct mie_type *, func_in); + MIE_VECTOR_DECLARE(struct mie_type *, func_out); +}; + +MIE_API struct mie_function_type *mie_function_type_create(void); +MIE_API void mie_function_type_add_in_part( + struct mie_function_type *ty, struct mie_type *part); +MIE_API void mie_function_type_add_out_part( + struct mie_function_type *ty, struct mie_type *part); + +#endif diff --git a/mie/include/mie/type/storage.h b/mie/include/mie/type/storage.h new file mode 100644 index 0000000..3f33902 --- /dev/null +++ b/mie/include/mie/type/storage.h @@ -0,0 +1,17 @@ +#ifndef MIE_TYPE_STORAGE_H_ +#define MIE_TYPE_STORAGE_H_ + +#include +#include + +struct mie_storage_type { + struct mie_type st_base; + + MIE_VECTOR_DECLARE(struct mie_type *, st_parts); +}; + +MIE_API struct mie_storage_type *mie_storage_type_create(void); +MIE_API void mie_storage_type_add_part( + struct mie_storage_type *ty, struct mie_type *part); + +#endif diff --git a/mie/include/mie/type/type.h b/mie/include/mie/type/type.h new file mode 100644 index 0000000..9cb7e12 --- /dev/null +++ b/mie/include/mie/type/type.h @@ -0,0 +1,31 @@ +#ifndef MIE_TYPE_TYPE_H_ +#define MIE_TYPE_TYPE_H_ + +#include +#include +#include + +struct mie_dialect; +struct mie_dialect_type; + +struct mie_type; + +/* a mie_type is an instance of mie_dialect_type. + * if the mie_dialect_type is a parametised type, the resulting mie_type + * will have those parameters baked in. + * this is a base struct. dialects that defined their own types do so by + * inheriting from this struct. */ +struct mie_type { + /* this is NOT the same as ty_def->ty_id */ + mie_id ty_id; + + /* this pointer is optional. if it is NULL, the name of the type can + * be found in ty_def */ + char *ty_name; + + struct mie_dialect_type *ty_def; +}; + +MIE_API struct mie_type *mie_type_create(struct mie_dialect_type *type); + +#endif