diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 18:16:33 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-03 18:16:33 -0500 |
| commit | 23478e7036fe9fbee17263e52d5d8a37adce1c95 (patch) | |
| tree | 7c588c0f7b7ac2f81dbbd960a8f70b197613b229 /builtins | |
| parent | 8fab88c56f95c03ffcb4be178f5dbb21b239d95e (diff) | |
Rename as_str -> as_text
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/array.c | 6 | ||||
| -rw-r--r-- | builtins/array.h | 4 | ||||
| -rw-r--r-- | builtins/bool.c | 4 | ||||
| -rw-r--r-- | builtins/bool.h | 2 | ||||
| -rw-r--r-- | builtins/functions.c | 20 | ||||
| -rw-r--r-- | builtins/functions.h | 2 | ||||
| -rw-r--r-- | builtins/integers.c | 4 | ||||
| -rw-r--r-- | builtins/integers.h | 2 | ||||
| -rw-r--r-- | builtins/memory.c | 4 | ||||
| -rw-r--r-- | builtins/memory.h | 2 | ||||
| -rw-r--r-- | builtins/nums.c | 8 | ||||
| -rw-r--r-- | builtins/nums.h | 4 | ||||
| -rw-r--r-- | builtins/pointer.c | 6 | ||||
| -rw-r--r-- | builtins/table.c | 12 | ||||
| -rw-r--r-- | builtins/table.h | 4 | ||||
| -rw-r--r-- | builtins/text.c | 4 | ||||
| -rw-r--r-- | builtins/text.h | 2 | ||||
| -rw-r--r-- | builtins/types.c | 4 | ||||
| -rw-r--r-- | builtins/types.h | 6 |
19 files changed, 50 insertions, 50 deletions
diff --git a/builtins/array.c b/builtins/array.c index 66060a71..ee583b5b 100644 --- a/builtins/array.c +++ b/builtins/array.c @@ -293,17 +293,17 @@ public bool Array__equal(const array_t *x, const array_t *y, const TypeInfo *typ return (Array__compare(x, y, type) == 0); } -public CORD Array__as_str(const array_t *arr, bool colorize, const TypeInfo *type) +public CORD Array__as_text(const array_t *arr, bool colorize, const TypeInfo *type) { if (!arr) - return CORD_all("[", generic_as_str(NULL, false, type->ArrayInfo.item), "]"); + return CORD_all("[", generic_as_text(NULL, false, type->ArrayInfo.item), "]"); const TypeInfo *item_type = type->ArrayInfo.item; CORD c = "["; for (int64_t i = 0; i < arr->length; i++) { if (i > 0) c = CORD_cat(c, ", "); - CORD item_cord = generic_as_str(arr->data + i*arr->stride, colorize, item_type); + CORD item_cord = generic_as_text(arr->data + i*arr->stride, colorize, item_type); c = CORD_cat(c, item_cord); } c = CORD_cat(c, "]"); diff --git a/builtins/array.h b/builtins/array.h index 021166b9..4706c227 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -12,7 +12,7 @@ const array_t $arr = x; int64_t $index = (int64_t)(i); \ int64_t $off = $index + ($index < 0) * ($arr.length + 1) - 1; \ if (__builtin_expect($off < 0 || $off >= $arr.length, 0)) \ - fail_source(filename, start, end, "Invalid array index: %r (array has length %ld)\n", Int__as_str(&$index, USE_COLOR, NULL), $arr.length); \ + fail_source(filename, start, end, "Invalid array index: %r (array has length %ld)\n", Int__as_text(&$index, USE_COLOR, NULL), $arr.length); \ (type*)($arr.data + $arr.stride * $off);}) #define $Array_get_unchecked(type, x, i) *({ const array_t $arr = x; int64_t $index = (int64_t)(i); \ int64_t $off = $index + ($index < 0) * ($arr.length + 1) - 1; \ @@ -53,6 +53,6 @@ array_t Array__concat(array_t x, array_t y, const TypeInfo *type); uint32_t Array__hash(const array_t *arr, const TypeInfo *type); int32_t Array__compare(const array_t *x, const array_t *y, const TypeInfo *type); bool Array__equal(const array_t *x, const array_t *y, const TypeInfo *type); -CORD Array__as_str(const array_t *arr, bool colorize, const TypeInfo *type); +CORD Array__as_text(const array_t *arr, bool colorize, const TypeInfo *type); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/bool.c b/builtins/bool.c index 257de6cb..327a101d 100644 --- a/builtins/bool.c +++ b/builtins/bool.c @@ -13,7 +13,7 @@ #include "bool.h" #include "types.h" -public CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type) +public CORD Bool__as_text(const bool *b, bool colorize, const TypeInfo *type) { (void)type; if (!b) return "Bool"; @@ -27,7 +27,7 @@ public const TypeInfo Bool = { .size=sizeof(bool), .align=__alignof__(bool), .tag=CustomInfo, - .CustomInfo={.as_str=(void*)Bool__as_str}, + .CustomInfo={.as_text=(void*)Bool__as_text}, }; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/bool.h b/builtins/bool.h index 5df30893..08b4126a 100644 --- a/builtins/bool.h +++ b/builtins/bool.h @@ -9,7 +9,7 @@ #define yes (Bool_t)true #define no (Bool_t)false -CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type); +CORD Bool__as_text(const bool *b, bool colorize, const TypeInfo *type); extern const TypeInfo Bool; diff --git a/builtins/functions.c b/builtins/functions.c index 5f66c1e1..69fe5934 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -107,18 +107,18 @@ public bool generic_equal(const void *x, const void *y, const TypeInfo *type) } } -public CORD generic_as_str(const void *obj, bool colorize, const TypeInfo *type) +public CORD generic_as_text(const void *obj, bool colorize, const TypeInfo *type) { switch (type->tag) { case PointerInfo: return Pointer__cord(obj, colorize, type); - case FunctionInfo: return Func__as_str(obj, colorize, type); - case ArrayInfo: return Array__as_str(obj, colorize, type); - case TableInfo: return Table_as_str(obj, colorize, type); - case TypeInfoInfo: return Type__as_str(obj, colorize, type); + case FunctionInfo: return Func__as_text(obj, colorize, type); + case ArrayInfo: return Array__as_text(obj, colorize, type); + case TableInfo: return Table_as_text(obj, colorize, type); + case TypeInfoInfo: return Type__as_text(obj, colorize, type); case CustomInfo: - if (!type->CustomInfo.as_str) + if (!type->CustomInfo.as_text) fail("No cord function provided for type!\n"); - return type->CustomInfo.as_str(obj, colorize, type); + return type->CustomInfo.as_text(obj, colorize, type); default: errx(1, "Invalid type tag: %d", type->tag); } } @@ -158,12 +158,12 @@ public void __doctest(void *expr, const TypeInfo *type, CORD expected, const cha CORD_fprintf(stderr, USE_COLOR ? "\x1b[33;1m>> \x1b[0m%.*s\x1b[m\n" : ">> %.*s\n", (end - start), file->text + start); if (expr) { - CORD expr_str = generic_as_str(expr, USE_COLOR, type); - CORD type_name = generic_as_str(NULL, false, type); + CORD expr_str = generic_as_text(expr, USE_COLOR, type); + CORD type_name = generic_as_text(NULL, false, type); CORD_fprintf(stderr, USE_COLOR ? "\x1b[2m=\x1b[0m %r \x1b[2m: %r\x1b[m\n" : "= %r : %r\n", expr_str, type_name); if (expected) { - CORD expr_plain = USE_COLOR ? generic_as_str(expr, false, type) : expr_str; + CORD expr_plain = USE_COLOR ? generic_as_text(expr, false, type) : expr_str; bool success = (CORD_cmp(expr_plain, expected) == 0); if (!success && CORD_chr(expected, 0, ':')) { success = (CORD_cmp(CORD_catn(3, expr_plain, " : ", type_name), expected) == 0); diff --git a/builtins/functions.h b/builtins/functions.h index 301630d8..8a6026a1 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -16,6 +16,6 @@ public void __doctest(void *expr, const TypeInfo *type, CORD expected, const cha uint32_t generic_hash(const void *obj, const TypeInfo *type); int32_t generic_compare(const void *x, const void *y, const TypeInfo *type); bool generic_equal(const void *x, const void *y, const TypeInfo *type); -CORD generic_as_str(const void *obj, bool colorize, const TypeInfo *type); +CORD generic_as_text(const void *obj, bool colorize, const TypeInfo *type); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/integers.c b/builtins/integers.c index 65046ad3..6de85c3e 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -15,7 +15,7 @@ #define str(a) #a #define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, min_val, max_val)\ - public CORD KindOfInt ## __as_str(const c_type *i, bool colorize, const TypeInfo *type) { \ + public CORD KindOfInt ## __as_text(const c_type *i, bool colorize, const TypeInfo *type) { \ (void)type; \ if (!i) return #KindOfInt; \ CORD c; \ @@ -62,7 +62,7 @@ .size=sizeof(c_type), \ .align=__alignof__(c_type), \ .tag=CustomInfo, \ - .CustomInfo={.compare=(void*)KindOfInt##__compare, .as_str=(void*)KindOfInt##__as_str}, \ + .CustomInfo={.compare=(void*)KindOfInt##__compare, .as_text=(void*)KindOfInt##__as_text}, \ }; DEFINE_INT_TYPE(int64_t, Int, "ld", INT64_MIN, INT64_MAX); diff --git a/builtins/integers.h b/builtins/integers.h index 1b42ee1e..79ce2643 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -16,7 +16,7 @@ #define I8(x) ((int8_t)x) #define DEFINE_INT_TYPE(c_type, type_name) \ - CORD type_name ## __as_str(const c_type *i, bool colorize, const TypeInfo *type); \ + CORD type_name ## __as_text(const c_type *i, bool colorize, const TypeInfo *type); \ int32_t type_name ## __compare(const c_type *x, const c_type *y, const TypeInfo *type); \ CORD type_name ## __format(c_type i, int64_t digits); \ CORD type_name ## __hex(c_type i, int64_t digits, bool uppercase, bool prefix); \ diff --git a/builtins/memory.c b/builtins/memory.c index 2ce2422e..41b1a841 100644 --- a/builtins/memory.c +++ b/builtins/memory.c @@ -13,7 +13,7 @@ #include "memory.h" #include "types.h" -public CORD Memory__as_str(const void *p, bool colorize, const TypeInfo *type) { +public CORD Memory__as_text(const void *p, bool colorize, const TypeInfo *type) { (void)type; if (!p) return "Memory"; CORD cord; @@ -25,7 +25,7 @@ public const TypeInfo Memory = { .size=0, .align=0, .tag=CustomInfo, - .CustomInfo={.as_str=(void*)Memory__as_str}, + .CustomInfo={.as_text=(void*)Memory__as_text}, }; // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/builtins/memory.h b/builtins/memory.h index ac041b36..af923837 100644 --- a/builtins/memory.h +++ b/builtins/memory.h @@ -6,6 +6,6 @@ #include "types.h" extern const TypeInfo Memory; -CORD Memory__as_str(const void *p, bool colorize, const TypeInfo *type); +CORD 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 ec4c445b..32ec89fb 100644 --- a/builtins/nums.c +++ b/builtins/nums.c @@ -12,7 +12,7 @@ #include "string.h" #include "types.h" -public CORD Num__as_str(const double *f, bool colorize, const TypeInfo *type) { +public CORD Num__as_text(const double *f, bool colorize, const TypeInfo *type) { (void)type; if (!f) return "Num"; CORD c; @@ -78,11 +78,11 @@ public const TypeInfo Num = { .CustomInfo={ .compare=(void*)Num__compare, .equal=(void*)Num__equal, - .as_str=(void*)Num__as_str, + .as_text=(void*)Num__as_text, }, }; -public CORD Num32__as_str(const float *f, bool colorize, const TypeInfo *type) { +public CORD Num32__as_text(const float *f, bool colorize, const TypeInfo *type) { (void)type; if (!f) return "Num32"; CORD c; @@ -148,7 +148,7 @@ public const TypeInfo Num32 = { .CustomInfo={ .compare=(void*)Num32__compare, .equal=(void*)Num32__equal, - .as_str=(void*)Num32__as_str, + .as_text=(void*)Num32__as_text, }, }; diff --git a/builtins/nums.h b/builtins/nums.h index a468e928..5b1b7c89 100644 --- a/builtins/nums.h +++ b/builtins/nums.h @@ -9,7 +9,7 @@ #define Num_t double #define Num32_t float -CORD Num__as_str(const double *f, bool colorize, const TypeInfo *type); +CORD Num__as_text(const double *f, bool colorize, const TypeInfo *type); int32_t Num__compare(const double *x, const double *y, const TypeInfo *type); bool Num__equal(const double *x, const double *y, const TypeInfo *type); bool Num__near(double a, double b, double ratio, double absolute); @@ -38,7 +38,7 @@ F(atan2) F(copysign) F(fdim) F(hypot) F(nextafter) F(pow) F(remainder) #undef F extern const TypeInfo Num; -CORD Num32__as_str(const float *f, bool colorize, const TypeInfo *type); +CORD Num32__as_text(const float *f, bool colorize, const TypeInfo *type); int32_t Num32__compare(const float *x, const float *y, const TypeInfo *type); bool Num32__equal(const float *x, const float *y, const TypeInfo *type); bool Num32__near(float a, float b, float ratio, float absolute); diff --git a/builtins/pointer.c b/builtins/pointer.c index d46ced00..bf844cbf 100644 --- a/builtins/pointer.c +++ b/builtins/pointer.c @@ -21,12 +21,12 @@ typedef struct recursion_s { public CORD Pointer__cord(const void *x, bool colorize, const TypeInfo *type) { auto ptr_info = type->PointerInfo; if (!x) { - CORD typename = generic_as_str(NULL, false, ptr_info.pointed); + CORD typename = generic_as_text(NULL, false, ptr_info.pointed); return colorize ? CORD_asprintf("\x1b[34;1m%s%s\x1b[m", ptr_info.sigil, typename) : CORD_cat(ptr_info.sigil, typename); } const void *ptr = *(const void**)x; if (!ptr) { - CORD typename = generic_as_str(NULL, false, ptr_info.pointed); + CORD typename = generic_as_text(NULL, false, ptr_info.pointed); return colorize ? CORD_asprintf("\x1b[34;1m!%s\x1b[m", typename) : CORD_cat("!", typename); } @@ -44,7 +44,7 @@ public CORD Pointer__cord(const void *x, bool colorize, const TypeInfo *type) { { // Stringify with this pointer flagged as a recursive one: recursion_t my_recursion = {.ptr=ptr, .next=recursion}; recursion = &my_recursion; - pointed = generic_as_str(ptr, colorize, ptr_info.pointed); + pointed = generic_as_text(ptr, colorize, ptr_info.pointed); recursion = recursion->next; } return colorize ? CORD_asprintf("\x1b[34;1m%s\x1b[m%r", ptr_info.sigil, pointed) : CORD_cat(ptr_info.sigil, pointed); diff --git a/builtins/table.c b/builtins/table.c index 523aae70..521b78ba 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -504,13 +504,13 @@ public uint32_t Table_hash(const table_t *t, const TypeInfo *type) return hash; } -public CORD Table_as_str(const table_t *t, bool colorize, const TypeInfo *type) +public CORD Table_as_text(const table_t *t, bool colorize, const TypeInfo *type) { assert(type->tag == TableInfo); auto table = type->TableInfo; if (!t) - return CORD_all("{", generic_as_str(NULL, false, table.key), "=>", generic_as_str(NULL, false, table.value), "}"); + return CORD_all("{", generic_as_text(NULL, false, table.key), "=>", generic_as_text(NULL, false, table.value), "}"); int64_t val_off = value_offset(type); CORD c = "{"; @@ -518,19 +518,19 @@ public CORD Table_as_str(const table_t *t, bool colorize, const TypeInfo *type) if (i > 0) c = CORD_cat(c, ", "); void *entry = GET_ENTRY(t, i); - c = CORD_cat(c, generic_as_str(entry, colorize, table.key)); + c = CORD_cat(c, generic_as_text(entry, colorize, table.key)); c = CORD_cat(c, "=>"); - c = CORD_cat(c, generic_as_str(entry + val_off, colorize, table.value)); + c = CORD_cat(c, generic_as_text(entry + val_off, colorize, table.value)); } if (t->fallback) { c = CORD_cat(c, "; fallback="); - c = CORD_cat(c, Table_as_str(t->fallback, colorize, type)); + c = CORD_cat(c, Table_as_text(t->fallback, colorize, type)); } if (t->default_value) { c = CORD_cat(c, "; default="); - c = CORD_cat(c, generic_as_str(t->default_value, colorize, table.value)); + c = CORD_cat(c, generic_as_text(t->default_value, colorize, table.value)); } c = CORD_cat(c, "}"); diff --git a/builtins/table.h b/builtins/table.h index 8060b11c..7439ee03 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -21,7 +21,7 @@ const table_t *$t = table_expr; key_t $k = key_expr; const TypeInfo* $info = info_expr; \ const val_t *$v = Table_get($t, &$k, $info); \ if (__builtin_expect($v == NULL, 0)) \ - fail_source(filename, start, end, "The key %r is not in this table\n", generic_as_str(&$k, USE_COLOR, $info->TableInfo.key)); \ + fail_source(filename, start, end, "The key %r is not in this table\n", generic_as_text(&$k, USE_COLOR, $info->TableInfo.key)); \ *$v; }) #define $TABLE_FOREACH(table_expr, key_type, k, value_type, v, value_offset, body, else_body) {\ array_t $entries = (table_expr).entries; \ @@ -49,7 +49,7 @@ void Table_mark_copy_on_write(table_t *t); int32_t Table_compare(const table_t *x, const table_t *y, const TypeInfo *type); bool Table_equal(const table_t *x, const table_t *y, const TypeInfo *type); uint32_t Table_hash(const table_t *t, const TypeInfo *type); -CORD Table_as_str(const table_t *t, bool colorize, const TypeInfo *type); +CORD Table_as_text(const table_t *t, bool colorize, const TypeInfo *type); void *Table_str_entry(const table_t *t, int64_t n); void *Table_str_get(const table_t *t, const char *key); diff --git a/builtins/text.c b/builtins/text.c index d85c03f0..a17ce23b 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -18,7 +18,7 @@ #define CLAMP(x, lo, hi) MIN(hi, MAX(x,lo)) -public CORD Text__as_str(const void *str, bool colorize, const TypeInfo *info) +public CORD Text__as_text(const void *str, bool colorize, const TypeInfo *info) { (void)info; if (!str) return "Text"; @@ -253,7 +253,7 @@ public const TypeInfo Text = { .align=__alignof__(CORD), .tag=CustomInfo, .CustomInfo={ - .as_str=(void*)Text__as_str, + .as_text=(void*)Text__as_text, .compare=(void*)Text__compare, .equal=(void*)Text__equal, .hash=(void*)Text__hash, diff --git a/builtins/text.h b/builtins/text.h index a8782d24..ecb6e603 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -14,7 +14,7 @@ typedef struct { int32_t index; } find_result_t; -CORD Text__as_str(const void *str, bool colorize, const TypeInfo *info); +CORD Text__as_text(const void *str, bool colorize, const TypeInfo *info); CORD Text__quoted(CORD str, bool colorize); int Text__compare(CORD *x, CORD *y); bool Text__equal(CORD *x, CORD *y); diff --git a/builtins/types.c b/builtins/types.c index f016ae24..59bf5c47 100644 --- a/builtins/types.c +++ b/builtins/types.c @@ -12,7 +12,7 @@ #include "../util.h" #include "../SipHash/halfsiphash.h" -public CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *type) +public CORD Type__as_text(const void *typeinfo, bool colorize, const TypeInfo *type) { if (!typeinfo) return "TypeInfo"; @@ -33,7 +33,7 @@ public const TypeInfo TypeInfo_info = { 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) +public CORD Func__as_text(const void *fn, bool colorize, const TypeInfo *type) { (void)fn; CORD c = type->FunctionInfo.type_str; diff --git a/builtins/types.h b/builtins/types.h index 019cc970..397e14c1 100644 --- a/builtins/types.h +++ b/builtins/types.h @@ -21,7 +21,7 @@ typedef struct TypeInfo { equal_fn_t equal; compare_fn_t compare; hash_fn_t hash; - str_fn_t as_str; + str_fn_t as_text; } CustomInfo; struct { const char *sigil; @@ -59,7 +59,7 @@ 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); +CORD Type__as_text(const void *typeinfo, bool colorize, const TypeInfo *type); +CORD Func__as_text(const void *fn, bool colorize, const TypeInfo *type); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
