Fix textual representation of table types
This commit is contained in:
parent
59993b8530
commit
cedae3039c
12
src/ast.c
12
src/ast.c
@ -171,11 +171,21 @@ CORD ast_to_xml(ast_t *ast)
|
||||
}
|
||||
}
|
||||
|
||||
const char *ast_to_str(ast_t *ast)
|
||||
const char *ast_to_xml_str(ast_t *ast)
|
||||
{
|
||||
return CORD_to_const_char_star(ast_to_xml(ast));
|
||||
}
|
||||
|
||||
const char *ast_source(ast_t *ast)
|
||||
{
|
||||
if (!ast) return NULL;
|
||||
size_t len = (size_t)(ast->end - ast->start);
|
||||
char *source = GC_MALLOC_ATOMIC(len + 1);
|
||||
memcpy(source, ast->start, len);
|
||||
source[len] = '\0';
|
||||
return source;
|
||||
}
|
||||
|
||||
CORD type_ast_to_xml(type_ast_t *t)
|
||||
{
|
||||
if (!t) return "NULL";
|
||||
|
@ -340,7 +340,8 @@ struct ast_s {
|
||||
};
|
||||
|
||||
CORD ast_to_xml(ast_t *ast);
|
||||
const char *ast_to_str(ast_t *ast);
|
||||
const char *ast_to_xml_str(ast_t *ast);
|
||||
const char *ast_source(ast_t *ast);
|
||||
CORD type_ast_to_xml(type_ast_t *ast);
|
||||
PUREFUNC bool is_idempotent(ast_t *ast);
|
||||
void visit_topologically(ast_list_t *ast, Closure_t fn);
|
||||
|
@ -158,7 +158,7 @@ static PUREFUNC void *get_address(env_t *env, ast_t *ast)
|
||||
if (!b) print_err("No such variable");
|
||||
return b->value;
|
||||
}
|
||||
default: print_err("Address not implemented for ", ast_to_str(ast));
|
||||
default: print_err("Address not implemented for ", ast_to_xml_str(ast));
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ void run(env_t *env, ast_t *ast)
|
||||
// type_t *obj_t = get_type(env, index->indexed);
|
||||
// TypeInfo_t *table_info = type_to_type_info(t);
|
||||
// }
|
||||
default: print_err("Assignment not implemented: ", ast_to_str(target->ast));
|
||||
default: print_err("Assignment not implemented: ", ast_to_xml_str(target->ast));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -452,7 +452,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: print_err(1, "Binary op not implemented for ", type_to_str(t), ": ", ast_to_str(ast));
|
||||
default: print_err(1, "Binary op not implemented for ", type_to_str(t), ": ", ast_to_xml_str(ast));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -541,7 +541,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
print_err("Eval not implemented for ", ast_to_str(ast));
|
||||
print_err("Eval not implemented for ", ast_to_xml_str(ast));
|
||||
}
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
|
@ -1432,13 +1432,13 @@ type_t *get_type(env_t *env, ast_t *ast)
|
||||
type_ast_t *type_ast = inline_code->type_ast;
|
||||
return type_ast ? parse_type_ast(env, type_ast) : Type(VoidType);
|
||||
}
|
||||
case Unknown: code_err(ast, "I can't figure out the type of: ", ast_to_str(ast));
|
||||
case Unknown: code_err(ast, "I can't figure out the type of: ", ast_to_xml_str(ast));
|
||||
case Deserialize: return parse_type_ast(env, Match(ast, Deserialize)->type);
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
code_err(ast, "I can't figure out the type of: ", ast_to_str(ast));
|
||||
code_err(ast, "I can't figure out the type of: ", ast_to_xml_str(ast));
|
||||
}
|
||||
|
||||
PUREFUNC bool is_discardable(env_t *env, ast_t *ast)
|
||||
|
@ -39,11 +39,7 @@ CORD type_to_cord(type_t *t) {
|
||||
}
|
||||
case TableType: {
|
||||
auto table = Match(t, TableType);
|
||||
if (table->default_value)
|
||||
return CORD_asprintf("{%r=%.*s}", type_to_cord(table->key_type),
|
||||
table->default_value->end - table->default_value->start, table->default_value->start);
|
||||
else
|
||||
return CORD_asprintf("{%r:%r}", type_to_cord(table->key_type), type_to_cord(table->value_type));
|
||||
return CORD_all("{", type_to_cord(table->key_type), "=", type_to_cord(table->value_type), "}");
|
||||
}
|
||||
case SetType: {
|
||||
auto set = Match(t, SetType);
|
||||
|
Loading…
Reference in New Issue
Block a user