aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/types.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/types.h')
-rw-r--r--src/stdlib/types.h63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/stdlib/types.h b/src/stdlib/types.h
index 60f1fcfd..a6509183 100644
--- a/src/stdlib/types.h
+++ b/src/stdlib/types.h
@@ -10,13 +10,13 @@
typedef struct TypeInfo_s TypeInfo_t;
-typedef void (*serialize_fn_t)(const void*, FILE*, Table_t*, const TypeInfo_t*);
-typedef void (*deserialize_fn_t)(FILE*, void*, List_t*, const TypeInfo_t*);
-typedef bool (*is_none_fn_t)(const void*, const TypeInfo_t*);
-typedef uint64_t (*hash_fn_t)(const void*, const TypeInfo_t*);
-typedef int32_t (*compare_fn_t)(const void*, const void*, const TypeInfo_t*);
-typedef bool (*equal_fn_t)(const void*, const void*, const TypeInfo_t*);
-typedef Text_t (*as_text_fn_t)(const void*, bool, const TypeInfo_t*);
+typedef void (*serialize_fn_t)(const void *, FILE *, Table_t *, const TypeInfo_t *);
+typedef void (*deserialize_fn_t)(FILE *, void *, List_t *, const TypeInfo_t *);
+typedef bool (*is_none_fn_t)(const void *, const TypeInfo_t *);
+typedef uint64_t (*hash_fn_t)(const void *, const TypeInfo_t *);
+typedef int32_t (*compare_fn_t)(const void *, const void *, const TypeInfo_t *);
+typedef bool (*equal_fn_t)(const void *, const void *, const TypeInfo_t *);
+typedef Text_t (*as_text_fn_t)(const void *, bool, const TypeInfo_t *);
typedef struct {
hash_fn_t hash;
@@ -36,11 +36,22 @@ typedef struct {
struct TypeInfo_s {
int64_t size, align;
metamethods_t metamethods;
- struct { // Anonymous tagged union for convenience
- enum { OpaqueInfo, StructInfo, EnumInfo, PointerInfo, TextInfo, ListInfo, TableInfo, FunctionInfo,
- OptionalInfo, TypeInfoInfo } tag;
+ struct { // Anonymous tagged union for convenience
+ enum {
+ OpaqueInfo,
+ StructInfo,
+ EnumInfo,
+ PointerInfo,
+ TextInfo,
+ ListInfo,
+ TableInfo,
+ FunctionInfo,
+ OptionalInfo,
+ TypeInfoInfo
+ } tag;
union {
- struct {} OpaqueInfo;
+ struct {
+ } OpaqueInfo;
struct {
const char *sigil;
const TypeInfo_t *pointed;
@@ -72,7 +83,7 @@ struct TypeInfo_s {
const char *name;
NamedType_t *fields;
int num_fields;
- bool is_secret:1, is_opaque:1;
+ bool is_secret : 1, is_opaque : 1;
} StructInfo;
};
};
@@ -84,18 +95,22 @@ extern const TypeInfo_t Abort$info;
Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type);
-#define Type$info(typestr) &((TypeInfo_t){.size=sizeof(TypeInfo_t), .align=__alignof__(TypeInfo_t), \
- .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr, \
- .metamethods={.serialize=cannot_serialize, .deserialize=cannot_deserialize, .as_text=Type$as_text}})
+#define Type$info(typestr) \
+ &((TypeInfo_t){ \
+ .size = sizeof(TypeInfo_t), \
+ .align = __alignof__(TypeInfo_t), \
+ .tag = TypeInfoInfo, \
+ .TypeInfoInfo.type_str = typestr, \
+ .metamethods = {.serialize = cannot_serialize, .deserialize = cannot_deserialize, .as_text = Type$as_text}})
-#define DEFINE_OPTIONAL_TYPE(t, unpadded_size, name) \
- typedef struct { \
- union { \
- t value; \
- struct { \
- char _padding[unpadded_size]; \
- Bool_t is_none; \
- }; \
- }; \
+#define DEFINE_OPTIONAL_TYPE(t, unpadded_size, name) \
+ typedef struct { \
+ union { \
+ t value; \
+ struct { \
+ char _padding[unpadded_size]; \
+ Bool_t is_none; \
+ }; \
+ }; \
} name
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0