aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-12 02:18:05 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-12 02:18:05 -0400
commit1d05704fdd6d3a3a9741bdef03975d4de05a37cf (patch)
treed6b20dad086994276124230a47d003d3ebb17f7f /compile.c
parent05724a659f914cee31dc8bc7c96a98115fd6325e (diff)
Use CString literals as constant values
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 9e5b8339..277c0a92 100644
--- a/compile.c
+++ b/compile.c
@@ -2826,6 +2826,12 @@ CORD compile(env_t *env, ast_t *ast)
// C String constructor:
if (!call->args || call->args->next)
code_err(call->fn, "This constructor takes exactly 1 argument");
+ if (call->args->value->tag == TextLiteral)
+ return compile_string_literal(Match(call->args->value, TextLiteral)->cord);
+ else if (call->args->value->tag == TextJoin && Match(call->args->value, TextJoin)->children == NULL)
+ return "\"\"";
+ else if (call->args->value->tag == TextJoin && Match(call->args->value, TextJoin)->children->next == NULL)
+ return compile_string_literal(Match(Match(call->args->value, TextJoin)->children->ast, TextLiteral)->cord);
type_t *actual = get_type(env, call->args->value);
return CORD_all("Text$as_c_string(", expr_as_text(env, compile(env, call->args->value), actual, "no"), ")");
} else {