Destructuring assignments.

This commit is contained in:
chriseth
2015-10-15 17:38:42 +02:00
parent 7ebd536e79
commit 039b2a764f
11 changed files with 389 additions and 105 deletions
+11 -4
View File
@@ -597,13 +597,20 @@ bool Compiler::visit(Break const& _breakStatement)
bool Compiler::visit(Return const& _return)
{
CompilerContext::LocationSetter locationSetter(m_context, _return);
//@todo modifications are needed to make this work with functions returning multiple values
if (Expression const* expression = _return.expression())
{
solAssert(_return.annotation().functionReturnParameters, "Invalid return parameters pointer.");
VariableDeclaration const& firstVariable = *_return.annotation().functionReturnParameters->parameters().front();
compileExpression(*expression, firstVariable.annotation().type);
CompilerUtils(m_context).moveToStackVariable(firstVariable);
vector<ASTPointer<VariableDeclaration>> const& returnParameters =
_return.annotation().functionReturnParameters->parameters();
TypePointers types;
for (auto const& retVariable: returnParameters)
types.push_back(retVariable->annotation().type);
TypePointer expectedType = types.size() == 1 ? types.front() : make_shared<TupleType>(types);
compileExpression(*expression, expectedType);
for (auto const& retVariable: boost::adaptors::reverse(returnParameters))
CompilerUtils(m_context).moveToStackVariable(*retVariable);
}
for (unsigned i = 0; i < m_stackCleanupForReturn; ++i)
m_context << eth::Instruction::POP;