Change lang stringification to include type name
This commit is contained in:
parent
2b83ab279d
commit
77c9669d41
@ -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);
|
||||
|
@ -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)
|
||||
|
13
compile.c
13
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, ")");
|
||||
|
@ -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);
|
||||
|
2
enums.c
2
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, ", \", \"");
|
||||
}
|
||||
|
@ -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, ", \", \"");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user