diff --git a/executable_semantics/interpreter/action.cpp b/executable_semantics/interpreter/action.cpp index bcde260be6fe..5b1522d69026 100644 --- a/executable_semantics/interpreter/action.cpp +++ b/executable_semantics/interpreter/action.cpp @@ -24,16 +24,16 @@ using llvm::cast; void Action::Print(llvm::raw_ostream& out) const { switch (kind()) { case Action::Kind::LValAction: - out << *cast(*this).Exp(); + out << cast(*this).expression(); break; case Action::Kind::ExpressionAction: - out << *cast(*this).Exp(); + out << cast(*this).expression(); break; case Action::Kind::PatternAction: - out << *cast(*this).Pat(); + out << cast(*this).pattern(); break; case Action::Kind::StatementAction: - cast(*this).Stmt()->PrintDepth(1, out); + cast(*this).statement().PrintDepth(1, out); break; } out << "<" << pos_ << ">"; diff --git a/executable_semantics/interpreter/action.h b/executable_semantics/interpreter/action.h index dda6f60ae689..e7a5d197a600 100644 --- a/executable_semantics/interpreter/action.h +++ b/executable_semantics/interpreter/action.h @@ -75,62 +75,62 @@ class Action { class LValAction : public Action { public: - explicit LValAction(Nonnull exp) - : Action(Kind::LValAction), exp(exp) {} + explicit LValAction(Nonnull expression) + : Action(Kind::LValAction), expression_(expression) {} static auto classof(const Action* action) -> bool { return action->kind() == Kind::LValAction; } - auto Exp() const -> Nonnull { return exp; } + auto expression() const -> const Expression& { return *expression_; } private: - Nonnull exp; + Nonnull expression_; }; class ExpressionAction : public Action { public: - explicit ExpressionAction(Nonnull exp) - : Action(Kind::ExpressionAction), exp(exp) {} + explicit ExpressionAction(Nonnull expression) + : Action(Kind::ExpressionAction), expression_(expression) {} static auto classof(const Action* action) -> bool { return action->kind() == Kind::ExpressionAction; } - auto Exp() const -> Nonnull { return exp; } + auto expression() const -> const Expression& { return *expression_; } private: - Nonnull exp; + Nonnull expression_; }; class PatternAction : public Action { public: - explicit PatternAction(Nonnull pat) - : Action(Kind::PatternAction), pat(pat) {} + explicit PatternAction(Nonnull pattern) + : Action(Kind::PatternAction), pattern_(pattern) {} static auto classof(const Action* action) -> bool { return action->kind() == Kind::PatternAction; } - auto Pat() const -> Nonnull { return pat; } + auto pattern() const -> const Pattern& { return *pattern_; } private: - Nonnull pat; + Nonnull pattern_; }; class StatementAction : public Action { public: - explicit StatementAction(Nonnull stmt) - : Action(Kind::StatementAction), stmt(stmt) {} + explicit StatementAction(Nonnull statement) + : Action(Kind::StatementAction), statement_(statement) {} static auto classof(const Action* action) -> bool { return action->kind() == Kind::StatementAction; } - auto Stmt() const -> Nonnull { return stmt; } + auto statement() const -> const Statement& { return *statement_; } private: - Nonnull stmt; + Nonnull statement_; }; } // namespace Carbon diff --git a/executable_semantics/interpreter/interpreter.cpp b/executable_semantics/interpreter/interpreter.cpp index 42ecfac9a06a..01b034dbae93 100644 --- a/executable_semantics/interpreter/interpreter.cpp +++ b/executable_semantics/interpreter/interpreter.cpp @@ -378,17 +378,17 @@ void Interpreter::PatternAssignment(Nonnull pat, auto Interpreter::StepLvalue() -> Transition { Nonnull act = stack.Top()->todo.Top(); - Nonnull exp = cast(*act).Exp(); + const Expression& exp = cast(*act).expression(); if (tracing_output) { - llvm::outs() << "--- step lvalue " << *exp << " (" << exp->source_loc() + llvm::outs() << "--- step lvalue " << exp << " (" << exp.source_loc() << ") --->\n"; } - switch (exp->kind()) { + switch (exp.kind()) { case Expression::Kind::IdentifierExpression: { // { {x :: C, E, F} :: S, H} // -> { {E(x) :: C, E, F} :: S, H} - Address pointer = GetFromEnv(exp->source_loc(), - cast(*exp).name()); + Address pointer = + GetFromEnv(exp.source_loc(), cast(exp).name()); Nonnull v = arena->New(pointer); return Done{v}; } @@ -397,13 +397,13 @@ auto Interpreter::StepLvalue() -> Transition { // { {e.f :: C, E, F} :: S, H} // -> { e :: [].f :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*exp).aggregate())}; + &cast(exp).aggregate())}; } else { // { v :: [].f :: C, E, F} :: S, H} // -> { { &v.f :: C, E, F} :: S, H } Address aggregate = cast(*act->results()[0]).value(); Address field = aggregate.SubobjectAddress( - cast(*exp).field()); + cast(exp).field()); return Done{arena->New(field)}; } } @@ -412,11 +412,11 @@ auto Interpreter::StepLvalue() -> Transition { // { {e[i] :: C, E, F} :: S, H} // -> { e :: [][i] :: C, E, F} :: S, H} return Spawn{ - arena->New(&cast(*exp).aggregate())}; + arena->New(&cast(exp).aggregate())}; } else if (act->pos() == 1) { - return Spawn{arena->New( - &cast(*exp).offset())}; + return Spawn{ + arena->New(&cast(exp).offset())}; } else { // { v :: [][i] :: C, E, F} :: S, H} // -> { { &v[i] :: C, E, F} :: S, H } @@ -429,15 +429,15 @@ auto Interpreter::StepLvalue() -> Transition { } case Expression::Kind::TupleLiteral: { if (act->pos() < - static_cast(cast(*exp).fields().size())) { + static_cast(cast(exp).fields().size())) { // { { vk :: (f1=v1,..., fk=[],fk+1=ek+1,...) :: C, E, F} :: S, // H} // -> { { ek+1 :: (f1=v1,..., fk=vk, fk+1=[],...) :: C, E, F} :: S, // H} return Spawn{arena->New( - cast(*exp).fields()[act->pos()])}; + cast(exp).fields()[act->pos()])}; } else { - return Done{CreateTuple(act, exp)}; + return Done{CreateTuple(act, &exp)}; } } case Expression::Kind::StructLiteral: @@ -455,27 +455,27 @@ auto Interpreter::StepLvalue() -> Transition { case Expression::Kind::StringTypeLiteral: case Expression::Kind::IntrinsicExpression: FATAL_RUNTIME_ERROR_NO_LINE() - << "Can't treat expression as lvalue: " << *exp; + << "Can't treat expression as lvalue: " << exp; } } auto Interpreter::StepExp() -> Transition { Nonnull act = stack.Top()->todo.Top(); - Nonnull exp = cast(*act).Exp(); + const Expression& exp = cast(*act).expression(); if (tracing_output) { - llvm::outs() << "--- step exp " << *exp << " (" << exp->source_loc() + llvm::outs() << "--- step exp " << exp << " (" << exp.source_loc() << ") --->\n"; } - switch (exp->kind()) { + switch (exp.kind()) { case Expression::Kind::IndexExpression: { if (act->pos() == 0) { // { { e[i] :: C, E, F} :: S, H} // -> { { e :: [][i] :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*exp).aggregate())}; + &cast(exp).aggregate())}; } else if (act->pos() == 1) { - return Spawn{arena->New( - &cast(*exp).offset())}; + return Spawn{ + arena->New(&cast(exp).offset())}; } else { // { { v :: [][i] :: C, E, F} :: S, H} // -> { { v_i :: C, E, F} : S, H} @@ -490,19 +490,19 @@ auto Interpreter::StepExp() -> Transition { } case Expression::Kind::TupleLiteral: { if (act->pos() < - static_cast(cast(*exp).fields().size())) { + static_cast(cast(exp).fields().size())) { // { { vk :: (f1=v1,..., fk=[],fk+1=ek+1,...) :: C, E, F} :: S, // H} // -> { { ek+1 :: (f1=v1,..., fk=vk, fk+1=[],...) :: C, E, F} :: S, // H} return Spawn{arena->New( - cast(*exp).fields()[act->pos()])}; + cast(exp).fields()[act->pos()])}; } else { - return Done{CreateTuple(act, exp)}; + return Done{CreateTuple(act, &exp)}; } } case Expression::Kind::StructLiteral: { - const auto& literal = cast(*exp); + const auto& literal = cast(exp); if (act->pos() < static_cast(literal.fields().size())) { return Spawn{arena->New( &literal.fields()[act->pos()].expression())}; @@ -511,7 +511,7 @@ auto Interpreter::StepExp() -> Transition { } } case Expression::Kind::StructTypeLiteral: { - const auto& struct_type = cast(*exp); + const auto& struct_type = cast(exp); if (act->pos() < static_cast(struct_type.fields().size())) { return Spawn{arena->New( &struct_type.fields()[act->pos()].expression())}; @@ -524,7 +524,7 @@ auto Interpreter::StepExp() -> Transition { } } case Expression::Kind::FieldAccessExpression: { - const auto& access = cast(*exp); + const auto& access = cast(exp); if (act->pos() == 0) { // { { e.f :: C, E, F} :: S, H} // -> { { e :: [].f :: C, E, F} :: S, H} @@ -533,26 +533,26 @@ auto Interpreter::StepExp() -> Transition { // { { v :: [].f :: C, E, F} :: S, H} // -> { { v_f :: C, E, F} : S, H} return Done{act->results()[0]->GetField( - arena, FieldPath(access.field()), exp->source_loc())}; + arena, FieldPath(access.field()), exp.source_loc())}; } } case Expression::Kind::IdentifierExpression: { CHECK(act->pos() == 0); - const auto& ident = cast(*exp); + const auto& ident = cast(exp); // { {x :: C, E, F} :: S, H} -> { {H(E(x)) :: C, E, F} :: S, H} - Address pointer = GetFromEnv(exp->source_loc(), ident.name()); - return Done{heap.Read(pointer, exp->source_loc())}; + Address pointer = GetFromEnv(exp.source_loc(), ident.name()); + return Done{heap.Read(pointer, exp.source_loc())}; } case Expression::Kind::IntLiteral: CHECK(act->pos() == 0); // { {n :: C, E, F} :: S, H} -> { {n' :: C, E, F} :: S, H} - return Done{arena->New(cast(*exp).value())}; + return Done{arena->New(cast(exp).value())}; case Expression::Kind::BoolLiteral: CHECK(act->pos() == 0); // { {n :: C, E, F} :: S, H} -> { {n' :: C, E, F} :: S, H} - return Done{arena->New(cast(*exp).value())}; + return Done{arena->New(cast(exp).value())}; case Expression::Kind::PrimitiveOperatorExpression: { - const auto& op = cast(*exp); + const auto& op = cast(exp); if (act->pos() != static_cast(op.arguments().size())) { // { {v :: op(vs,[],e,es) :: C, E, F} :: S, H} // -> { {e :: op(vs,v,[],es) :: C, E, F} :: S, H} @@ -561,7 +561,7 @@ auto Interpreter::StepExp() -> Transition { } else { // { {v :: op(vs,[]) :: C, E, F} :: S, H} // -> { {eval_prim(op, (vs,v)) :: C, E, F} :: S, H} - return Done{EvalPrim(op.op(), act->results(), exp->source_loc())}; + return Done{EvalPrim(op.op(), act->results(), exp.source_loc())}; } } case Expression::Kind::CallExpression: @@ -569,12 +569,12 @@ auto Interpreter::StepExp() -> Transition { // { {e1(e2) :: C, E, F} :: S, H} // -> { {e1 :: [](e2) :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*exp).function())}; + &cast(exp).function())}; } else if (act->pos() == 1) { // { { v :: [](e) :: C, E, F} :: S, H} // -> { { e :: v([]) :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*exp).argument())}; + &cast(exp).argument())}; } else if (act->pos() == 2) { // { { v2 :: v1([]) :: C, E, F} :: S, H} // -> { {C',E',F'} :: {C, E, F} :: S, H} @@ -583,7 +583,7 @@ auto Interpreter::StepExp() -> Transition { const auto& alt = cast(*act->results()[0]); Nonnull arg = - CopyVal(arena, act->results()[1], exp->source_loc()); + CopyVal(arena, act->results()[1], exp.source_loc()); return Done{arena->New(alt.alt_name(), alt.choice_name(), arg)}; } @@ -594,9 +594,9 @@ auto Interpreter::StepExp() -> Transition { .function = Nonnull( cast(act->results()[0])), .args = act->results()[1], - .source_loc = exp->source_loc()}; + .source_loc = exp.source_loc()}; default: - FATAL_RUNTIME_ERROR(exp->source_loc()) + FATAL_RUNTIME_ERROR(exp.source_loc()) << "in call, expected a function, not " << *act->results()[0]; } } else { @@ -605,10 +605,10 @@ auto Interpreter::StepExp() -> Transition { case Expression::Kind::IntrinsicExpression: CHECK(act->pos() == 0); // { {n :: C, E, F} :: S, H} -> { {n' :: C, E, F} :: S, H} - switch (cast(*exp).intrinsic()) { + switch (cast(exp).intrinsic()) { case IntrinsicExpression::Intrinsic::Print: - Address pointer = GetFromEnv(exp->source_loc(), "format_str"); - Nonnull pointee = heap.Read(pointer, exp->source_loc()); + Address pointer = GetFromEnv(exp.source_loc(), "format_str"); + Nonnull pointee = heap.Read(pointer, exp.source_loc()); CHECK(pointee->kind() == Value::Kind::StringValue); // TODO: This could eventually use something like llvm::formatv. llvm::outs() << cast(*pointee).value(); @@ -630,12 +630,12 @@ auto Interpreter::StepExp() -> Transition { case Expression::Kind::FunctionTypeLiteral: { if (act->pos() == 0) { return Spawn{arena->New( - &cast(*exp).parameter())}; + &cast(exp).parameter())}; } else if (act->pos() == 1) { // { { pt :: fn [] -> e :: C, E, F} :: S, H} // -> { { e :: fn pt -> []) :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*exp).return_type())}; + &cast(exp).return_type())}; } else { // { { rt :: fn pt -> [] :: C, E, F} :: S, H} // -> { fn pt -> rt :: {C, E, F} :: S, H} @@ -651,7 +651,7 @@ auto Interpreter::StepExp() -> Transition { case Expression::Kind::StringLiteral: CHECK(act->pos() == 0); // { {n :: C, E, F} :: S, H} -> { {n' :: C, E, F} :: S, H} - return Done{arena->New(cast(*exp).value())}; + return Done{arena->New(cast(exp).value())}; case Expression::Kind::StringTypeLiteral: { CHECK(act->pos() == 0); return Done{arena->New()}; @@ -661,18 +661,18 @@ auto Interpreter::StepExp() -> Transition { auto Interpreter::StepPattern() -> Transition { Nonnull act = stack.Top()->todo.Top(); - Nonnull pattern = cast(*act).Pat(); + const Pattern& pattern = cast(*act).pattern(); if (tracing_output) { - llvm::outs() << "--- step pattern " << *pattern << " (" - << pattern->source_loc() << ") --->\n"; + llvm::outs() << "--- step pattern " << pattern << " (" + << pattern.source_loc() << ") --->\n"; } - switch (pattern->kind()) { + switch (pattern.kind()) { case Pattern::Kind::AutoPattern: { CHECK(act->pos() == 0); return Done{arena->New()}; } case Pattern::Kind::BindingPattern: { - const auto& binding = cast(*pattern); + const auto& binding = cast(pattern); if (act->pos() == 0) { return Spawn{arena->New(&binding.type())}; } else { @@ -681,7 +681,7 @@ auto Interpreter::StepPattern() -> Transition { } } case Pattern::Kind::TuplePattern: { - const auto& tuple = cast(*pattern); + const auto& tuple = cast(pattern); if (act->pos() < static_cast(tuple.fields().size())) { // { { vk :: (f1=v1,..., fk=[],fk+1=ek+1,...) :: C, E, F} :: S, // H} @@ -693,7 +693,7 @@ auto Interpreter::StepPattern() -> Transition { } } case Pattern::Kind::AlternativePattern: { - const auto& alternative = cast(*pattern); + const auto& alternative = cast(pattern); if (act->pos() == 0) { return Spawn{arena->New(&alternative.choice_type())}; } else if (act->pos() == 1) { @@ -708,14 +708,14 @@ auto Interpreter::StepPattern() -> Transition { } case Pattern::Kind::ExpressionPattern: return Delegate{arena->New( - &cast(*pattern).expression())}; + &cast(pattern).expression())}; } } static auto IsWhileAct(Nonnull act) -> bool { switch (act->kind()) { case Action::Kind::StatementAction: - switch (cast(*act).Stmt()->kind()) { + switch (cast(*act).statement().kind()) { case Statement::Kind::While: return true; default: @@ -729,7 +729,7 @@ static auto IsWhileAct(Nonnull act) -> bool { static auto HasLocalScope(Nonnull act) -> bool { switch (act->kind()) { case Action::Kind::StatementAction: - switch (cast(*act).Stmt()->kind()) { + switch (cast(*act).statement().kind()) { case Statement::Kind::Block: case Statement::Kind::Match: return true; @@ -744,15 +744,15 @@ static auto HasLocalScope(Nonnull act) -> bool { auto Interpreter::StepStmt() -> Transition { Nonnull frame = stack.Top(); Nonnull act = frame->todo.Top(); - Nonnull stmt = cast(*act).Stmt(); + const Statement& stmt = cast(*act).statement(); if (tracing_output) { llvm::outs() << "--- step stmt "; - stmt->PrintDepth(1, llvm::outs()); - llvm::outs() << " (" << stmt->source_loc() << ") --->\n"; + stmt.PrintDepth(1, llvm::outs()); + llvm::outs() << " (" << stmt.source_loc() << ") --->\n"; } - switch (stmt->kind()) { + switch (stmt.kind()) { case Statement::Kind::Match: { - const auto& match_stmt = cast(*stmt); + const auto& match_stmt = cast(stmt); if (act->pos() == 0) { // { { (match (e) ...) :: C, E, F} :: S, H} // -> { { e :: (match ([]) ...) :: C, E, F} :: S, H} @@ -784,7 +784,7 @@ auto Interpreter::StepStmt() -> Transition { } else { // try to match auto v = act->results()[0]; auto pat = act->results()[clause_num + 1]; - std::optional matches = PatternMatch(pat, v, stmt->source_loc()); + std::optional matches = PatternMatch(pat, v, stmt.source_loc()); if (matches) { // we have a match, start the body // Ensure we don't process any more clauses. act->set_pos(2 * match_stmt.clauses().size() + 1); @@ -806,11 +806,11 @@ auto Interpreter::StepStmt() -> Transition { // -> { { e :: (while ([]) s) :: C, E, F} :: S, H} act->Clear(); return Spawn{ - arena->New(&cast(*stmt).condition())}; + arena->New(&cast(stmt).condition())}; } else if (cast(*act->results().back()).value()) { // { {true :: (while ([]) s) :: C, E, F} :: S, H} // -> { { s :: (while (e) s) :: C, E, F } :: S, H} - return Spawn{arena->New(&cast(*stmt).body())}; + return Spawn{arena->New(&cast(stmt).body())}; } else { // { {false :: (while ([]) s) :: C, E, F} :: S, H} // -> { { C, E, F } :: S, H} @@ -823,7 +823,7 @@ auto Interpreter::StepStmt() -> Transition { auto it = std::find_if(frame->todo.begin(), frame->todo.end(), &IsWhileAct); if (it == frame->todo.end()) { - FATAL_RUNTIME_ERROR(stmt->source_loc()) + FATAL_RUNTIME_ERROR(stmt.source_loc()) << "`break` not inside `while` statement"; } ++it; @@ -836,14 +836,14 @@ auto Interpreter::StepStmt() -> Transition { auto it = std::find_if(frame->todo.begin(), frame->todo.end(), &IsWhileAct); if (it == frame->todo.end()) { - FATAL_RUNTIME_ERROR(stmt->source_loc()) + FATAL_RUNTIME_ERROR(stmt.source_loc()) << "`continue` not inside `while` statement"; } return UnwindTo{*it}; } case Statement::Kind::Block: { if (act->pos() == 0) { - const auto& block = cast(*stmt); + const auto& block = cast(stmt); if (block.statement()) { frame->scopes.Push(arena->New(CurrentEnv())); return Spawn{arena->New(*block.statement())}; @@ -862,19 +862,19 @@ auto Interpreter::StepStmt() -> Transition { // { {(var x = e) :: C, E, F} :: S, H} // -> { {e :: (var x = []) :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*stmt).init())}; + &cast(stmt).init())}; } else if (act->pos() == 1) { return Spawn{arena->New( - &cast(*stmt).pattern())}; + &cast(stmt).pattern())}; } else { // { { v :: (x = []) :: C, E, F} :: S, H} // -> { { C, E(x := a), F} :: S, H(a := copy(v))} Nonnull v = act->results()[0]; Nonnull p = act->results()[1]; - std::optional matches = PatternMatch(p, v, stmt->source_loc()); + std::optional matches = PatternMatch(p, v, stmt.source_loc()); CHECK(matches) - << stmt->source_loc() + << stmt.source_loc() << ": internal error in variable definition, match failed"; for (const auto& [name, value] : *matches) { frame->scopes.Top()->values.Set(name, value); @@ -887,7 +887,7 @@ auto Interpreter::StepStmt() -> Transition { // { {e :: C, E, F} :: S, H} // -> { {e :: C, E, F} :: S, H} return Spawn{arena->New( - &cast(*stmt).expression())}; + &cast(stmt).expression())}; } else { return Done{}; } @@ -895,37 +895,36 @@ auto Interpreter::StepStmt() -> Transition { if (act->pos() == 0) { // { {(lv = e) :: C, E, F} :: S, H} // -> { {lv :: ([] = e) :: C, E, F} :: S, H} - return Spawn{arena->New(&cast(*stmt).lhs())}; + return Spawn{arena->New(&cast(stmt).lhs())}; } else if (act->pos() == 1) { // { { a :: ([] = e) :: C, E, F} :: S, H} // -> { { e :: (a = []) :: C, E, F} :: S, H} - return Spawn{arena->New(&cast(*stmt).rhs())}; + return Spawn{arena->New(&cast(stmt).rhs())}; } else { // { { v :: (a = []) :: C, E, F} :: S, H} // -> { { C, E, F} :: S, H(a := v)} auto pat = act->results()[0]; auto val = act->results()[1]; - PatternAssignment(pat, val, stmt->source_loc()); + PatternAssignment(pat, val, stmt.source_loc()); return Done{}; } case Statement::Kind::If: if (act->pos() == 0) { // { {(if (e) then_stmt else else_stmt) :: C, E, F} :: S, H} // -> { { e :: (if ([]) then_stmt else else_stmt) :: C, E, F} :: S, H} - return Spawn{ - arena->New(&cast(*stmt).condition())}; + return Spawn{arena->New(&cast(stmt).condition())}; } else if (cast(*act->results()[0]).value()) { // { {true :: if ([]) then_stmt else else_stmt :: C, E, F} :: // S, H} // -> { { then_stmt :: C, E, F } :: S, H} return Delegate{ - arena->New(&cast(*stmt).then_statement())}; - } else if (cast(*stmt).else_statement()) { + arena->New(&cast(stmt).then_statement())}; + } else if (cast(stmt).else_statement()) { // { {false :: if ([]) then_stmt else else_stmt :: C, E, F} :: // S, H} // -> { { else_stmt :: C, E, F } :: S, H} return Delegate{ - arena->New(*cast(*stmt).else_statement())}; + arena->New(*cast(stmt).else_statement())}; } else { return Done{}; } @@ -934,24 +933,24 @@ auto Interpreter::StepStmt() -> Transition { // { {return e :: C, E, F} :: S, H} // -> { {e :: return [] :: C, E, F} :: S, H} return Spawn{ - arena->New(&cast(*stmt).expression())}; + arena->New(&cast(stmt).expression())}; } else { // { {v :: return [] :: C, E, F} :: {C', E', F'} :: S, H} // -> { {v :: C', E', F'} :: S, H} Nonnull ret_val = - CopyVal(arena, act->results()[0], stmt->source_loc()); + CopyVal(arena, act->results()[0], stmt.source_loc()); return UnwindFunctionCall{ret_val}; } case Statement::Kind::Sequence: { // { { (s1,s2) :: C, E, F} :: S, H} // -> { { s1 :: s2 :: C, E, F} :: S, H} - const auto& seq = cast(*stmt); + const auto& seq = cast(stmt); if (act->pos() == 0) { return Spawn{arena->New(&seq.statement())}; } else { if (seq.next()) { return Delegate{ - arena->New(*cast(*stmt).next())}; + arena->New(*cast(stmt).next())}; } else { return Done{}; } @@ -964,8 +963,8 @@ auto Interpreter::StepStmt() -> Transition { auto scopes = Stack>(arena->New(CurrentEnv())); Stack> todo; todo.Push(arena->New( - arena->New(arena, stmt->source_loc()))); - todo.Push(arena->New(&cast(*stmt).body())); + arena->New(arena, stmt.source_loc()))); + todo.Push(arena->New(&cast(stmt).body())); auto continuation_stack = arena->New>>(); auto continuation_frame = arena->New("__continuation", scopes, todo); @@ -976,7 +975,7 @@ auto Interpreter::StepStmt() -> Transition { continuation_frame->continuation = continuation_address; // Bind the continuation object to the continuation variable frame->scopes.Top()->values.Set( - cast(*stmt).continuation_variable(), + cast(stmt).continuation_variable(), continuation_address); // Pop the continuation statement. frame->todo.Pop(); @@ -985,16 +984,15 @@ auto Interpreter::StepStmt() -> Transition { case Statement::Kind::Run: if (act->pos() == 0) { // Evaluate the argument of the run statement. - return Spawn{ - arena->New(&cast(*stmt).argument())}; + return Spawn{arena->New(&cast(stmt).argument())}; } else { frame->todo.Pop(1); // Push an expression statement action to ignore the result // value from the continuation. auto ignore_result = arena->New(arena->New( - stmt->source_loc(), - arena->New(stmt->source_loc()))); + stmt.source_loc(), + arena->New(stmt.source_loc()))); frame->todo.Push(ignore_result); // Push the continuation onto the current stack. std::vector>& continuation_vector = @@ -1015,7 +1013,7 @@ auto Interpreter::StepStmt() -> Transition { } while (paused.back()->continuation == std::nullopt); // Update the continuation with the paused stack. const auto& continuation = cast( - *heap.Read(*paused.back()->continuation, stmt->source_loc())); + *heap.Read(*paused.back()->continuation, stmt.source_loc())); CHECK(continuation.stack().empty()); continuation.stack() = std::move(paused); return ManualTransition{};