Add support for do/while loops

This commit adds support for a standard do <statement> while <expr>;
form of statement.  While loops were already being supported; supporting
a do/while loop mostly involves reusing code from while loops but putting
the conditional checking last.
This commit is contained in:
Rhett Aultman
2016-11-10 07:07:25 -08:00
parent dc8a5f4ef5
commit 4524ad0870
11 changed files with 92 additions and 11 deletions
+16 -3
View File
@@ -611,12 +611,25 @@ bool ContractCompiler::visit(WhileStatement const& _whileStatement)
m_breakTags.push_back(loopEnd);
m_context << loopStart;
compileExpression(_whileStatement.condition());
m_context << Instruction::ISZERO;
m_context.appendConditionalJumpTo(loopEnd);
// While loops have the condition prepended
if (!_whileStatement.isDoWhile())
{
compileExpression(_whileStatement.condition());
m_context << Instruction::ISZERO;
m_context.appendConditionalJumpTo(loopEnd);
}
_whileStatement.body().accept(*this);
// Do-while loops have the condition appended
if (_whileStatement.isDoWhile())
{
compileExpression(_whileStatement.condition());
m_context << Instruction::ISZERO;
m_context.appendConditionalJumpTo(loopEnd);
}
m_context.appendJumpTo(loopStart);
m_context << loopEnd;