aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-23 13:58:33 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-23 14:00:42 -0500
commit4a6c0438f9a2c82e834116e3e1bc110b8cae8432 (patch)
tree3cae849d6f4688a68f7417f103a6a2feaf421b06
parenta89500afd9a34f2af94ab6fcd7a0469b0450732a (diff)
Big speedup my trimming down MAP_LIST macro and inlining some
applications of it.
-rw-r--r--CHANGES.md4
-rw-r--r--src/compile/assertions.c14
-rw-r--r--src/compile/indexing.c2
-rw-r--r--src/compile/optionals.c8
-rw-r--r--src/compile/promotions.c12
-rw-r--r--src/compile/text.c15
-rw-r--r--src/stdlib/bytes.c2
-rw-r--r--src/stdlib/c_strings.c4
-rw-r--r--src/stdlib/enums.c2
-rw-r--r--src/stdlib/intX.c.h2
-rw-r--r--src/stdlib/lists.h10
-rw-r--r--src/stdlib/mapmacro.h4
-rw-r--r--src/stdlib/memory.c2
-rw-r--r--src/stdlib/numX.c.h6
-rw-r--r--src/stdlib/paths.c4
-rw-r--r--src/stdlib/pointers.c8
-rw-r--r--src/stdlib/stdlib.h4
-rw-r--r--src/stdlib/structs.c4
-rw-r--r--src/stdlib/tables.c6
-rw-r--r--src/stdlib/tables.h4
-rw-r--r--src/stdlib/text.c16
-rw-r--r--src/stdlib/text.h5
22 files changed, 65 insertions, 73 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 9690a745..6f8f5e16 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v2025-12-23
+
+- Improved C preprocessing performance by eliminating expensive macro calls.
+
## v2025-12-22
- Use static linking instead of dynamic linking for the Tomo standard library
diff --git a/src/compile/assertions.c b/src/compile/assertions.c
index 34055998..18531fd9 100644
--- a/src/compile/assertions.c
+++ b/src/compile/assertions.c
@@ -60,13 +60,10 @@ Text_t compile_assertion(env_t *env, ast_t *ast) {
compile_declaration(operand_t, Text("_rhs")), " = ", compile_to_type(env, cmp.rhs, operand_t), ";\n",
"\n#line ", line, "\n", "if (!(", compile_condition(env, var_comparison), "))\n", "#line ", line, "\n",
Texts("fail_source(", quoted_str(ast->file->filename), ", ", (int64_t)(expr->start - expr->file->text),
- ", ", (int64_t)(expr->end - expr->file->text), ", ",
- message ? Texts("Text$as_c_string(", compile_to_type(env, message, Type(TextType)), ")")
- : Text("\"This assertion failed!\""),
- ", ", "\" (\", ", expr_as_text(Text("_lhs"), operand_t, Text("no")),
- ", "
- "\" ",
- failure, " \", ", expr_as_text(Text("_rhs"), operand_t, Text("no")), ", \")\");\n"),
+ ", ", (int64_t)(expr->end - expr->file->text), ", Text$concat(",
+ message ? compile_to_type(env, message, Type(TextType)) : Text("Text(\"This assertion failed!\")"),
+ ", Text(\" (\"), ", expr_as_text(Text("_lhs"), operand_t, Text("no")), ", Text(\" ", failure,
+ " \"), ", expr_as_text(Text("_rhs"), operand_t, Text("no")), ", Text(\")\")));\n"),
"}\n");
}
default: {
@@ -74,8 +71,7 @@ Text_t compile_assertion(env_t *env, ast_t *ast) {
return Texts("if (!(", compile_condition(env, expr), "))\n", "#line ", line, "\n", "fail_source(",
quoted_str(ast->file->filename), ", ", (int64_t)(expr->start - expr->file->text), ", ",
(int64_t)(expr->end - expr->file->text), ", ",
- message ? Texts("Text$as_c_string(", compile_to_type(env, message, Type(TextType)), ")")
- : Text("\"This assertion failed!\""),
+ message ? compile_to_type(env, message, Type(TextType)) : Text("Text(\"This assertion failed!\")"),
");\n");
}
}
diff --git a/src/compile/indexing.c b/src/compile/indexing.c
index 13062641..031ef9a0 100644
--- a/src/compile/indexing.c
+++ b/src/compile/indexing.c
@@ -50,7 +50,7 @@ Text_t compile_indexing(env_t *env, ast_t *ast, bool checked) {
return Texts("({ ", compile_declaration(item_type, Text("opt")), " = ", code, "; ", "if unlikely (",
check_none(item_type, Text("opt")), ")\n", "#line ", line, "\n", "fail_source(",
quoted_str(ast->file->filename), ", ", start, ", ", end, ", ",
- "\"This was expected to be a value, but it's `none`\\n\");\n",
+ "Text(\"This was expected to be a value, but it's `none`\\n\"));\n",
optional_into_nonnone(item_type, Text("opt")), "; })");
}
return code;
diff --git a/src/compile/optionals.c b/src/compile/optionals.c
index 83f387e2..75dff935 100644
--- a/src/compile/optionals.c
+++ b/src/compile/optionals.c
@@ -134,9 +134,9 @@ Text_t compile_non_optional(env_t *env, ast_t *ast) {
compile_to_pointer_depth(env, f->fielded, 0, true), ";",
"if unlikely (_test_enum.$tag != ", tag_name, ") {\n", "#line ", line, "\n", "fail_source(",
quoted_str(f->fielded->file->filename), ", ", (int64_t)(f->fielded->start - f->fielded->file->text),
- ", ", (int64_t)(f->fielded->end - f->fielded->file->text), ", ", "\"This was expected to be ",
- tag->name, ", but it was: \", ", expr_as_text(Text("_test_enum"), enum_t, Text("false")),
- ", \"\\n\");\n}\n",
+ ", ", (int64_t)(f->fielded->end - f->fielded->file->text), ", ",
+ "Text$concat(Text(\"This was expected to be ", tag->name, ", but it was: \"), ",
+ expr_as_text(Text("_test_enum"), enum_t, Text("false")), ", Text(\"\\n\")));\n}\n",
compile_maybe_incref(
env, WrapLiteralCode(value, Texts("_test_enum.", tag->name), .type = tag->type), tag->type),
"; })");
@@ -149,7 +149,7 @@ Text_t compile_non_optional(env_t *env, ast_t *ast) {
check_none(value_t, Text("opt")), ")\n", "#line ", line, "\n", "fail_source(",
quoted_str(value->file->filename), ", ", (int64_t)(value->start - value->file->text), ", ",
(int64_t)(value->end - value->file->text), ", ",
- "\"This was expected to be a value, but it's `none`\\n\");\n",
+ "Text(\"This was expected to be a value, but it's `none`\\n\"));\n",
optional_into_nonnone(value_t, Text("opt")), "; })");
}
}
diff --git a/src/compile/promotions.c b/src/compile/promotions.c
index 5b0ccb95..482e5ed0 100644
--- a/src/compile/promotions.c
+++ b/src/compile/promotions.c
@@ -61,12 +61,12 @@ bool promote(env_t *env, ast_t *ast, Text_t *code, type_t *actual, type_t *neede
// Automatic optional checking for nums:
if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType) {
int64_t line = get_line_number(ast->file, ast->start);
- *code =
- Texts("({ ", compile_declaration(actual, Text("opt")), " = ", *code, "; ", "if unlikely (",
- check_none(actual, Text("opt")), ")\n", "#line ", line, "\n", "fail_source(",
- quoted_str(ast->file->filename), ", ", (int64_t)(ast->start - ast->file->text), ", ",
- (int64_t)(ast->end - ast->file->text), ", ", "\"This was expected to be a value, but it's none\");\n",
- optional_into_nonnone(actual, Text("opt")), "; })");
+ *code = Texts("({ ", compile_declaration(actual, Text("opt")), " = ", *code, "; ", "if unlikely (",
+ check_none(actual, Text("opt")), ")\n", "#line ", line, "\n", "fail_source(",
+ quoted_str(ast->file->filename), ", ", (int64_t)(ast->start - ast->file->text), ", ",
+ (int64_t)(ast->end - ast->file->text), ", ",
+ "Text(\"This was expected to be a value, but it's none\"));\n",
+ optional_into_nonnone(actual, Text("opt")), "; })");
return true;
}
diff --git a/src/compile/text.c b/src/compile/text.c
index 3a8a227c..2a64ca45 100644
--- a/src/compile/text.c
+++ b/src/compile/text.c
@@ -4,7 +4,6 @@
#include "../ast.h"
#include "../environment.h"
-#include "../naming.h"
#include "../stdlib/datatypes.h"
#include "../stdlib/tables.h"
#include "../stdlib/text.h"
@@ -102,19 +101,12 @@ Text_t compile_text_ast(env_t *env, ast_t *ast) {
type_t *text_t = lang ? Table$str_get(*env->types, lang) : TEXT_TYPE;
if (!text_t || text_t->tag != TextType) code_err(ast, quoted(lang), " is not a valid text language name");
- Text_t lang_constructor;
- if (!lang || streq(lang, "Text")) lang_constructor = Text("Text");
- else
- lang_constructor = namespace_name(Match(text_t, TextType)->env, Match(text_t, TextType)->env->namespace->parent,
- Text$from_str(lang));
-
ast_list_t *chunks = Match(ast, TextJoin)->children;
if (!chunks) {
- return Texts(lang_constructor, "(\"\")");
+ return Text("EMPTY_TEXT");
} else if (!chunks->next && chunks->ast->tag == TextLiteral) {
Text_t literal = Match(chunks->ast, TextLiteral)->text;
- if (string_literal_is_all_ascii(literal))
- return Texts(lang_constructor, "(", compile_text_literal(literal), ")");
+ if (string_literal_is_all_ascii(literal)) return Texts("Text(", compile_text_literal(literal), ")");
return Texts("((", compile_type(text_t), ")", compile(env, chunks->ast), ")");
} else {
Text_t code = EMPTY_TEXT;
@@ -142,7 +134,6 @@ Text_t compile_text_ast(env_t *env, ast_t *ast) {
code = Texts(code, chunk_code);
if (chunk->next) code = Texts(code, ", ");
}
- if (chunks->next) return Texts(lang_constructor, "s(", code, ")");
- else return code;
+ return Texts("Text$concat(", code, ")");
}
}
diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c
index 4416d804..a1e953a0 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -25,7 +25,7 @@ PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo
'\0',
};
Text_t text = Text$from_str(digits);
- if (colorize) text = Texts(Text("\x1b[35m"), text, Text("\x1b[m"));
+ if (colorize) text = Text$concat(Text("\x1b[35m"), text, Text("\x1b[m"));
return text;
}
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index 57960577..cbe46b68 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -70,8 +70,8 @@ const char *CString$join(const char *glue, List_t strings) {
Text_t ret = EMPTY_TEXT;
Text_t glue_text = Text$from_str(glue);
for (int64_t i = 0; i < (int64_t)strings.length; i++) {
- if (i > 0) ret = Texts(ret, glue_text);
- ret = Texts(ret, Text$from_str(*(const char **)(strings.data + i * strings.stride)));
+ if (i > 0) ret = Text$concat(ret, glue_text);
+ ret = Text$concat(ret, Text$from_str(*(const char **)(strings.data + i * strings.stride)));
}
return Text$as_c_string(ret);
}
diff --git a/src/stdlib/enums.c b/src/stdlib/enums.c
index b9b970fa..9cc16c5d 100644
--- a/src/stdlib/enums.c
+++ b/src/stdlib/enums.c
@@ -65,7 +65,7 @@ Text_t Enum$as_text(const void *obj, bool colorize, const TypeInfo_t *type) {
NamedType_t value = type->EnumInfo.tags[tag - 1];
if (!value.type || value.type->size == 0) {
Text_t text = Text$from_str(value.name);
- return colorize ? Texts(Text("\x1b[1m"), text, Text("\x1b[m")) : text;
+ return colorize ? Text$concat(Text("\x1b[1m"), text, Text("\x1b[m")) : text;
}
return generic_as_text(obj + value_offset(type), colorize, value.type);
diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h
index 72dfe6ed..03322e5b 100644
--- a/src/stdlib/intX.c.h
+++ b/src/stdlib/intX.c.h
@@ -98,7 +98,7 @@ Text_t NAMESPACED(as_text)(const void *i, bool colorize, const TypeInfo_t *info)
(void)info;
if (!i) return Text(NAME_STR);
Text_t text = _int64_to_text((int64_t)(*(INT_T *)i));
- return colorize ? Texts(Text("\033[35m"), text, Text("\033[m")) : text;
+ return colorize ? Text$concat(Text("\033[35m"), text, Text("\033[m")) : text;
}
public
Text_t NAMESPACED(value_as_text)(INT_T i) { return _int64_to_text((int64_t)i); }
diff --git a/src/stdlib/lists.h b/src/stdlib/lists.h
index 6a0a1d43..9ac8bf1b 100644
--- a/src/stdlib/lists.h
+++ b/src/stdlib/lists.h
@@ -20,8 +20,9 @@ extern char _EMPTY_LIST_SENTINEL;
int64_t index = index_expr; \
int64_t off = index + (index < 0) * (list.length + 1) - 1; \
if (unlikely(off < 0 || off >= list.length)) \
- fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", \
- (int64_t)list.length, ")\n"); \
+ fail_source(__SOURCE_FILE__, start, end, \
+ Text$concat(Text("Invalid list index: "), convert_to_text(index), Text(" (list has length "), \
+ convert_to_text((int64_t)list.length), Text(")\n"))); \
*(item_type *)(list.data + list.stride * off); \
})
#define List_get(list_expr, index_expr, item_type, var, optional_expr, none_expr) \
@@ -40,8 +41,9 @@ extern char _EMPTY_LIST_SENTINEL;
int64_t index = index_expr; \
int64_t off = index + (index < 0) * (list->length + 1) - 1; \
if (unlikely(off < 0 || off >= list->length)) \
- fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", \
- (int64_t)list->length, ")\n"); \
+ fail_source(__SOURCE_FILE__, start, end, \
+ Text$concat(Text("Invalid list index: "), convert_to_text(index), Text(" (list has length "), \
+ convert_to_text((int64_t)list->length), Text(")\n"))); \
if (list->data_refcount > 0) List$compact(list, sizeof(item_type)); \
(item_type *)(list->data + list->stride * off); \
})
diff --git a/src/stdlib/mapmacro.h b/src/stdlib/mapmacro.h
index 7b0e3c4e..5e9eaa36 100644
--- a/src/stdlib/mapmacro.h
+++ b/src/stdlib/mapmacro.h
@@ -7,9 +7,7 @@
#define EVAL0(...) __VA_ARGS__
#define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__)))
#define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
-#define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
-#define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
-#define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
+#define EVAL(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
#define MAP_END(...)
#define MAP_OUT
diff --git a/src/stdlib/memory.c b/src/stdlib/memory.c
index fd396463..53a180fb 100644
--- a/src/stdlib/memory.c
+++ b/src/stdlib/memory.c
@@ -18,7 +18,7 @@ Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!p) return Text("Memory");
Text_t text = Text$from_str(String("Memory<", (void *)p, ">"));
- return colorize ? Texts(Text("\x1b[0;34;1m"), text, Text("\x1b[m")) : text;
+ return colorize ? Text$concat(Text("\x1b[0;34;1m"), text, Text("\x1b[m")) : text;
}
public
diff --git a/src/stdlib/numX.c.h b/src/stdlib/numX.c.h
index 0e84708f..2fde8c45 100644
--- a/src/stdlib/numX.c.h
+++ b/src/stdlib/numX.c.h
@@ -50,7 +50,7 @@ PUREFUNC Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo
if (!x) return Text(TYPE_STR);
static const Text_t color_prefix = Text("\x1b[35m"), color_suffix = Text("\x1b[m");
Text_t text = NAMESPACED(value_as_text)(*(NUM_T *)x);
- return colorize ? Texts(color_prefix, text, color_suffix) : text;
+ return colorize ? Text$concat(color_prefix, text, color_suffix) : text;
}
public
PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *info) {
@@ -73,7 +73,7 @@ PUREFUNC Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo
if (!x) return Text(TYPE_STR);
static const Text_t color_prefix = Text("\x1b[35m"), color_suffix = Text("\x1b[m");
Text_t text = Num$value_as_text((double)*(NUM_T *)x);
- return colorize ? Texts(color_prefix, text, color_suffix) : text;
+ return colorize ? Text$concat(color_prefix, text, color_suffix) : text;
}
public
PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *info) {
@@ -115,7 +115,7 @@ public
Text_t NAMESPACED(percent)(NUM_T x, NUM_T precision) {
NUM_T d = SUFFIXED(100.) * x;
d = NAMESPACED(with_precision)(d, precision);
- return Texts(NAMESPACED(value_as_text)(d), Text("%"));
+ return Text$concat(NAMESPACED(value_as_text)(d), Text("%"));
}
public
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index 9c74f4c1..e3028cce 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -690,7 +690,7 @@ bool Path$has_extension(Path_t path, Text_t extension) {
if (extension.length == 0)
return !Text$has(Text$from(last, I(2)), Text(".")) || Text$equal_values(last, Text(".."));
- if (!Text$starts_with(extension, Text("."), NULL)) extension = Texts(Text("."), extension);
+ if (!Text$starts_with(extension, Text("."), NULL)) extension = Text$concat(Text("."), extension);
return Text$ends_with(Text$from(last, I(2)), extension, NULL);
}
@@ -879,7 +879,7 @@ Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) {
&& (path->components.length == 0 || !Text$equal_values(*(Text_t *)(path->components.data), Text(".."))))
text = Text$concat(path->components.length > 0 ? Text("./") : Text("."), text);
- if (color) text = Texts(Text("\033[32;1m"), text, Text("\033[m"));
+ if (color) text = Text$concat(Text("\033[32;1m"), text, Text("\033[m"));
return text;
}
diff --git a/src/stdlib/pointers.c b/src/stdlib/pointers.c
index 74037613..0bf9a274 100644
--- a/src/stdlib/pointers.c
+++ b/src/stdlib/pointers.c
@@ -38,14 +38,14 @@ Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *type) {
if (top_level) {
root = ptr;
} else if (ptr == root) {
- Text_t text = Texts(Text$from_str(ptr_info.sigil), Text("~1"));
- return colorize ? Texts(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
+ Text_t text = Text$concat(Text$from_str(ptr_info.sigil), Text("~1"));
+ return colorize ? Text$concat(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
} else {
TypeInfo_t rec_table = *Table$info(type, &Int64$info);
int64_t *id = Table$get(pending, x, &rec_table);
if (id) {
- Text_t text = Texts(Text$from_str(ptr_info.sigil), Int64$value_as_text(*id));
- return colorize ? Texts(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
+ Text_t text = Text$concat(Text$from_str(ptr_info.sigil), Int64$value_as_text(*id));
+ return colorize ? Text$concat(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
}
int64_t next_id = (int64_t)pending.entries.length + 2;
Table$set(&pending, x, &next_id, &rec_table);
diff --git a/src/stdlib/stdlib.h b/src/stdlib/stdlib.h
index 234048e9..087ed4bf 100644
--- a/src/stdlib/stdlib.h
+++ b/src/stdlib/stdlib.h
@@ -37,7 +37,7 @@ void tomo_cleanup(void);
exit(1); \
})
-#define fail_source(filename, start, end, ...) \
+#define fail_source(filename, start, end, message) \
({ \
tomo_cleanup(); \
fflush(stdout); \
@@ -46,7 +46,7 @@ void tomo_cleanup(void);
print_stacktrace(stderr, 0); \
fputs("\n", stderr); \
if (USE_COLOR) fputs("\x1b[31;1m", stderr); \
- fprint_inline(stderr, __VA_ARGS__); \
+ Text$print(stderr, message); \
file_t *_file = (filename) ? load_file(filename) : NULL; \
if ((filename) && _file) { \
fputs("\n", stderr); \
diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c
index da8f1461..d1b9f824 100644
--- a/src/stdlib/structs.c
+++ b/src/stdlib/structs.c
@@ -126,10 +126,10 @@ PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const Type
Text_t name = Text$from_str(type->StructInfo.name);
if (type->StructInfo.is_secret || type->StructInfo.is_opaque) {
- return colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(...)")) : Texts(name, Text("(...)"));
+ return colorize ? Text$concat(Text("\x1b[0;1m"), name, Text("\x1b[m(...)")) : Text$concat(name, Text("(...)"));
}
- Text_t text = colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(")) : Texts(name, Text("("));
+ Text_t text = colorize ? Text$concat(Text("\x1b[0;1m"), name, Text("\x1b[m(")) : Text$concat(name, Text("("));
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c
index a801957f..400cc1b8 100644
--- a/src/stdlib/tables.c
+++ b/src/stdlib/tables.c
@@ -537,9 +537,9 @@ Text_t Table$as_text(const void *obj, bool colorize, const TypeInfo_t *type) {
__typeof(type->TableInfo) table = type->TableInfo;
if (!t) {
- return table.value->size > 0 ? Texts("{", generic_as_text(NULL, false, table.key), ":",
- generic_as_text(NULL, false, table.value), "}")
- : Texts("{", generic_as_text(NULL, false, table.key), "}");
+ return table.value->size > 0 ? Text$concat(Text("{"), generic_as_text(NULL, false, table.key), Text(":"),
+ generic_as_text(NULL, false, table.value), Text("}"))
+ : Text$concat(Text("{"), generic_as_text(NULL, false, table.key), Text("}"));
}
int64_t val_off = (int64_t)value_offset(type);
diff --git a/src/stdlib/tables.h b/src/stdlib/tables.h
index cf1c3625..93da465e 100644
--- a/src/stdlib/tables.h
+++ b/src/stdlib/tables.h
@@ -47,8 +47,8 @@ void *Table$get(Table_t t, const void *key, const TypeInfo_t *type);
val_t *value = Table$get(t, &key, info); \
if (unlikely(value == NULL)) \
fail_source(__SOURCE_FILE__, start, end, \
- "This key was not found in the table: ", generic_as_text(&key, false, info->TableInfo.key), \
- "\n"); \
+ Text$concat(Text("This key was not found in the table: "), \
+ generic_as_text(&key, false, info->TableInfo.key), Text("\n"))); \
*value; \
})
#define Table$get_or_setdefault(table_expr, key_t, val_t, key_expr, default_expr, info_expr) \
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index b4b27fed..411f3546 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -606,8 +606,8 @@ Text_t Text$middle_pad(Text_t text, Int_t width, Text_t padding, Text_t language
if (padding.length == 0) fail("Cannot pad with an empty text!");
int64_t needed = Int64$from_int(width, false) - Int64$from_int(Text$width(text, language), false);
- return Texts(Text$repeat_to_width(padding, needed / 2, language), text,
- Text$repeat_to_width(padding, (needed + 1) / 2, language));
+ return Text$concat(Text$repeat_to_width(padding, needed / 2, language), text,
+ Text$repeat_to_width(padding, (needed + 1) / 2, language));
}
public
@@ -1506,8 +1506,8 @@ Text_t Text$quoted(Text_t text, bool colorize, Text_t quotation_mark) {
Text_t ret = Text$escaped(text, colorize, quotation_mark);
if (!(Text$equal_values(quotation_mark, Text("\"")) || Text$equal_values(quotation_mark, Text("'"))
|| Text$equal_values(quotation_mark, Text("`"))))
- ret = Texts("$", quotation_mark, ret, quotation_mark);
- else ret = Texts(quotation_mark, ret, quotation_mark);
+ ret = Text$concat(Text("$"), quotation_mark, ret, quotation_mark);
+ else ret = Text$concat(quotation_mark, ret, quotation_mark);
return ret;
}
@@ -1803,11 +1803,11 @@ Int_t Text$memory_size(Text_t text) {
public
Text_t Text$layout(Text_t text) {
switch (text.tag) {
- case TEXT_ASCII: return Texts(Text("ASCII("), Int64$value_as_text(text.length), Text(")"));
- case TEXT_GRAPHEMES: return Texts(Text("Graphemes("), Int64$value_as_text(text.length), Text(")"));
- case TEXT_BLOB: return Texts(Text("Blob("), Int64$value_as_text(text.length), Text(")"));
+ case TEXT_ASCII: return Text$concat(Text("ASCII("), Int64$value_as_text(text.length), Text(")"));
+ case TEXT_GRAPHEMES: return Text$concat(Text("Graphemes("), Int64$value_as_text(text.length), Text(")"));
+ case TEXT_BLOB: return Text$concat(Text("Blob("), Int64$value_as_text(text.length), Text(")"));
case TEXT_CONCAT:
- return Texts(Text("Concat("), Text$layout(*text.left), Text(", "), Text$layout(*text.right), Text(")"));
+ return Text$concat(Text("Concat("), Text$layout(*text.left), Text(", "), Text$layout(*text.right), Text(")"));
default: errx(1, "Invalid text tag: %d", text.tag);
}
}
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 9ad7441c..776ea8ec 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -63,8 +63,9 @@ OptionalText_t Text$cluster(Text_t text, Int_t index_int);
Int_t index = index_expr; \
OptionalText_t cluster = Text$cluster(text, index); \
if (unlikely(cluster.tag == TEXT_NONE)) \
- fail_source(__SOURCE_FILE__, start, end, "Invalid text index: ", index, " (text has length ", \
- (int64_t)text.length, ")\n"); \
+ fail_source(__SOURCE_FILE__, start, end, \
+ Text$concat(Text("Invalid text index: "), convert_to_text(index), Text(" (text has length "), \
+ convert_to_text((int64_t)text.length), Text(")\n"))); \
cluster; \
})
OptionalText_t Text$from_str(const char *str);