aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast.c12
-rw-r--r--src/ast.h3
-rw-r--r--src/repl.c8
-rw-r--r--src/typecheck.c4
-rw-r--r--src/types.c6
5 files changed, 20 insertions, 13 deletions
diff --git a/src/ast.c b/src/ast.c
index 75795d61..84d25db0 100644
--- a/src/ast.c
+++ b/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";
diff --git a/src/ast.h b/src/ast.h
index cad7bb64..766b484b 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -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);
diff --git a/src/repl.c b/src/repl.c
index e4a7b7a4..ae12427a 100644
--- a/src/repl.c
+++ b/src/repl.c
@@ -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__
diff --git a/src/typecheck.c b/src/typecheck.c
index 648ffbc8..d2a976b8 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -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)
diff --git a/src/types.c b/src/types.c
index c4155c8d..d8ff377b 100644
--- a/src/types.c
+++ b/src/types.c
@@ -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);