Refactor errors and update post draft.

This commit is contained in:
2020-09-11 21:29:49 -07:00
parent 725958137a
commit 6b8d3b0f8a
8 changed files with 431 additions and 42 deletions

View File

@@ -235,13 +235,13 @@ struct case_mappings {
std::vector<instruction_ptr>& make_case_for(tag_type tag) {
if(default_case)
throw type_error("attempted pattern match after catch-all");
throw compiler_error("attempted pattern match after catch-all");
return defined_cases[tag];
}
std::vector<instruction_ptr>& make_default_case() {
if(default_case)
throw type_error("attempted repeated use of catch-all");
throw compiler_error("attempted repeated use of catch-all");
default_case.emplace(std::vector<instruction_ptr>());
return *default_case;
}
@@ -285,7 +285,7 @@ struct case_strategy_bool {
if(!(cpat = dynamic_cast<pattern_constr*>(pt.get())) ||
(cpat->constr != "True" && cpat->constr != "False") ||
cpat->params.size() != 0)
throw type_error(
throw compiler_error(
"pattern cannot be converted to a boolean",
pt->loc);
return cpat->constr == "True";
@@ -335,7 +335,7 @@ struct case_strategy_data {
repr_type repr_from_pattern(const pattern_ptr& pt) {
pattern_constr* cpat;
if(!(cpat = dynamic_cast<pattern_constr*>(pt.get())))
throw type_error(
throw compiler_error(
"pattern cannot be interpreted as constructor.",
pt->loc);
return std::make_pair(
@@ -398,7 +398,7 @@ void compile_case(const ast_case& node, const env_ptr& env, const type* type, st
pattern_var* vpat;
if((vpat = dynamic_cast<pattern_var*>(branch->pat.get()))) {
if(cases.defined_cases_count() == strategy.case_count())
throw type_error("redundant catch-all pattern", branch->pat->loc);
throw compiler_error("redundant catch-all pattern", branch->pat->loc);
auto& branch_into = cases.make_default_case();
env_ptr new_env(new env_var(vpat->var, env));
branch->expr->compile(new_env, branch_into);
@@ -412,7 +412,7 @@ void compile_case(const ast_case& node, const env_ptr& env, const type* type, st
if(!(cases.defined_cases_count() == strategy.case_count() ||
cases.default_case_defined()))
throw type_error("incomplete patterns", node.loc);
throw compiler_error("incomplete patterns", node.loc);
strategy.into_instructions(cases, into);
}