aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins/array.c6
-rw-r--r--builtins/array.h4
-rw-r--r--builtins/bool.c4
-rw-r--r--builtins/bool.h2
-rw-r--r--builtins/functions.c20
-rw-r--r--builtins/functions.h2
-rw-r--r--builtins/integers.c4
-rw-r--r--builtins/integers.h2
-rw-r--r--builtins/memory.c4
-rw-r--r--builtins/memory.h2
-rw-r--r--builtins/nums.c8
-rw-r--r--builtins/nums.h4
-rw-r--r--builtins/pointer.c6
-rw-r--r--builtins/table.c12
-rw-r--r--builtins/table.h4
-rw-r--r--builtins/text.c4
-rw-r--r--builtins/text.h2
-rw-r--r--builtins/types.c4
-rw-r--r--builtins/types.h6
-rw-r--r--compile.c26
-rw-r--r--compile.h2
-rw-r--r--enums.c6
-rw-r--r--structs.c6
23 files changed, 70 insertions, 70 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
diff --git a/compile.c b/compile.c
index a4df2ba9..ae1a66bf 100644
--- a/compile.c
+++ b/compile.c
@@ -67,25 +67,25 @@ CORD compile_statement(env_t *env, ast_t *ast)
return stmt;
}
-CORD expr_as_string(env_t *env, CORD expr, type_t *t, CORD color)
+CORD expr_as_texting(env_t *env, CORD expr, type_t *t, CORD color)
{
switch (t->tag) {
- case MemoryType: return CORD_asprintf("Memory__as_str($stack(%r), %r, &Memory)", expr, color);
- case BoolType: return CORD_asprintf("Bool__as_str($stack(%r), %r, &Bool)", expr, color);
+ case MemoryType: return CORD_asprintf("Memory__as_text($stack(%r), %r, &Memory)", expr, color);
+ case BoolType: return CORD_asprintf("Bool__as_text($stack(%r), %r, &Bool)", expr, color);
case IntType: {
CORD name = type_to_cord(t);
- return CORD_asprintf("%r__as_str($stack(%r), %r, &%r)", name, expr, color, name);
+ return CORD_asprintf("%r__as_text($stack(%r), %r, &%r)", name, expr, color, name);
}
case NumType: {
CORD name = type_to_cord(t);
- return CORD_asprintf("%r__as_str($stack(%r), %r, &Num%r)", name, expr, color, name);
+ return CORD_asprintf("%r__as_text($stack(%r), %r, &Num%r)", name, expr, color, name);
}
- case TextType: return CORD_asprintf("Text__as_str($stack(%r), %r, &Text)", expr, color);
- case ArrayType: return CORD_asprintf("Array__as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
- case TableType: return CORD_asprintf("Table_as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
- case FunctionType: return CORD_asprintf("Func__as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
- case PointerType: return CORD_asprintf("Pointer__as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
- case StructType: case EnumType: return CORD_asprintf("(%r)->CustomInfo.as_str($stack(%r), %r, %r)",
+ case TextType: return CORD_asprintf("Text__as_text($stack(%r), %r, &Text)", expr, color);
+ case ArrayType: return CORD_asprintf("Array__as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
+ case TableType: return CORD_asprintf("Table_as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
+ case FunctionType: return CORD_asprintf("Func__as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
+ case PointerType: return CORD_asprintf("Pointer__as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
+ case StructType: case EnumType: return CORD_asprintf("(%r)->CustomInfo.as_text($stack(%r), %r, %r)",
compile_type_info(env, t), expr, color, compile_type_info(env, t));
default: compiler_err(NULL, NULL, NULL, "Stringifying is not supported for %T", t);
}
@@ -95,7 +95,7 @@ CORD compile_string(env_t *env, ast_t *ast, CORD color)
{
type_t *t = get_type(env, ast);
CORD expr = compile(env, ast);
- return expr_as_string(env, expr, t, color);
+ return expr_as_texting(env, expr, t, color);
}
static CORD compile_to_pointer_depth(env_t *env, ast_t *ast, int64_t target_depth, bool allow_optional)
@@ -882,7 +882,7 @@ CORD compile(env_t *env, ast_t *ast)
CORD expr_cord = "CORD_all(";
i = 1;
for (ast_list_t *target = assign->targets; target; target = target->next) {
- CORD item = expr_as_string(env, CORD_asprintf("$%ld", i++), get_type(env, target->ast), "USE_COLOR");
+ CORD item = expr_as_texting(env, CORD_asprintf("$%ld", i++), get_type(env, target->ast), "USE_COLOR");
expr_cord = CORD_all(expr_cord, item, target->next ? ", \", \", " : CORD_EMPTY);
}
expr_cord = CORD_cat(expr_cord, ")");
diff --git a/compile.h b/compile.h
index e3c2f368..df7464b7 100644
--- a/compile.h
+++ b/compile.h
@@ -12,7 +12,7 @@ typedef struct {
CORD header, c_file;
} module_code_t;
-CORD expr_as_string(env_t *env, CORD expr, type_t *t, CORD color);
+CORD expr_as_texting(env_t *env, CORD expr, type_t *t, CORD color);
module_code_t compile_file(ast_t *ast);
CORD compile_type_ast(type_ast_t *t);
CORD compile_type(type_t *t);
diff --git a/enums.c b/enums.c
index 46f13d4d..caa64018 100644
--- a/enums.c
+++ b/enums.c
@@ -15,7 +15,7 @@
static CORD compile_str_method(env_t *env, ast_t *ast)
{
auto def = Match(ast, EnumDef);
- CORD str_func = CORD_all("static CORD ", def->name, "__as_str(", def->name, "_t *obj, bool use_color) {\n"
+ CORD str_func = CORD_all("static CORD ", def->name, "__as_text(", def->name, "_t *obj, bool use_color) {\n"
"\tif (!obj) return \"", def->name, "\";\n"
"switch (obj->$tag) {\n");
for (tag_ast_t *tag = def->tags; tag; tag = tag->next) {
@@ -29,7 +29,7 @@ static CORD compile_str_method(env_t *env, ast_t *ast)
for (arg_ast_t *field = tag->fields; field; field = field->next) {
type_t *field_t = parse_type_ast(env, field->type);
- CORD field_str = expr_as_string(env, CORD_all("obj->", tag->name, ".", field->name), field_t, "use_color");
+ CORD field_str = expr_as_texting(env, CORD_all("obj->", tag->name, ".", field->name), field_t, "use_color");
str_func = CORD_all(str_func, ", \"", field->name, "=\", ", field_str);
if (field->next) str_func = CORD_cat(str_func, ", \", \"");
}
@@ -143,7 +143,7 @@ void compile_enum_def(env_t *env, ast_t *ast)
compile_hash_method(env, ast));
typeinfo = CORD_all(
typeinfo,
- ".as_str=(void*)", def->name, "__as_str, "
+ ".as_text=(void*)", def->name, "__as_text, "
".equal=(void*)", def->name, "__equal, "
".hash=(void*)", def->name, "__hash, "
".compare=(void*)", def->name, "__compare");
diff --git a/structs.c b/structs.c
index cabd83d2..de2cf806 100644
--- a/structs.c
+++ b/structs.c
@@ -38,7 +38,7 @@ static bool is_plain_data(env_t *env, type_t *t)
static CORD compile_str_method(env_t *env, ast_t *ast)
{
auto def = Match(ast, StructDef);
- CORD str_func = CORD_asprintf("static CORD %s__as_str(%s_t *obj, bool use_color) {\n"
+ CORD str_func = CORD_asprintf("static CORD %s__as_text(%s_t *obj, bool use_color) {\n"
"\tif (!obj) return \"%s\";\n", def->name, def->name, def->name);
if (def->secret) {
CORD_appendf(&str_func, "\treturn use_color ? \"\\x1b[0;1m%s\\x1b[m(\\x1b[2m...\\x1b[m)\" : \"%s(...)\";\n}",
@@ -47,7 +47,7 @@ static CORD compile_str_method(env_t *env, ast_t *ast)
CORD_appendf(&str_func, "\treturn CORD_all(use_color ? \"\\x1b[0;1m%s\\x1b[m(\" : \"%s(\"", def->name, def->name);
for (arg_ast_t *field = def->fields; field; field = field->next) {
type_t *field_type = get_arg_ast_type(env, field);
- CORD field_str = expr_as_string(env, CORD_cat("obj->", field->name), field_type, "use_color");
+ CORD field_str = expr_as_texting(env, CORD_cat("obj->", field->name), field_type, "use_color");
CORD_appendf(&str_func, ", \"%s=\", %r", field->name, field_str);
if (field->next) CORD_appendf(&str_func, ", \", \"");
}
@@ -146,7 +146,7 @@ void compile_struct_def(env_t *env, ast_t *ast)
CORD typeinfo = CORD_asprintf("public const TypeInfo %s = {%zu, %zu, {.tag=CustomInfo, .CustomInfo={",
def->name, type_size(t), type_align(t));
- typeinfo = CORD_all(typeinfo, ".as_str=(void*)", def->name, "__as_str, ");
+ typeinfo = CORD_all(typeinfo, ".as_text=(void*)", def->name, "__as_text, ");
env->code->funcs = CORD_all(env->code->funcs, compile_str_method(env, ast));
if (!t || !is_plain_data(env, t)) {
env->code->funcs = CORD_all(