diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-30 14:39:30 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-30 14:39:30 -0400 |
| commit | 1a6ce0047bbc5125c386f65ae348688f98a9bb3f (patch) | |
| tree | ee56e2b3535ddcbc36fab5240d804d95f7744b5f /stdlib/types.h | |
| parent | 2ba07c2cf53a765d4decb2cb09dbf5e1e99f1966 (diff) | |
Rename TypeInfo -> TypeInfo_t and fix up some typeinfo code
Diffstat (limited to 'stdlib/types.h')
| -rw-r--r-- | stdlib/types.h | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/stdlib/types.h b/stdlib/types.h index bcdafad2..7e113dc0 100644 --- a/stdlib/types.h +++ b/stdlib/types.h @@ -7,14 +7,14 @@ #include "datatypes.h" -struct TypeInfo; +struct TypeInfo_t; -typedef uint64_t (*hash_fn_t)(const void*, const struct TypeInfo*); -typedef int32_t (*compare_fn_t)(const void*, const void*, const struct TypeInfo*); -typedef bool (*equal_fn_t)(const void*, const void*, const struct TypeInfo*); -typedef Text_t (*text_fn_t)(const void*, bool, const struct TypeInfo*); +typedef uint64_t (*hash_fn_t)(const void*, const struct TypeInfo_t*); +typedef int32_t (*compare_fn_t)(const void*, const void*, const struct TypeInfo_t*); +typedef bool (*equal_fn_t)(const void*, const void*, const struct TypeInfo_t*); +typedef Text_t (*text_fn_t)(const void*, bool, const struct TypeInfo_t*); -typedef struct TypeInfo { +typedef struct TypeInfo_t { int64_t size, align; struct { // Anonymous tagged union for convenience enum { CustomInfo, StructInfo, EnumInfo, PointerInfo, TextInfo, ArrayInfo, ChannelInfo, TableInfo, FunctionInfo, @@ -28,16 +28,16 @@ typedef struct TypeInfo { } CustomInfo; struct { const char *sigil; - const struct TypeInfo *pointed; + const struct TypeInfo_t *pointed; } PointerInfo; struct { const char *lang; } TextInfo; struct { - const struct TypeInfo *item; + const struct TypeInfo_t *item; } ArrayInfo, ChannelInfo; struct { - const struct TypeInfo *key, *value; + const struct TypeInfo_t *key, *value; } TableInfo; struct { const char *type_str; @@ -46,7 +46,7 @@ typedef struct TypeInfo { const char *type_str; } TypeInfoInfo; struct { - const struct TypeInfo *type; + const struct TypeInfo_t *type; } OptionalInfo; #pragma GCC diagnostic ignored "-Wpedantic" struct {} OpaqueInfo; @@ -55,32 +55,31 @@ typedef struct TypeInfo { } EmptyStructInfo; }; }; -} TypeInfo; +} TypeInfo_t; -#define Pointer$info(sigil_expr, pointed_info) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ +#define Pointer$info(sigil_expr, pointed_info) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \ .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info}}) -#define Array$info(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \ +#define Array$info(item_info) &((TypeInfo_t){.size=sizeof(Array_t), .align=__alignof__(Array_t), \ .tag=ArrayInfo, .ArrayInfo.item=item_info}) -#define Set$info(item_info) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ +#define Set$info(item_info) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&Void$info}) -#define Channel$info(item_info) &((TypeInfo){.size=sizeof(Channel_t), .align=__alignof__(Channel_t), \ +#define Channel$info(item_info) &((TypeInfo_t){.size=sizeof(Channel_t), .align=__alignof__(Channel_t), \ .tag=ChannelInfo, .ChannelInfo.item=item_info}) -#define Table$info(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ +#define Table$info(key_expr, value_expr) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ .tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr}) -#define Function$info(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ +#define Function$info(typestr) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) -#define Closure$info(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \ +#define Closure$info(typestr) &((TypeInfo_t){.size=sizeof(void*[2]), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) -#define TypeInfo$info(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \ - .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr}) -#define Optional$info(t) &((TypeInfo){.size=(t)->size, .align=(t)->align, \ +#define Type$info(typestr) &((TypeInfo_t){.size=sizeof(TypeInfo_t), .align=__alignof__(TypeInfo_t), \ + .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr}) +#define Optional$info(t) &((TypeInfo_t){.size=(t)->size, .align=(t)->align, \ .tag=OptionalInfo, .OptionalInfo.type=t}) -extern const TypeInfo TypeInfo$info; -extern const TypeInfo Void$info; -extern const TypeInfo Abort$info; +extern const TypeInfo_t Void$info; +extern const TypeInfo_t Abort$info; #define Void_t void -Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo *type); +Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
