From 805082d2990c780328bef7d0d8ebc5601ef02eb1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 3 Sep 2024 23:35:42 -0400 Subject: Minor codegen cleanup Texts(...) --- builtins/text.h | 1 + compile.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/builtins/text.h b/builtins/text.h index b343798d..3aa51872 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -20,6 +20,7 @@ int Text$print(FILE *stream, Text_t t); void Text$visualize(Text_t t); Text_t Text$_concat(int n, Text_t items[n]); #define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__}) +#define Texts(...) Text$concat(__VA_ARGS__) Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int); Text_t Text$from_str(const char *str); uint64_t Text$hash(Text_t *text); diff --git a/compile.c b/compile.c index 6c1bee4c..edad2f12 100644 --- a/compile.c +++ b/compile.c @@ -593,7 +593,7 @@ CORD compile_statement(env_t *env, ast_t *ast) return CORD_all(lhs, " ^= ", rhs, ";"); case BINOP_CONCAT: { if (lhs_t->tag == TextType) { - return CORD_all(lhs, " = Text$concat(", lhs, ", ", rhs, ");"); + return CORD_all(lhs, " = Texts(", lhs, ", ", rhs, ");"); } else if (lhs_t->tag == ArrayType) { CORD padded_item_size = CORD_asprintf("%ld", padded_type_size(Match(lhs_t, ArrayType)->item_type)); if (promote(env, &rhs, rhs_t, Match(lhs_t, ArrayType)->item_type)) { @@ -822,7 +822,7 @@ CORD compile_statement(env_t *env, ast_t *ast) if (!to_print) return CORD_EMPTY; - CORD code = "say(Text$concat("; + CORD code = "say(Texts("; for (ast_list_t *chunk = to_print; chunk; chunk = chunk->next) { if (chunk->ast->tag == TextLiteral) { code = CORD_cat(code, compile(env, chunk->ast)); @@ -1845,7 +1845,7 @@ CORD compile(env_t *env, ast_t *ast) if (chunk->next) code = CORD_cat(code, ", "); } if (chunks->next) - return CORD_all("Text$concat(", code, ")"); + return CORD_all("Texts(", code, ")"); else return code; } -- cgit v1.2.3