diff options
author | Himbeer <himbeer@disroot.org> | 2024-09-15 18:02:50 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-09-15 18:18:47 +0200 |
commit | 765155fa86f03e7779ac450455fa46c954f41a3b (patch) | |
tree | 64f3f8e9965a35ee753a4efe067a9a8237b7823b /include/type.h | |
parent | e4e380156a220fc2285580f3c0d873031df2aa77 (diff) |
Add data structures for types
Diffstat (limited to 'include/type.h')
-rw-r--r-- | include/type.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/include/type.h b/include/type.h new file mode 100644 index 0000000..aa745b7 --- /dev/null +++ b/include/type.h @@ -0,0 +1,75 @@ +#ifndef CERC_TYPE_H +#define CERC_TYPE_H +#include <stdbool.h> +#include <stdint.h> + +struct cer_int { + bool sign; + short bits; +}; + +struct cer_float { + bool is64; +}; + +struct cer_array { + struct type *member_type; + int length; +}; + +struct cer_slice { + struct type *member_type; +}; + +struct field { + const char *name; + struct type *type; +}; + +struct cer_struct { + struct field *fields; +}; + +struct variant { + const char *name; + uint64_t tag; +}; + +struct cer_enum { + struct cer_int *tag_type; + struct variant variants[]; +}; + +struct cer_union { + struct type *alts; +}; + +enum type_kind { + TYP_INT, + TYP_FLOAT, + TYP_ARRAY, + TYP_SLICE, + TYP_STRUCT, + TYP_ENUM, + TYP_UNION, + TYP_POINTER, + TYP_OPTIONAL, + TYP_FALLIBLE, +}; + +union type_desc { + struct cer_int *i; + struct cer_float *f; + struct cer_array *array; + struct cer_slice *slice; + struct cer_struct *s; + struct cer_enum *en; + struct cer_union *un; +}; + +struct type { + enum type_kind kind; + union type_desc desc; +}; + +#endif |