diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-19 21:04:17 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-19 21:04:17 +0200 |
commit | 3ea67fa6af035b3f5b2865e6eeb39ceea49bf07c (patch) | |
tree | 4838df83b684e8450c486a7166d96c72d34bcfa2 | |
parent | 61c6bb0ae72d565db169459b1da6af7ac6797116 (diff) |
Add f32 and f64 as types
-rw-r--r-- | src/analyzer.c | 5 | ||||
-rw-r--r-- | src/analyzer.h | 15 | ||||
-rw-r--r-- | src/primitives.gperf | 28 |
3 files changed, 20 insertions, 28 deletions
diff --git a/src/analyzer.c b/src/analyzer.c index 4d41a33..dc22190 100644 --- a/src/analyzer.c +++ b/src/analyzer.c @@ -292,6 +292,7 @@ typecompat(struct type lhs, struct type rhs) return true; /* Two typed numeric types are only compatible if they have the same size - and sign */ - return lhs.issigned == rhs.issigned && lhs.size == rhs.size; + and sign and are either both integral or both floats */ + return lhs.issigned == rhs.issigned && lhs.isfloat == rhs.isfloat + && lhs.size == rhs.size; } diff --git a/src/analyzer.h b/src/analyzer.h index 5e28903..261427c 100644 --- a/src/analyzer.h +++ b/src/analyzer.h @@ -9,20 +9,8 @@ enum { TYPE_UNSET = 0, TYPE_CHECKING = 1, - TYPE_NUM, - - /* Floating point numbers */ - TYPE_F16, - TYPE_F32, - TYPE_F64, - - /* Unicode codepoint */ - TYPE_RUNE, - - /* Function type */ TYPE_FN, - _TYPE_LAST_ENT, }; @@ -32,8 +20,9 @@ static_assert(_TYPE_LAST_ENT - 1 <= (type_kind_t_)-1, struct type { type_kind_t_ kind; - uint8_t size : 7; /* bytes */ + uint8_t size : 6; /* bytes */ bool issigned : 1; + bool isfloat : 1; /* For functions */ const struct type *params, *ret; diff --git a/src/primitives.gperf b/src/primitives.gperf index 4391565..09d9b68 100644 --- a/src/primitives.gperf +++ b/src/primitives.gperf @@ -16,19 +16,21 @@ struct typeslot { char *name; struct type inner; }; %% -i8, { TYPE_NUM, 1, true } -i16, { TYPE_NUM, 2, true } -i32, { TYPE_NUM, 4, true } -i64, { TYPE_NUM, 8, true } -i128, { TYPE_NUM, 16, true } -int, { TYPE_NUM, 8, true } -u8, { TYPE_NUM, 1, false } -u16, { TYPE_NUM, 2, false } -u32, { TYPE_NUM, 4, false } -u64, { TYPE_NUM, 8, false } -u128, { TYPE_NUM, 16, false } -uint, { TYPE_NUM, 8, false } -rune, { TYPE_NUM , 4, true } +i8, { TYPE_NUM, 1, true, false } +i16, { TYPE_NUM, 2, true, false } +i32, { TYPE_NUM, 4, true, false } +i64, { TYPE_NUM, 8, true, false } +i128, { TYPE_NUM, 16, true, false } +int, { TYPE_NUM, 8, true, false } +u8, { TYPE_NUM, 1, false, false } +u16, { TYPE_NUM, 2, false, false } +u32, { TYPE_NUM, 4, false, false } +u64, { TYPE_NUM, 8, false, false } +u128, { TYPE_NUM, 16, false, false } +uint, { TYPE_NUM, 8, false, false } +rune, { TYPE_NUM , 4, true, false } +f32, { TYPE_NUM, 4, true, true } +f64, { TYPE_NUM, 8, true, true } %% const struct type * typelookup(const uchar *p, size_t len) |