aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-09 18:32:36 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-09 18:32:36 -0500
commit77c9669d41d24a89e9364e1a91d9a1343c75537f (patch)
tree2be81490146052edd3e87caa5e76557e74d1e38b
parent2b83ab279dbfb77cfd699d6da944c51c2353e64a (diff)
Change lang stringification to include type name
-rw-r--r--builtins/functions.c2
-rw-r--r--builtins/text.c10
-rw-r--r--compile.c13
-rw-r--r--compile.h2
-rw-r--r--enums.c2
-rw-r--r--structs.c2
6 files changed, 18 insertions, 13 deletions
diff --git a/builtins/functions.c b/builtins/functions.c
index 815e8ff2..bcaf5d11 100644
--- a/builtins/functions.c
+++ b/builtins/functions.c
@@ -112,7 +112,7 @@ public CORD generic_as_text(const void *obj, bool colorize, const TypeInfo *type
switch (type->tag) {
case PointerInfo: return Pointer__as_text(obj, colorize, type);
case FunctionInfo: return Func__as_text(obj, colorize, type);
- case TextInfo: return obj ? Text__quoted(*(CORD*)obj, colorize) :type->TextInfo.lang;
+ case TextInfo: return Text__as_text(obj, colorize, type);
case ArrayInfo: return Array__as_text(obj, colorize, type);
case TableInfo: return Table_as_text(obj, colorize, type);
case TypeInfoInfo: return Type__as_text(obj, colorize, type);
diff --git a/builtins/text.c b/builtins/text.c
index f9eb6a27..4641bc1d 100644
--- a/builtins/text.c
+++ b/builtins/text.c
@@ -22,11 +22,13 @@
#define CLAMP(x, lo, hi) MIN(hi, MAX(x,lo))
-public CORD Text__as_text(const void *str, bool colorize, const TypeInfo *info)
+public CORD Text__as_text(const void *text, bool colorize, const TypeInfo *info)
{
- (void)info;
- if (!str) return "Text";
- return Text__quoted(*(CORD*)str, colorize);
+ if (!text) return info->TextInfo.lang;
+ CORD ret = Text__quoted(*(CORD*)text, colorize);
+ if (!streq(info->TextInfo.lang, "Text"))
+ ret = colorize ? CORD_all("\x1b[1m$", info->TextInfo.lang, "\x1b[m", ret) : CORD_all("$", info->TextInfo.lang, ret);
+ return ret;
}
public CORD Text__quoted(CORD str, bool colorize)
diff --git a/compile.c b/compile.c
index 83927cab..a35ce177 100644
--- a/compile.c
+++ b/compile.c
@@ -122,7 +122,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
return stmt;
}
-CORD expr_as_texting(env_t *env, CORD expr, type_t *t, CORD color)
+CORD expr_as_text(env_t *env, CORD expr, type_t *t, CORD color)
{
switch (t->tag) {
case MemoryType: return CORD_asprintf("Memory__as_text($stack(%r), %r, &Memory)", expr, color);
@@ -135,7 +135,10 @@ CORD expr_as_texting(env_t *env, CORD expr, type_t *t, CORD color)
CORD name = type_to_cord(t);
return CORD_asprintf("%r__as_text($stack(%r), %r, &Num%r)", name, expr, color, name);
}
- case TextType: return CORD_asprintf("Text__as_text($stack(%r), %r, &Text)", expr, color);
+ case TextType: {
+ const char *lang = Match(t, TextType)->lang;
+ return CORD_asprintf("Text__as_text($stack(%r), %r, &%s)", expr, color, lang ? lang : "Text");
+ }
case ArrayType: return CORD_asprintf("Array__as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
case TableType: return CORD_asprintf("Table_as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
case FunctionType: return CORD_asprintf("Func__as_text($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
@@ -150,7 +153,7 @@ CORD compile_string(env_t *env, ast_t *ast, CORD color)
{
type_t *t = get_type(env, ast);
CORD expr = compile(env, ast);
- return expr_as_texting(env, expr, t, color);
+ return expr_as_text(env, expr, t, color);
}
static CORD compile_to_pointer_depth(env_t *env, ast_t *ast, int64_t target_depth, bool allow_optional)
@@ -611,7 +614,7 @@ CORD compile(env_t *env, ast_t *ast)
chunk_code = CORD_all(entry->b->code, "(", chunk_code, ")");
goto found_conversion;
}
- code_err(chunk->ast, "I don't know how to convert a %T to a %T", chunk_t, text_t);
+ code_err(chunk->ast, "I don't know how to convert %T to %T", chunk_t, text_t);
found_conversion:;
} else {
chunk_code = compile_string(env, chunk->ast, "no");
@@ -1285,7 +1288,7 @@ CORD compile(env_t *env, ast_t *ast)
CORD expr_cord = "CORD_all(";
i = 1;
for (ast_list_t *target = assign->targets; target; target = target->next) {
- CORD item = expr_as_texting(env, CORD_asprintf("$%ld", i++), get_type(env, target->ast), "USE_COLOR");
+ CORD item = expr_as_text(env, CORD_asprintf("$%ld", i++), get_type(env, target->ast), "USE_COLOR");
expr_cord = CORD_all(expr_cord, item, target->next ? ", \", \", " : CORD_EMPTY);
}
expr_cord = CORD_cat(expr_cord, ")");
diff --git a/compile.h b/compile.h
index 1f385bb3..c50e22aa 100644
--- a/compile.h
+++ b/compile.h
@@ -12,7 +12,7 @@ typedef struct {
CORD header, c_file;
} module_code_t;
-CORD expr_as_texting(env_t *env, CORD expr, type_t *t, CORD color);
+CORD expr_as_text(env_t *env, CORD expr, type_t *t, CORD color);
module_code_t compile_file(ast_t *ast);
CORD compile_type_ast(type_ast_t *t);
CORD compile_declaration(type_t *t, const char *name);
diff --git a/enums.c b/enums.c
index cb55f549..6aaa9ced 100644
--- a/enums.c
+++ b/enums.c
@@ -29,7 +29,7 @@ static CORD compile_str_method(env_t *env, ast_t *ast)
for (arg_ast_t *field = tag->fields; field; field = field->next) {
type_t *field_t = get_arg_ast_type(env, field);
- CORD field_str = expr_as_texting(env, CORD_all("obj->", tag->name, ".", field->name), field_t, "use_color");
+ CORD field_str = expr_as_text(env, CORD_all("obj->", tag->name, ".", field->name), field_t, "use_color");
str_func = CORD_all(str_func, ", \"", field->name, "=\", ", field_str);
if (field->next) str_func = CORD_cat(str_func, ", \", \"");
}
diff --git a/structs.c b/structs.c
index fa672c49..a5f4b964 100644
--- a/structs.c
+++ b/structs.c
@@ -47,7 +47,7 @@ static CORD compile_str_method(env_t *env, ast_t *ast)
CORD_appendf(&str_func, "\treturn CORD_all(use_color ? \"\\x1b[0;1m%s\\x1b[m(\" : \"%s(\"", def->name, def->name);
for (arg_ast_t *field = def->fields; field; field = field->next) {
type_t *field_type = get_arg_ast_type(env, field);
- CORD field_str = expr_as_texting(env, CORD_cat("obj->", field->name), field_type, "use_color");
+ CORD field_str = expr_as_text(env, CORD_cat("obj->", field->name), field_type, "use_color");
CORD_appendf(&str_func, ", \"%s=\", %r", field->name, field_str);
if (field->next) CORD_appendf(&str_func, ", \", \"");
}