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