Switch Statement to std::variant (#639)

Aligns Assign/Assignment, If/IfStatement naming to favor the name in the enum.
This commit is contained in:
Jon Meow
2021-07-13 13:54:38 -07:00
committed by GitHub
parent b03d3cdbb0
commit 0960c51d20
5 changed files with 156 additions and 147 deletions
@@ -967,7 +967,7 @@ void StepExp() {
auto IsWhileAct(Action* act) -> bool {
switch (act->tag()) {
case ActionKind::StatementAction:
switch (act->GetStatementAction().stmt->tag) {
switch (act->GetStatementAction().stmt->tag()) {
case StatementKind::While:
return true;
default:
@@ -981,7 +981,7 @@ auto IsWhileAct(Action* act) -> bool {
auto IsBlockAct(Action* act) -> bool {
switch (act->tag()) {
case ActionKind::StatementAction:
switch (act->GetStatementAction().stmt->tag) {
switch (act->GetStatementAction().stmt->tag()) {
case StatementKind::Block:
return true;
default:
@@ -1004,7 +1004,7 @@ void StepStmt() {
PrintStatement(stmt, 1);
std::cout << " --->" << std::endl;
}
switch (stmt->tag) {
switch (stmt->tag()) {
case StatementKind::Match:
if (act->pos == 0) {
// { { (match (e) ...) :: C, E, F} :: S, H}
@@ -1164,7 +1164,8 @@ void StepStmt() {
if (act->pos == 0) {
// { {e :: C, E, F} :: S, H}
// -> { {e :: C, E, F} :: S, H}
frame->todo.Push(Action::MakeExpressionAction(stmt->GetExpression()));
frame->todo.Push(
Action::MakeExpressionAction(stmt->GetExpressionStatement().exp));
act->pos++;
} else {
frame->todo.Pop(1);
@@ -1216,7 +1217,7 @@ void StepStmt() {
if (act->pos == 0) {
// { {return e :: C, E, F} :: S, H}
// -> { {e :: return [] :: C, E, F} :: S, H}
frame->todo.Push(Action::MakeExpressionAction(stmt->GetReturn()));
frame->todo.Push(Action::MakeExpressionAction(stmt->GetReturn().exp));
act->pos++;
} else {
// { {v :: return [] :: C, E, F} :: {C', E', F'} :: S, H}
@@ -1256,7 +1257,7 @@ void StepStmt() {
continuation_frame->continuation = continuation_address;
// Bind the continuation object to the continuation variable
frame->scopes.Top()->values.Set(
*stmt->GetContinuation().continuation_variable, continuation_address);
stmt->GetContinuation().continuation_variable, continuation_address);
// Pop the continuation statement.
frame->todo.Pop();
break;
@@ -1270,9 +1271,10 @@ void StepStmt() {
frame->todo.Pop(1);
// Push an expression statement action to ignore the result
// value from the continuation.
Action* ignore_result = Action::MakeStatementAction(
Statement::MakeExpStmt(stmt->line_num, Expression::MakeTupleLiteral(
stmt->line_num, {})));
Action* ignore_result =
Action::MakeStatementAction(Statement::MakeExpressionStatement(
stmt->line_num,
Expression::MakeTupleLiteral(stmt->line_num, {})));
ignore_result->pos = 0;
frame->todo.Push(ignore_result);
// Push the continuation onto the current stack.
+12 -12
View File
@@ -456,7 +456,7 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
if (!s) {
return TCStatement(s, types);
}
switch (s->tag) {
switch (s->tag()) {
case StatementKind::Match: {
auto res = TypeCheckExp(s->GetMatch().exp, types, values, nullptr,
TCContext::ValueContext);
@@ -497,7 +497,7 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
const Value* rhs_ty = res.type;
auto lhs_res = TypeCheckExp(s->GetVariableDefinition().pat, types, values,
rhs_ty, TCContext::PatternContext);
const Statement* new_s = Statement::MakeVarDef(
const Statement* new_s = Statement::MakeVariableDefinition(
s->line_num, s->GetVariableDefinition().pat, res.exp);
return TCStatement(new_s, lhs_res.types);
}
@@ -509,7 +509,7 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
TypeCheckStmt(s->GetSequence().next, types2, values, ret_type);
auto types3 = next_res.types;
return TCStatement(
Statement::MakeSeq(s->line_num, stmt_res.stmt, next_res.stmt),
Statement::MakeSequence(s->line_num, stmt_res.stmt, next_res.stmt),
types3);
}
case StatementKind::Assign: {
@@ -524,9 +524,9 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
return TCStatement(new_s, lhs_res.types);
}
case StatementKind::ExpressionStatement: {
auto res = TypeCheckExp(s->GetExpression(), types, values, nullptr,
TCContext::ValueContext);
auto new_s = Statement::MakeExpStmt(s->line_num, res.exp);
auto res = TypeCheckExp(s->GetExpressionStatement().exp, types, values,
nullptr, TCContext::ValueContext);
auto new_s = Statement::MakeExpressionStatement(s->line_num, res.exp);
return TCStatement(new_s, types);
}
case StatementKind::If: {
@@ -543,7 +543,7 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
return TCStatement(new_s, types);
}
case StatementKind::Return: {
auto res = TypeCheckExp(s->GetReturn(), types, values, nullptr,
auto res = TypeCheckExp(s->GetReturn().exp, types, values, nullptr,
TCContext::ValueContext);
if (ret_type->tag() == ValKind::AutoType) {
// The following infers the return type from the first 'return'
@@ -559,9 +559,9 @@ auto TypeCheckStmt(const Statement* s, TypeEnv types, Env values,
TCStatement body_result =
TypeCheckStmt(s->GetContinuation().body, types, values, ret_type);
const Statement* new_continuation = Statement::MakeContinuation(
s->line_num, *s->GetContinuation().continuation_variable,
s->line_num, s->GetContinuation().continuation_variable,
body_result.stmt);
types.Set(*s->GetContinuation().continuation_variable,
types.Set(s->GetContinuation().continuation_variable,
Value::MakeContinuationType());
return TCStatement(new_continuation, types);
}
@@ -595,7 +595,7 @@ auto CheckOrEnsureReturn(const Statement* stmt, bool void_return, int line_num)
exit(-1);
}
}
switch (stmt->tag) {
switch (stmt->tag()) {
case StatementKind::Match: {
auto new_clauses =
new std::list<std::pair<const Expression*, const Statement*>>();
@@ -622,7 +622,7 @@ auto CheckOrEnsureReturn(const Statement* stmt, bool void_return, int line_num)
return stmt;
case StatementKind::Sequence:
if (stmt->GetSequence().next) {
return Statement::MakeSeq(
return Statement::MakeSequence(
stmt->line_num, stmt->GetSequence().stmt,
CheckOrEnsureReturn(stmt->GetSequence().next, void_return,
stmt->line_num));
@@ -641,7 +641,7 @@ auto CheckOrEnsureReturn(const Statement* stmt, bool void_return, int line_num)
case StatementKind::Continue:
case StatementKind::VariableDefinition:
if (void_return) {
return Statement::MakeSeq(
return Statement::MakeSequence(
stmt->line_num, stmt,
Statement::MakeReturn(stmt->line_num, Expression::MakeTupleLiteral(
stmt->line_num, {})));