aboutsummaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-05-21 13:42:33 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-05-21 13:42:33 -0400
commit760f46e71c2a430c5824e79539af4b3537f307f0 (patch)
treed42cf5bc5cad9f7035ae30fe15fef22fa8bb66d1 /builtins
parentc5c3be9e5d74cda08df2c36412e0a652f1433d4f (diff)
Reduce codegen output for enums without data attached to any tags
Diffstat (limited to 'builtins')
-rw-r--r--builtins/functions.c4
-rw-r--r--builtins/types.h5
2 files changed, 8 insertions, 1 deletions
diff --git a/builtins/functions.c b/builtins/functions.c
index b2808c5a..bed3dbfd 100644
--- a/builtins/functions.c
+++ b/builtins/functions.c
@@ -81,6 +81,7 @@ public uint32_t generic_hash(const void *obj, const TypeInfo *type)
case TextInfo: return Text$hash(obj);
case ArrayInfo: return Array$hash(obj, type);
case TableInfo: return Table$hash(obj, type);
+ case EmptyStruct: return 0;
case CustomInfo:
if (!type->CustomInfo.hash)
goto hash_data;
@@ -101,6 +102,7 @@ public int32_t generic_compare(const void *x, const void *y, const TypeInfo *typ
case TextInfo: return Text$compare(x, y);
case ArrayInfo: return Array$compare(x, y, type);
case TableInfo: return Table$compare(x, y, type);
+ case EmptyStruct: return 0;
case CustomInfo:
if (!type->CustomInfo.compare)
goto compare_data;
@@ -118,6 +120,7 @@ public bool generic_equal(const void *x, const void *y, const TypeInfo *type)
case TextInfo: return Text$equal(x, y);
case ArrayInfo: return Array$equal(x, y, type);
case TableInfo: return Table$equal(x, y, type);
+ case EmptyStruct: return true;
case CustomInfo:
if (!type->CustomInfo.equal)
goto use_generic_compare;
@@ -137,6 +140,7 @@ public CORD generic_as_text(const void *obj, bool colorize, const TypeInfo *type
case ArrayInfo: return Array$as_text(obj, colorize, type);
case TableInfo: return Table$as_text(obj, colorize, type);
case TypeInfoInfo: return Type$as_text(obj, colorize, type);
+ case EmptyStruct: return colorize ? CORD_all("\x1b[0;1m", type->EmptyStruct.name, "\x1b[m()") : CORD_all(type->EmptyStruct.name, "()");
case CustomInfo:
if (!type->CustomInfo.as_text)
fail("No cord function provided for type!\n");
diff --git a/builtins/types.h b/builtins/types.h
index 3b517fd3..ac2166f0 100644
--- a/builtins/types.h
+++ b/builtins/types.h
@@ -18,7 +18,7 @@ typedef CORD (*str_fn_t)(const void*, bool, const struct TypeInfo*);
typedef struct TypeInfo {
int64_t size, align;
struct { // Anonymous tagged union for convenience
- enum { CustomInfo, PointerInfo, TextInfo, ArrayInfo, TableInfo, FunctionInfo, TypeInfoInfo, OpaqueInfo, } tag;
+ enum { CustomInfo, PointerInfo, TextInfo, ArrayInfo, TableInfo, FunctionInfo, TypeInfoInfo, OpaqueInfo, EmptyStruct } tag;
union {
struct {
equal_fn_t equal;
@@ -47,6 +47,9 @@ typedef struct TypeInfo {
const char *type_str;
} TypeInfoInfo;
struct {} OpaqueInfo;
+ struct {
+ const char *name;
+ } EmptyStruct;
};
};
} TypeInfo;