Switch Clause to Ptr (#800)

This is consistent with other lists, doesn't seem to benefit from being a Ptr.
This commit is contained in:
Jon Meow
2021-09-01 15:19:58 -07:00
committed by GitHub
parent 9f67c4b9a8
commit 5f8b231322
5 changed files with 24 additions and 33 deletions
@@ -765,12 +765,12 @@ auto Interpreter::StepStmt() -> Transition {
// * 2: the pattern for clause 1
// * ...
auto clause_num = (act->Pos() - 1) / 2;
if (clause_num >= static_cast<int>(match_stmt.Clauses()->size())) {
if (clause_num >= static_cast<int>(match_stmt.Clauses().size())) {
DeallocateScope(frame->scopes.Top());
frame->scopes.Pop();
return Done{};
}
auto c = match_stmt.Clauses()->begin();
auto c = match_stmt.Clauses().begin();
std::advance(c, clause_num);
if (act->Pos() % 2 == 1) {
@@ -784,7 +784,7 @@ auto Interpreter::StepStmt() -> Transition {
std::optional<Env> matches = PatternMatch(pat, v, stmt->SourceLoc());
if (matches) { // we have a match, start the body
// Ensure we don't process any more clauses.
act->SetPos(2 * match_stmt.Clauses()->size() + 1);
act->SetPos(2 * match_stmt.Clauses().size() + 1);
for (const auto& [name, value] : *matches) {
frame->scopes.Top()->values.Set(name, value);
@@ -667,12 +667,12 @@ auto TypeChecker::TypeCheckStmt(Ptr<const Statement> s, TypeEnv types,
const auto& match = cast<Match>(*s);
auto res = TypeCheckExp(match.Exp(), types, values);
auto res_type = res.type;
auto new_clauses = global_arena->RawNew<
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>>();
for (auto& clause : *match.Clauses()) {
new_clauses->push_back(TypeCheckCase(res_type, clause.first,
clause.second, types, values,
ret_type, is_omitted_ret_type));
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
new_clauses;
for (auto& clause : match.Clauses()) {
new_clauses.push_back(TypeCheckCase(res_type, clause.first,
clause.second, types, values,
ret_type, is_omitted_ret_type));
}
auto new_s =
global_arena->New<Match>(s->SourceLoc(), res.exp, new_clauses);
@@ -826,12 +826,12 @@ static auto CheckOrEnsureReturn(std::optional<Ptr<const Statement>> opt_stmt,
switch (stmt->Tag()) {
case Statement::Kind::Match: {
const auto& match = cast<Match>(*stmt);
auto new_clauses = global_arena->RawNew<
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>>();
for (const auto& clause : *match.Clauses()) {
std::list<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>
new_clauses;
for (const auto& clause : match.Clauses()) {
auto s = CheckOrEnsureReturn(clause.second, omitted_ret_type,
stmt->SourceLoc());
new_clauses->push_back(std::make_pair(clause.first, s));
new_clauses.push_back(std::make_pair(clause.first, s));
}
return global_arena->New<Match>(stmt->SourceLoc(), match.Exp(),
new_clauses);