diff options
author | Himbeer <himbeer@disroot.org> | 2025-05-06 11:50:07 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2025-05-06 11:50:07 +0200 |
commit | bba151c9fa9a0a0c630577dc6e20cc8809a337d9 (patch) | |
tree | d74cbdec8e513d7794f2f96fa00296eca1725f6f | |
parent | b49e96941fb9f07426d49adeef50cd8c1716bf15 (diff) |
Simplify type system to primitives only
-rw-r--r-- | include/type.h | 95 | ||||
-rw-r--r-- | src/type.c | 63 |
2 files changed, 34 insertions, 124 deletions
diff --git a/include/type.h b/include/type.h index c8a6b76..d871106 100644 --- a/include/type.h +++ b/include/type.h @@ -10,87 +10,34 @@ #define PLATBITS 64 struct cer_int { - bool sign; - short bits; + int bits; + int issigned; }; struct cer_float { - bool is64; + int bits; }; -struct cer_array { - struct type *member_type; - struct disjunction_e *length; -}; - -struct field { - const char *name; - struct type *type; -}; - -struct cer_struct { - struct field *fields; - int fieldsz, fieldlen; -}; - -struct variant { - const char *name; - uint64_t tag; -}; - -struct cer_enum { - struct type *tag_type; - struct variant *variants; - int variantsz, variantlen; -}; - -struct cer_union { - struct type *tag_type; - struct type *alts; - int altsz, altlen; -}; - -enum type_kind { - TYP_ARRAY, - TYP_BOOL, - TYP_ENUM, - TYP_FALLIBLE, - TYP_FLOAT, - TYP_INT, - TYP_OPTIONAL, - TYP_PATH, - TYP_POINTER, - TYP_SLICE, - TYP_STRUCT, - TYP_UNION, -}; - -union type_desc { - struct cer_int i; - struct cer_float f; - struct cer_array array; - struct cer_struct s; - struct cer_enum en; - struct cer_union un; - struct type *inner; - struct path path; +enum typekind { + TK_INT, + TK_FLOAT, + TK_BOOL, }; struct type { - enum type_kind kind; - union type_desc desc; -}; - -/** - * Builtin types - */ - -extern const struct cer_int int8_b, uint8_b; -extern const struct cer_int int16_b, uint16_b; -extern const struct cer_int int32_b, uint32_b; -extern const struct cer_int int64_b, uint64_b; -extern const struct cer_int int_b, uint_b; - -extern const struct cer_float float32_b, float64_b; + enum typekind kind; + union { + struct cer_int i; + struct cer_float fp; + } desc; +}; + +extern const struct cer_int cer_int8_t, cer_uint8_t; +extern const struct cer_int cer_int16_t, cer_uint16_t; +extern const struct cer_int cer_int32_t, cer_uint32_t; +extern const struct cer_int cer_int64_t, cer_uint64_t; +extern const struct cer_int cer_int_t, cer_uint_t; +extern const struct cer_float cer_float32_t; +extern const struct cer_float cer_float64_t; #endif @@ -1,52 +1,15 @@ #include "type.h" -/** - * Builtin types - */ - -const struct cer_int int8_b = { - .sign = true, - .bits = 8, -}; - -const struct cer_int uint8_b = { - .sign = false, - .bits = 8, -}; - -const struct cer_int int16_b = { - .sign = true, - .bits = 16, -}; - -const struct cer_int uint16_b = { - .sign = false, - .bits = 16, -}; - -const struct cer_int int32_b = { - .sign = true, - .bits = 32, -}; - -const struct cer_int uint32_b = { - .sign = false, - .bits = 32, -}; - -const struct cer_int int64_b = { - .sign = true, - .bits = 64, -}; - -const struct cer_int uint64_b = { - .sign = false, - .bits = 64, -}; - -// Only 64-bit targets are supported (by QBE) -const struct cer_int int_b = int64_b; -const struct cer_int uint_b = uint64_b; - -const struct cer_float float32_b = { .is64 = false }; -const struct cer_float float64_b = { .is64 = true }; +const struct cer_int cer_int8_t = struct cer_int { .bits = 8, .issigned = 1 }; +const struct cer_int cer_uint8_t = struct cer_int { .bits = 8, .issigned = 0 }; +const struct cer_int cer_int16_t = struct cer_int { .bits = 16, .issigned = 1 }; +const struct cer_int cer_uint16_t = struct cer_int { .bits = 16, .issigned = 0 }; +const struct cer_int cer_int32_t = struct cer_int { .bits = 32, .issigned = 1 }; +const struct cer_int cer_uint32_t = struct cer_int { .bits = 32, .issigned = 0 }; +const struct cer_int cer_int64_t = struct cer_int { .bits = 64, .issigned = 1 }; +const struct cer_int cer_uint64_t = struct cer_int { .bits = 64, .issigned = 0 }; +const struct cer_int cer_int_t = struct cer_int { .bits = PLATBITS, .issigned = 1 }; +const struct cer_int cer_uint_t = struct cer_int { .bits = PLATBITS, .issigned = 0 }; + +const struct cer_float cer_float32_t = struct cer_float { .bits = 32 }; +const struct cer_float cer_floaf64_t = struct cer_float { .bits = 64 }; |