aboutsummaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 15:33:47 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 15:33:47 -0400
commite422079fcced744e3a6247aeb12a09a658989072 (patch)
tree393d5e52ba67dcc822ccfa9a812198edda5e735d /types.c
parent259c7efcf8c3808d8151d8e15f1167ad2b6f2ca7 (diff)
Add a Byte datatype
Diffstat (limited to 'types.c')
-rw-r--r--types.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/types.c b/types.c
index bc54015c..b1269bbb 100644
--- a/types.c
+++ b/types.c
@@ -23,6 +23,7 @@ CORD type_to_cord(type_t *t) {
case VoidType: return "Void";
case MemoryType: return "Memory";
case BoolType: return "Bool";
+ case ByteType: return "Byte";
case CStringType: return "CString";
case TextType: return Match(t, TextType)->lang ? Match(t, TextType)->lang : "Text";
case BigIntType: return "Int";
@@ -165,6 +166,7 @@ static PUREFUNC inline double type_min_magnitude(type_t *t)
{
switch (t->tag) {
case BoolType: return (double)false;
+ case ByteType: return 0;
case BigIntType: return -1./0.;
case IntType: {
switch (Match(t, IntType)->bits) {
@@ -184,6 +186,7 @@ static PUREFUNC inline double type_max_magnitude(type_t *t)
{
switch (t->tag) {
case BoolType: return (double)true;
+ case ByteType: return (double)UINT8_MAX;
case BigIntType: return 1./0.;
case IntType: {
switch (Match(t, IntType)->bits) {
@@ -396,7 +399,7 @@ PUREFUNC bool is_numeric_type(type_t *t)
PUREFUNC bool supports_optionals(type_t *t)
{
switch (t->tag) {
- case BoolType: case CStringType: case BigIntType: case NumType: case TextType:
+ case BoolType: case ByteType: case CStringType: case BigIntType: case NumType: case TextType:
case ArrayType: case SetType: case TableType: case FunctionType: case ClosureType:
case PointerType: case IntType:
return true;
@@ -411,6 +414,7 @@ PUREFUNC size_t type_size(type_t *t)
case UnknownType: case AbortType: case ReturnType: case VoidType: return 0;
case MemoryType: errx(1, "Memory has undefined type size");
case BoolType: return sizeof(bool);
+ case ByteType: return sizeof(uint8_t);
case CStringType: return sizeof(char*);
case BigIntType: return sizeof(Int_t);
case IntType: {
@@ -489,6 +493,7 @@ PUREFUNC size_t type_align(type_t *t)
case UnknownType: case AbortType: case ReturnType: case VoidType: return 0;
case MemoryType: errx(1, "Memory has undefined type alignment");
case BoolType: return __alignof__(bool);
+ case ByteType: return __alignof__(uint8_t);
case CStringType: return __alignof__(char*);
case BigIntType: return __alignof__(Int_t);
case IntType: {