Overload type names with constructor and namespace struct
This commit is contained in:
parent
9564118202
commit
4a5c651d43
@ -25,7 +25,7 @@ public CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type)
|
||||
return *b ? "yes" : "no";
|
||||
}
|
||||
|
||||
public Bool_namespace_t Bool_type = {
|
||||
public Bool_namespace_t Bool = {
|
||||
.type={
|
||||
.size=sizeof(bool),
|
||||
.align=__alignof__(bool),
|
||||
|
@ -11,6 +11,6 @@ typedef struct {
|
||||
TypeInfo type;
|
||||
} Bool_namespace_t;
|
||||
|
||||
extern Bool_namespace_t Bool_type;
|
||||
extern Bool_namespace_t Bool;
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
||||
|
@ -46,7 +46,7 @@
|
||||
uint32_t r = arc4random_uniform((uint32_t)range); \
|
||||
return min + (c_type)r; \
|
||||
} \
|
||||
public KindOfInt##_namespace_t KindOfInt##_type = { \
|
||||
public KindOfInt##_namespace_t KindOfInt = { \
|
||||
.type={ \
|
||||
.size=sizeof(c_type), \
|
||||
.align=__alignof__(c_type), \
|
||||
|
@ -21,7 +21,7 @@
|
||||
CORD (*octal)(c_type i, int64_t digits, bool prefix); \
|
||||
c_type (*random)(int64_t min, int64_t max); \
|
||||
} type_name##_namespace_t; \
|
||||
extern type_name##_namespace_t type_name##_type;
|
||||
extern type_name##_namespace_t type_name;
|
||||
|
||||
DEFINE_INT_TYPE(int64_t, Int64);
|
||||
DEFINE_INT_TYPE(int32_t, Int32);
|
||||
@ -36,6 +36,6 @@ DEFINE_INT_TYPE(int8_t, Int8);
|
||||
#define Int__octal Int64__octal
|
||||
#define Int__random Int64__random
|
||||
#define Int_namespace_t Int64_namespace_t
|
||||
#define Int_type Int64_type
|
||||
#define Int Int64
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
||||
|
@ -21,7 +21,7 @@ public CORD Memory__as_str(const void *p, bool colorize, const TypeInfo *type) {
|
||||
return cord;
|
||||
}
|
||||
|
||||
public TypeInfo Memory_type = {
|
||||
public TypeInfo Memory = {
|
||||
.size=0,
|
||||
.align=0,
|
||||
.tag=CustomInfo,
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
extern TypeInfo Memory_type;
|
||||
extern TypeInfo Memory;
|
||||
CORD Memory__as_str(const void *p, bool colorize, const TypeInfo *type);
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
||||
|
@ -50,7 +50,7 @@ public bool Num64__isinf(double n) { return isinf(n); }
|
||||
public bool Num64__finite(double n) { return finite(n); }
|
||||
public bool Num64__isnan(double n) { return isnan(n); }
|
||||
|
||||
public Num64_namespace_t Num64_type = {
|
||||
public Num64_namespace_t Num64 = {
|
||||
.type=(TypeInfo){
|
||||
.size=sizeof(double),
|
||||
.align=__alignof__(double),
|
||||
@ -120,7 +120,7 @@ public bool Num32__isinf(float n) { return isinf(n); }
|
||||
public bool Num32__finite(float n) { return finite(n); }
|
||||
public bool Num32__isnan(float n) { return isnan(n); }
|
||||
|
||||
public Num32_namespace_t Num32_type = {
|
||||
public Num32_namespace_t Num32 = {
|
||||
.type=(TypeInfo){
|
||||
.size=sizeof(float),
|
||||
.align=__alignof__(float),
|
||||
|
@ -39,7 +39,7 @@ typedef struct {
|
||||
CORD (*format)(double f, int64_t precision);
|
||||
CORD (*scientific)(double f, int64_t precision);
|
||||
} Num64_namespace_t;
|
||||
extern Num64_namespace_t Num64_type;
|
||||
extern Num64_namespace_t Num64;
|
||||
|
||||
CORD Num32__as_str(float *f, bool colorize, const TypeInfo *type);
|
||||
int32_t Num32__compare(const float *x, const float *y, const TypeInfo *type);
|
||||
@ -76,6 +76,6 @@ typedef struct {
|
||||
CORD (*format)(float f, int64_t precision);
|
||||
CORD (*scientific)(float f, int64_t precision);
|
||||
} Num32_namespace_t;
|
||||
extern Num32_namespace_t Num32_type;
|
||||
extern Num32_namespace_t Num32;
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
|
||||
|
@ -254,7 +254,7 @@ public CORD Str__join(CORD glue, Str_Array_t pieces)
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Str_namespace_t Str_type = {
|
||||
public Str_namespace_t Str = {
|
||||
.type={
|
||||
.size=sizeof(CORD),
|
||||
.align=__alignof__(CORD),
|
||||
|
@ -42,7 +42,7 @@ typedef struct {
|
||||
int (*hash)(CORD *s, TypeInfo *type);
|
||||
CORD (*cord)(CORD *s, bool colorize, TypeInfo *type);
|
||||
} Str_namespace_t;
|
||||
extern Str_namespace_t Str_type;
|
||||
extern Str_namespace_t Str;
|
||||
|
||||
CORD Str__quoted(CORD str, bool colorize);
|
||||
int Str__compare(CORD *x, CORD *y);
|
||||
|
@ -41,7 +41,7 @@
|
||||
#define GET_ENTRY(t, i) ((t)->entries.data + (t)->entries.stride*(i))
|
||||
#define ENTRIES_TYPE(type) (&(TypeInfo){.size=sizeof(array_t), .align=__alignof__(array_t), .tag=ArrayInfo, .ArrayInfo.item=(&(TypeInfo){.size=entry_size(type), .align=entry_align(type), .tag=OpaqueInfo})})
|
||||
|
||||
TypeInfo MemoryPointer_typeinfo = {
|
||||
TypeInfo MemoryPointer = {
|
||||
.size=sizeof(void*),
|
||||
.align=__alignof__(void*),
|
||||
.tag=PointerInfo,
|
||||
@ -51,11 +51,11 @@ TypeInfo MemoryPointer_typeinfo = {
|
||||
},
|
||||
};
|
||||
|
||||
TypeInfo StrToVoidStarTable_type = {
|
||||
TypeInfo StrToVoidStarTable = {
|
||||
.size=sizeof(table_t),
|
||||
.align=__alignof__(table_t),
|
||||
.tag=TableInfo,
|
||||
.TableInfo={.key=&Str_type.type, .value=&MemoryPointer_typeinfo},
|
||||
.TableInfo={.key=&Str.type, .value=&MemoryPointer},
|
||||
};
|
||||
|
||||
static inline size_t entry_size(const TypeInfo *info)
|
||||
@ -547,29 +547,29 @@ public table_t Table_from_entries(array_t entries, const TypeInfo *type)
|
||||
|
||||
void *Table_str_get(const table_t *t, const char *key)
|
||||
{
|
||||
void **ret = Table_get(t, &key, &StrToVoidStarTable_type);
|
||||
void **ret = Table_get(t, &key, &StrToVoidStarTable);
|
||||
return ret ? *ret : NULL;
|
||||
}
|
||||
|
||||
void *Table_str_get_raw(const table_t *t, const char *key)
|
||||
{
|
||||
void **ret = Table_get_raw(t, &key, &StrToVoidStarTable_type);
|
||||
void **ret = Table_get_raw(t, &key, &StrToVoidStarTable);
|
||||
return ret ? *ret : NULL;
|
||||
}
|
||||
|
||||
void *Table_str_reserve(table_t *t, const char *key, const void *value)
|
||||
{
|
||||
return Table_reserve(t, &key, &value, &StrToVoidStarTable_type);
|
||||
return Table_reserve(t, &key, &value, &StrToVoidStarTable);
|
||||
}
|
||||
|
||||
void Table_str_set(table_t *t, const char *key, const void *value)
|
||||
{
|
||||
Table_set(t, &key, &value, &StrToVoidStarTable_type);
|
||||
Table_set(t, &key, &value, &StrToVoidStarTable);
|
||||
}
|
||||
|
||||
void Table_str_remove(table_t *t, const char *key)
|
||||
{
|
||||
return Table_remove(t, &key, &StrToVoidStarTable_type);
|
||||
return Table_remove(t, &key, &StrToVoidStarTable);
|
||||
}
|
||||
|
||||
void *Table_str_entry(const table_t *t, int64_t n)
|
||||
|
@ -30,6 +30,6 @@ void Table_str_remove(table_t *t, const char *key);
|
||||
|
||||
#define Table_length(t) ((t)->entries.length)
|
||||
|
||||
extern TypeInfo StrToVoidStarTable_type;
|
||||
extern TypeInfo StrToVoidStarTable;
|
||||
|
||||
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
|
||||
|
@ -23,9 +23,7 @@ public CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *ty
|
||||
return c;
|
||||
}
|
||||
|
||||
public struct {
|
||||
TypeInfo type;
|
||||
} TypeInfo_type = {
|
||||
public TypeInfo_namespace_t TypeInfo_namespace = {
|
||||
.type={
|
||||
.size=sizeof(TypeInfo),
|
||||
.align=__alignof__(TypeInfo),
|
||||
@ -36,10 +34,10 @@ public struct {
|
||||
|
||||
public struct {
|
||||
TypeInfo type;
|
||||
} Void_type = {.type={.size=0, .align=0}};
|
||||
} Void = {.type={.size=0, .align=0}};
|
||||
public struct {
|
||||
TypeInfo type;
|
||||
} Abort_type = {.type={.size=0, .align=0}};
|
||||
} Abort = {.type={.size=0, .align=0}};
|
||||
|
||||
public CORD Func__as_str(const void *fn, bool colorize, const TypeInfo *type)
|
||||
{
|
||||
|
@ -44,6 +44,12 @@ typedef struct TypeInfo {
|
||||
};
|
||||
} TypeInfo;
|
||||
|
||||
typedef struct {
|
||||
TypeInfo type;
|
||||
} TypeInfo_namespace_t;
|
||||
|
||||
extern TypeInfo_namespace_t TypeInfo_namespace;
|
||||
|
||||
CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *type);
|
||||
CORD Func__as_str(const void *fn, bool colorize, const TypeInfo *type);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user