From bba9f1b141fba5ffc366ef9377fb3089c0c5a1a3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 11:08:15 -0400 Subject: Optional fixed-size ints --- types.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'types.c') diff --git a/types.c b/types.c index c91e6eb2..daa1026f 100644 --- a/types.c +++ b/types.c @@ -5,9 +5,10 @@ #include #include +#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); -- cgit v1.2.3