aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
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 /src/stdlib
parenta89500afd9a34f2af94ab6fcd7a0469b0450732a (diff)
Big speedup my trimming down MAP_LIST macro and inlining some
applications of it.
Diffstat (limited to 'src/stdlib')
-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
16 files changed, 42 insertions, 41 deletions
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);