Use `leave` in code generator.

This commit is contained in:
chriseth 2019-10-24 19:23:56 +02:00
parent f98925d8b6
commit c30839888f
2 changed files with 3 additions and 8 deletions

View File

@ -132,10 +132,7 @@ string IRGenerator::generateFunction(FunctionDefinition const& _function)
return m_context.functionCollector()->createFunction(functionName, [&]() { return m_context.functionCollector()->createFunction(functionName, [&]() {
Whiskers t(R"( Whiskers t(R"(
function <functionName>(<params>) <returns> { function <functionName>(<params>) <returns> {
for { let return_flag := 1 } return_flag {} { <body>
<body>
break
}
} }
)"); )");
t("functionName", functionName); t("functionName", functionName);

View File

@ -296,7 +296,7 @@ void IRGeneratorForStatements::endVisit(Return const& _return)
expressionAsType(*value, *types.front()) << expressionAsType(*value, *types.front()) <<
"\n"; "\n";
} }
m_code << "return_flag := 0\n" << "break\n"; m_code << "leave\n";
} }
void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation) void IRGeneratorForStatements::endVisit(UnaryOperation const& _unaryOperation)
@ -1349,7 +1349,7 @@ void IRGeneratorForStatements::generateLoop(
m_code << "for {\n"; m_code << "for {\n";
if (_initExpression) if (_initExpression)
_initExpression->accept(*this); _initExpression->accept(*this);
m_code << "} return_flag {\n"; m_code << "} 1 {\n";
if (_loopExpression) if (_loopExpression)
_loopExpression->accept(*this); _loopExpression->accept(*this);
m_code << "}\n"; m_code << "}\n";
@ -1373,8 +1373,6 @@ void IRGeneratorForStatements::generateLoop(
_body.accept(*this); _body.accept(*this);
m_code << "}\n"; m_code << "}\n";
// Bubble up the return condition.
m_code << "if iszero(return_flag) { break }\n";
} }
Type const& IRGeneratorForStatements::type(Expression const& _expression) Type const& IRGeneratorForStatements::type(Expression const& _expression)