diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 11:08:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 11:08:15 -0400 |
| commit | bba9f1b141fba5ffc366ef9377fb3089c0c5a1a3 (patch) | |
| tree | 371100a85fa638102bbf331811ef53b8fcb67159 /types.c | |
| parent | 0ca48c98e897c6edd800c0aefabd20cc4e7a5409 (diff) | |
Optional fixed-size ints
Diffstat (limited to 'types.c')
| -rw-r--r-- | types.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -5,9 +5,10 @@ #include <limits.h> #include <math.h> +#include "builtins/integers.h" #include "builtins/table.h" -#include "types.h" #include "builtins/util.h" +#include "types.h" CORD type_to_cord(type_t *t) { switch (t->tag) { @@ -373,7 +374,7 @@ PUREFUNC bool supports_optionals(type_t *t) switch (t->tag) { case BoolType: case CStringType: case BigIntType: case NumType: case TextType: case ArrayType: case SetType: case TableType: case FunctionType: case ClosureType: - case PointerType: + case PointerType: case IntType: return true; default: return false; } @@ -411,10 +412,10 @@ PUREFUNC size_t type_size(type_t *t) switch (nonnull->tag) { case IntType: switch (Match(t, IntType)->bits) { - case TYPE_IBITS64: return sizeof(struct { int64_t x; bool is_null; }); - case TYPE_IBITS32: return sizeof(int64_t); - case TYPE_IBITS16: return sizeof(int32_t); - case TYPE_IBITS8: return sizeof(int16_t); + case TYPE_IBITS64: return sizeof(OptionalInt64_t); + case TYPE_IBITS32: return sizeof(OptionalInt32_t); + case TYPE_IBITS16: return sizeof(OptionalInt16_t); + case TYPE_IBITS8: return sizeof(OptionalInt8_t); default: errx(1, "Invalid integer bit size"); } default: return type_size(nonnull); @@ -488,10 +489,10 @@ PUREFUNC size_t type_align(type_t *t) switch (nonnull->tag) { case IntType: switch (Match(t, IntType)->bits) { - case TYPE_IBITS64: return __alignof__(struct { int64_t x; bool is_null; }); - case TYPE_IBITS32: return __alignof__(int64_t); - case TYPE_IBITS16: return __alignof__(int32_t); - case TYPE_IBITS8: return __alignof__(int16_t); + case TYPE_IBITS64: return __alignof__(OptionalInt64_t); + case TYPE_IBITS32: return __alignof__(OptionalInt32_t); + case TYPE_IBITS16: return __alignof__(OptionalInt16_t); + case TYPE_IBITS8: return __alignof__(OptionalInt8_t); default: errx(1, "Invalid integer bit size"); } default: return type_align(nonnull); |
