Const typeinfos

This commit is contained in:
Bruce Hill 2024-02-27 13:47:29 -05:00
parent 805c26e65a
commit a7bbbe9584
12 changed files with 18 additions and 20 deletions

View File

@ -23,7 +23,7 @@ public CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type)
return *b ? "yes" : "no";
}
public TypeInfo Bool = {
public const TypeInfo Bool = {
.size=sizeof(bool),
.align=__alignof__(bool),
.tag=CustomInfo,

View File

@ -11,6 +11,6 @@
CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type);
extern TypeInfo Bool;
extern const TypeInfo Bool;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -48,7 +48,7 @@
} \
public const c_type KindOfInt##__min = min_val; \
public const c_type KindOfInt##__max = max_val; \
public TypeInfo KindOfInt = { \
public const TypeInfo KindOfInt = { \
.size=sizeof(c_type), \
.align=__alignof__(c_type), \
.tag=CustomInfo, \

View File

@ -23,7 +23,7 @@
CORD type_name ## __octal(c_type i, int64_t digits, bool prefix); \
c_type type_name ## __random(int64_t min, int64_t max); \
extern const c_type type_name ## __min, type_name##__max; \
extern TypeInfo type_name;
extern const TypeInfo type_name;
DEFINE_INT_TYPE(int64_t, Int64);
DEFINE_INT_TYPE(int32_t, Int32);

View File

@ -21,7 +21,7 @@ public CORD Memory__as_str(const void *p, bool colorize, const TypeInfo *type) {
return cord;
}
public TypeInfo Memory = {
public const TypeInfo Memory = {
.size=0,
.align=0,
.tag=CustomInfo,

View File

@ -5,7 +5,7 @@
#include "types.h"
extern TypeInfo Memory;
extern const 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

View File

@ -54,7 +54,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 TypeInfo Num64 = {
public const TypeInfo Num64 = {
.size=sizeof(double),
.align=__alignof__(double),
.tag=CustomInfo,
@ -109,7 +109,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 TypeInfo Num32 = {
public const TypeInfo Num32 = {
.size=sizeof(float),
.align=__alignof__(float),
.tag=CustomInfo,

View File

@ -39,7 +39,7 @@ F(tan) F(tanh) F(tgamma) F(trunc) F(y0) F(y1)
#define F(name) double (*Num64__##name)(double x, double y) = name;
F(atan2) F(copysign) F(fdim) F(hypot) F(nextafter) F(pow) F(remainder)
#undef F
extern TypeInfo Num64;
extern const TypeInfo Num64;
CORD Num32__as_str(const float *f, bool colorize, const TypeInfo *type);
int32_t Num32__compare(const float *x, const float *y, const TypeInfo *type);
@ -70,6 +70,6 @@ F(tan) F(tanh) F(tgamma) F(trunc) F(y0) F(y1)
#define F(name) float (*Num32__##name)(float x, float y) = name##f;
F(atan2) F(copysign) F(fdim) F(hypot) F(nextafter) F(pow) F(remainder)
#undef F
extern TypeInfo Num32;
extern const TypeInfo Num32;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -254,7 +254,7 @@ public CORD Str__join(CORD glue, Str_Array_t pieces)
return ret;
}
public TypeInfo Str = {
public const TypeInfo Str = {
.size=sizeof(CORD),
.align=__alignof__(CORD),
.tag=CustomInfo,

View File

@ -39,6 +39,6 @@ CORD Str__replace(CORD text, CORD pat, CORD replacement, int64_t limit);
Str_Array_t Str__split(CORD str, CORD split);
CORD Str__join(CORD glue, Str_Array_t pieces);
extern TypeInfo Str;
extern const TypeInfo Str;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -23,19 +23,15 @@ public CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *ty
return c;
}
public TypeInfo TypeInfo_info = {
public const TypeInfo TypeInfo_info = {
.size=sizeof(TypeInfo),
.align=__alignof__(TypeInfo),
.tag=CustomInfo,
.TypeInfoInfo.type_str="TypeInfo",
};
public struct {
TypeInfo type;
} Void = {.type={.size=0, .align=0}};
public struct {
TypeInfo type;
} Abort = {.type={.size=0, .align=0}};
public const TypeInfo Void = {.size=0, .align=0};
public const TypeInfo Abort = {.size=0, .align=0};
public CORD Func__as_str(const void *fn, bool colorize, const TypeInfo *type)
{

View File

@ -55,7 +55,9 @@ typedef struct TypeInfo {
#define $TypeInfoInfo(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \
.tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr})
extern TypeInfo TypeInfo_info;
extern const TypeInfo TypeInfo_info;
extern const TypeInfo Void;
extern const TypeInfo Abort;
CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *type);
CORD Func__as_str(const void *fn, bool colorize, const TypeInfo *type);