diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-05 15:31:54 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-05 15:31:54 -0400 |
| commit | 04c8fb0362dc4f922c1e96ca01fb87a3e8e74214 (patch) | |
| tree | a5a65a625a9b697ac6875874b9b4c04abd3d0a65 /builtins | |
| parent | 391c1b6bde0d5fd6f306f9613109e18ec487afe7 (diff) | |
Replace $Type with Type$info for builtin TypeInfos
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/array.c | 2 | ||||
| -rw-r--r-- | builtins/bool.c | 2 | ||||
| -rw-r--r-- | builtins/bool.h | 2 | ||||
| -rw-r--r-- | builtins/c_string.c | 2 | ||||
| -rw-r--r-- | builtins/c_string.h | 2 | ||||
| -rw-r--r-- | builtins/integers.c | 8 | ||||
| -rw-r--r-- | builtins/integers.h | 6 | ||||
| -rw-r--r-- | builtins/memory.c | 2 | ||||
| -rw-r--r-- | builtins/memory.h | 2 | ||||
| -rw-r--r-- | builtins/nums.c | 4 | ||||
| -rw-r--r-- | builtins/nums.h | 4 | ||||
| -rw-r--r-- | builtins/pointer.c | 2 | ||||
| -rw-r--r-- | builtins/range.c | 12 | ||||
| -rw-r--r-- | builtins/table.c | 12 | ||||
| -rw-r--r-- | builtins/table.h | 4 | ||||
| -rw-r--r-- | builtins/text.c | 10 | ||||
| -rw-r--r-- | builtins/text.h | 4 | ||||
| -rw-r--r-- | builtins/types.c | 6 | ||||
| -rw-r--r-- | builtins/types.h | 26 |
19 files changed, 56 insertions, 56 deletions
diff --git a/builtins/array.c b/builtins/array.c index 32aeab23..174bcbdd 100644 --- a/builtins/array.c +++ b/builtins/array.c @@ -282,7 +282,7 @@ public Table_t Array$counts(Array_t arr, const TypeInfo *type) { Table_t counts = {}; const TypeInfo count_type = {.size=sizeof(Table_t), .align=__alignof__(Table_t), - .tag=TableInfo, .TableInfo.key=type->ArrayInfo.item, .TableInfo.value=&$Int}; + .tag=TableInfo, .TableInfo.key=type->ArrayInfo.item, .TableInfo.value=&Int$info}; for (int64_t i = 0; i < arr.length; i++) { void *key = arr.data + i*arr.stride; int64_t *count = Table$get(counts, key, &count_type); diff --git a/builtins/bool.c b/builtins/bool.c index b3ba0bd7..677cfd97 100644 --- a/builtins/bool.c +++ b/builtins/bool.c @@ -48,7 +48,7 @@ public Bool_t Bool$random(double p) return (drand48() < p); } -public const TypeInfo $Bool = { +public const TypeInfo Bool$info = { .size=sizeof(bool), .align=__alignof__(bool), .tag=CustomInfo, diff --git a/builtins/bool.h b/builtins/bool.h index 578cad6c..cf2237fd 100644 --- a/builtins/bool.h +++ b/builtins/bool.h @@ -16,6 +16,6 @@ Text_t Bool$as_text(const bool *b, bool colorize, const TypeInfo *type); bool Bool$from_text(Text_t text, bool *success); Bool_t Bool$random(double p); -extern const TypeInfo $Bool; +extern const TypeInfo Bool$info; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/c_string.c b/builtins/c_string.c index 47ea4858..b0c70f0a 100644 --- a/builtins/c_string.c +++ b/builtins/c_string.c @@ -46,7 +46,7 @@ public uint32_t CString$hash(const char **c_str) return hash; } -public const TypeInfo $CString = { +public const TypeInfo CString$info = { .size=sizeof(char*), .align=__alignof__(char*), .tag=CustomInfo, diff --git a/builtins/c_string.h b/builtins/c_string.h index d909083d..76c74c23 100644 --- a/builtins/c_string.h +++ b/builtins/c_string.h @@ -13,6 +13,6 @@ int CString$compare(const char **x, const char **y); bool CString$equal(const char **x, const char **y); uint64_t CString$hash(const char **str); -extern const TypeInfo $CString; +extern const TypeInfo CString$info; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/integers.c b/builtins/integers.c index 0f0400f1..aad4bf33 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -318,7 +318,7 @@ public Int_t Int$sqrt(Int_t i) public Int_t Int$random(Int_t min, Int_t max) { int32_t cmp = Int$compare_value(min, max); if (cmp > 0) { - Text_t min_text = Int$as_text(&min, false, &$Int), max_text = Int$as_text(&max, false, &$Int); + Text_t min_text = Int$as_text(&min, false, &Int$info), max_text = Int$as_text(&max, false, &Int$info); fail("Random minimum value (%k) is larger than the maximum value (%k)", &min_text, &max_text); } @@ -387,11 +387,11 @@ public Int_t Int$prev_prime(Int_t x) mpz_t p; mpz_init_set_int(p, x); if (mpz_prevprime(p, p) == 0) - fail("There is no prime number before %k", (Text_t[1]){Int$as_text(&x, false, &$Int)}); + fail("There is no prime number before %k", (Text_t[1]){Int$as_text(&x, false, &Int$info)}); return Int$from_mpz(p); } -public const TypeInfo $Int = { +public const TypeInfo Int$info = { .size=sizeof(Int_t), .align=__alignof__(Int_t), .tag=CustomInfo, @@ -476,7 +476,7 @@ public const TypeInfo $Int = { } \ public const c_type KindOfInt##$min = min_val; \ public const c_type KindOfInt##$max = max_val; \ - public const TypeInfo $ ## KindOfInt = { \ + public const TypeInfo KindOfInt##$info = { \ .size=sizeof(c_type), \ .align=__alignof__(c_type), \ .tag=CustomInfo, \ diff --git a/builtins/integers.h b/builtins/integers.h index d70f609a..e5765de3 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -38,7 +38,7 @@ return x < min ? min : (x > max ? max : x); \ } \ extern const c_type type_name ## $min, type_name##$max; \ - extern const TypeInfo $ ## type_name; \ + extern const TypeInfo type_name ## $info; \ static inline c_type type_name ## $divided_by(c_type D, c_type d) { \ c_type q = D/d, r = D%d; \ if (r < 0) { \ @@ -126,11 +126,11 @@ bool Int$is_prime(Int_t x, Int_t reps); Int_t Int$next_prime(Int_t x); Int_t Int$prev_prime(Int_t x); -extern const TypeInfo $Int; +extern const TypeInfo Int$info; static inline Int_t Int$clamped(Int_t x, Int_t low, Int_t high) { - return (Int$compare(&x, &low, &$Int) <= 0) ? low : (Int$compare(&x, &high, &$Int) >= 0 ? high : x); + return (Int$compare(&x, &low, &Int$info) <= 0) ? low : (Int$compare(&x, &high, &Int$info) >= 0 ? high : x); } // Fast-path inline versions for the common case where integer arithmetic is diff --git a/builtins/memory.c b/builtins/memory.c index 06fb7bb2..47ff081b 100644 --- a/builtins/memory.c +++ b/builtins/memory.c @@ -19,7 +19,7 @@ public Text_t Memory__as_text(const void *p, bool colorize, const TypeInfo *type return Text$format(colorize ? "\x1b[0;34;1mMemory<%p>\x1b[m" : "Memory<%p>", p); } -public const TypeInfo $Memory = { +public const TypeInfo Memory$info = { .size=0, .align=0, .tag=CustomInfo, diff --git a/builtins/memory.h b/builtins/memory.h index e3cb2983..9bde4617 100644 --- a/builtins/memory.h +++ b/builtins/memory.h @@ -8,7 +8,7 @@ #include "types.h" -extern const TypeInfo $Memory; +extern const TypeInfo Memory$info; Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo *type); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/nums.c b/builtins/nums.c index ab386c78..35ec9b18 100644 --- a/builtins/nums.c +++ b/builtins/nums.c @@ -82,7 +82,7 @@ public bool Num$isinf(double n) { return !!isinf(n); } public bool Num$finite(double n) { return !!finite(n); } public bool Num$isnan(double n) { return !!isnan(n); } -public const TypeInfo $Num = { +public const TypeInfo Num$info = { .size=sizeof(double), .align=__alignof__(double), .tag=CustomInfo, @@ -161,7 +161,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 const TypeInfo $Num32 = { +public const TypeInfo Num32$info = { .size=sizeof(float), .align=__alignof__(float), .tag=CustomInfo, diff --git a/builtins/nums.h b/builtins/nums.h index a3f862d7..059ac7bd 100644 --- a/builtins/nums.h +++ b/builtins/nums.h @@ -31,7 +31,7 @@ double Num$from_text(Text_t text, bool *success); static inline double Num$clamped(double x, double low, double high) { return (x <= low) ? low : (x >= high ? high : x); } -extern const TypeInfo $Num; +extern const TypeInfo Num$info; Text_t Num32$as_text(const float *f, bool colorize, const TypeInfo *type); int32_t Num32$compare(const float *x, const float *y, const TypeInfo *type); @@ -50,6 +50,6 @@ float Num32$nan(Text_t tag); static inline float Num32$clamped(float x, float low, float high) { return (x <= low) ? low : (x >= high ? high : x); } -extern const TypeInfo $Num32; +extern const TypeInfo Num32$info; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/pointer.c b/builtins/pointer.c index 5090edd9..bd18a1e4 100644 --- a/builtins/pointer.c +++ b/builtins/pointer.c @@ -54,7 +54,7 @@ public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo *type colorize ? Text("\x1b[34;1m") : Text(""), Text$from_str(ptr_info.sigil), Text(".."), - Int32$as_text(&depth, false, &$Int32), + Int32$as_text(&depth, false, &Int32$info), colorize ? Text("\x1b[m") : Text("")); if (ptr_info.is_optional) text = Text$concat(text, colorize ? Text("\x1b[34;1m?\x1b[m") : Text("?")); diff --git a/builtins/range.c b/builtins/range.c index 068d8cea..1c8106eb 100644 --- a/builtins/range.c +++ b/builtins/range.c @@ -19,18 +19,18 @@ static int32_t Range$compare(const Range_t *x, const Range_t *y, const TypeInfo { (void)type; if (x == y) return 0; - int32_t diff = Int$compare(&x->first, &y->first, &$Int); + int32_t diff = Int$compare(&x->first, &y->first, &Int$info); if (diff != 0) return diff; - diff = Int$compare(&x->last, &y->last, &$Int); + diff = Int$compare(&x->last, &y->last, &Int$info); if (diff != 0) return diff; - return Int$compare(&x->step, &y->step, &$Int); + return Int$compare(&x->step, &y->step, &Int$info); } static bool Range$equal(const Range_t *x, const Range_t *y, const TypeInfo *type) { (void)type; if (x == y) return true; - return Int$equal(&x->first, &y->first, &$Int) && Int$equal(&x->last, &y->last, &$Int) && Int$equal(&x->step, &y->step, &$Int); + return Int$equal(&x->first, &y->first, &Int$info) && Int$equal(&x->last, &y->last, &Int$info) && Int$equal(&x->step, &y->step, &Int$info); } static Text_t Range$as_text(const Range_t *r, bool use_color, const TypeInfo *type) @@ -40,8 +40,8 @@ static Text_t Range$as_text(const Range_t *r, bool use_color, const TypeInfo *ty return Text$format(use_color ? "\x1b[0;1mRange\x1b[m(first=%r, last=%r, step=%r)" : "Range(first=%r, last=%r, step=%r)", - Int$as_text(&r->first, use_color, &$Int), Int$as_text(&r->last, use_color, &$Int), - Int$as_text(&r->step, use_color, &$Int)); + Int$as_text(&r->first, use_color, &Int$info), Int$as_text(&r->last, use_color, &Int$info), + Int$as_text(&r->step, use_color, &Int$info)); } public Range_t Range$reversed(Range_t r) diff --git a/builtins/table.c b/builtins/table.c index b0b95af7..3a672e0f 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -48,7 +48,7 @@ static const TypeInfo MemoryPointer = { .tag=PointerInfo, .PointerInfo={ .sigil="@", - .pointed=&$Memory, + .pointed=&Memory$info, }, }; @@ -56,7 +56,7 @@ const TypeInfo CStrToVoidStarTable = { .size=sizeof(Table_t), .align=__alignof__(Table_t), .tag=TableInfo, - .TableInfo={.key=&$CString, .value=&MemoryPointer}, + .TableInfo={.key=&CString$info, .value=&MemoryPointer}, }; static inline size_t entry_size(const TypeInfo *info) @@ -446,8 +446,8 @@ public uint32_t Table$hash(const Table_t *t, const TypeInfo *type) // Where fallback and default hash to zero if absent auto table = type->TableInfo; uint32_t components[] = { - Array$hash(&t->entries, $ArrayInfo(table.key)), - Array$hash(&t->entries + value_offset(type), $ArrayInfo(table.value)), + Array$hash(&t->entries, Array$info(table.key)), + Array$hash(&t->entries + value_offset(type), Array$info(table.value)), t->fallback ? Table$hash(t->fallback, type) : 0, }; uint32_t hash; @@ -461,7 +461,7 @@ public Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *typ auto table = type->TableInfo; if (!t) { - if (table.value != &$Void) + if (table.value != &Void$info) return Text$concat( Text("{"), generic_as_text(NULL, false, table.key), @@ -482,7 +482,7 @@ public Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *typ text = Text$concat(text, Text(", ")); void *entry = GET_ENTRY(*t, i); text = Text$concat(text, generic_as_text(entry, colorize, table.key)); - if (table.value != &$Void) + if (table.value != &Void$info) text = Text$concat(text, Text(":"), generic_as_text(entry + val_off, colorize, table.value)); } diff --git a/builtins/table.h b/builtins/table.h index d7afb56f..cd267912 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -17,7 +17,7 @@ .data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \ .length=sizeof(ents)/sizeof(ents[0]), \ .stride=(void*)&ents[1] - (void*)&ents[0], \ - }, $TableInfo(key_info, value_info)); \ + }, Table$info(key_info, value_info)); \ table.fallback = fb; \ table; }) #define Set(item_t, item_info, N, ...) ({ \ @@ -26,7 +26,7 @@ .data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \ .length=sizeof(ents)/sizeof(ents[0]), \ .stride=(void*)&ents[1] - (void*)&ents[0], \ - }, $SetInfo(item_info)); \ + }, Set$info(item_info)); \ set; }) Table_t Table$from_entries(Array_t entries, const TypeInfo *type); diff --git a/builtins/text.c b/builtins/text.c index 4bca6516..39222ed4 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -126,7 +126,7 @@ static const TypeInfo GraphemeClusterInfo = { static const TypeInfo GraphemeIDLookupTableInfo = { .size=sizeof(Table_t), .align=__alignof__(Table_t), - .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&$Int32}, + .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&Int32$info}, }; int32_t get_synthetic_grapheme(const uint32_t *codepoints, int64_t utf32_len) @@ -1762,8 +1762,8 @@ public Text_t Text$as_text(const void *text, bool colorize, const TypeInfo *info { (void)info; if (!text) return info && info->TextInfo.lang ? Text$from_str(info->TextInfo.lang) : Text("Text"); - Text_t as_text = _quoted(*(Text_t*)text, colorize, info == &Pattern ? '/' : '"'); - if (info && info->TextInfo.lang && info != &$Text && info != &Pattern) + Text_t as_text = _quoted(*(Text_t*)text, colorize, info == &Pattern$info ? '/' : '"'); + if (info && info->TextInfo.lang && info != &Text$info && info != &Pattern$info) as_text = Text$concat( colorize ? Text("\x1b[1m$") : Text("$"), Text$from_str(info->TextInfo.lang), @@ -2165,7 +2165,7 @@ public Array_t Text$lines(Text_t text) return lines; } -public const TypeInfo $Text = { +public const TypeInfo Text$info = { .size=sizeof(Text_t), .align=__alignof__(Text_t), .tag=TextInfo, @@ -2202,7 +2202,7 @@ public Pattern_t Pattern$escape_text(Text_t text) #undef add_escaped } -public const TypeInfo Pattern = { +public const TypeInfo Pattern$info = { .size=sizeof(Text_t), .align=__alignof__(Text_t), .tag=TextInfo, diff --git a/builtins/text.h b/builtins/text.h index a8ca85fc..eff01dbe 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -54,11 +54,11 @@ Text_t Text$join(Text_t glue, Array_t pieces); Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn); Text_t Text$repeat(Text_t text, Int_t count); -extern const TypeInfo $Text; +extern const TypeInfo Text$info; #define Pattern(text) ((Pattern_t)Text(text)) #define Patterns(...) ((Pattern_t)Texts(__VA_ARGS__)) Pattern_t Pattern$escape_text(Text_t text); -extern const TypeInfo Pattern; +extern const TypeInfo Pattern$info; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/types.c b/builtins/types.c index c34882f0..6d9e2408 100644 --- a/builtins/types.c +++ b/builtins/types.c @@ -25,15 +25,15 @@ public Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo * return Text$from_str(type->TypeInfoInfo.type_str); } -public const TypeInfo $TypeInfo = { +public const TypeInfo TypeInfo$info = { .size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), .tag=CustomInfo, .TypeInfoInfo.type_str="TypeInfo", }; -public const TypeInfo $Void = {.size=0, .align=0, .tag=EmptyStruct}; -public const TypeInfo $Abort = {.size=0, .align=0, .tag=EmptyStruct}; +public const TypeInfo Void$info = {.size=0, .align=0, .tag=EmptyStruct}; +public const TypeInfo Abort$info = {.size=0, .align=0, .tag=EmptyStruct}; public Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo *type) { diff --git a/builtins/types.h b/builtins/types.h index 24640f89..70cf89c3 100644 --- a/builtins/types.h +++ b/builtins/types.h @@ -53,26 +53,26 @@ typedef struct TypeInfo { }; } TypeInfo; -#define $PointerInfo(sigil_expr, pointed_info, opt) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ - .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info, .is_optional=opt}}) -#define $ArrayInfo(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \ +#define Pointer$info(sigil_expr, pointed_info, opt) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ + .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info, .is_optional=opt}}) +#define Array$info(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \ .tag=ArrayInfo, .ArrayInfo.item=item_info}) -#define $SetInfo(item_info) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ - .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&$Void}) -#define $ChannelInfo(item_info) &((TypeInfo){.size=sizeof(channel_t), .align=__alignof__(channel_t), \ +#define Set$info(item_info) &((TypeInfo){.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), \ .tag=ChannelInfo, .ChannelInfo.item=item_info}) -#define $TableInfo(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ +#define Table$info(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \ .tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr}) -#define $FunctionInfo(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ +#define Function$info(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) -#define $ClosureInfo(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \ +#define Closure$info(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \ .tag=FunctionInfo, .FunctionInfo.type_str=typestr}) -#define $TypeInfoInfo(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \ +#define TypeInfo$info(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \ .tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr}) -extern const TypeInfo $TypeInfo; -extern const TypeInfo $Void; -extern const TypeInfo $Abort; +extern const TypeInfo TypeInfo$info; +extern const TypeInfo Void$info; +extern const TypeInfo Abort$info; #define Void_t void Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo *type); |
