mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Working implementation of arraypush
ByteArrayPush() gets a test but is ignored for now, since there are still some issues with its implementation
This commit is contained in:
parent
a521843f6b
commit
9224c1f712
@ -623,27 +623,29 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
appendExternalFunctionCall(function, arguments);
|
||||
break;
|
||||
}
|
||||
case Location::ByteArrayPush:
|
||||
solAssert(false, "Not properly implemented yet");
|
||||
case Location::ArrayPush:
|
||||
{
|
||||
cout << "Beginning " << m_context.stackHeight() << endl;
|
||||
_functionCall.expression().accept(*this);
|
||||
solAssert(function.parameterTypes().size() == 1, "");
|
||||
solAssert(!!function.parameterTypes()[0], "");
|
||||
TypePointer const& paramType = function.parameterTypes()[0];
|
||||
ArrayType arrayType(DataLocation::Storage, paramType);
|
||||
shared_ptr<ArrayType> arrayType =
|
||||
function.location() == Location::ArrayPush ?
|
||||
make_shared<ArrayType>(DataLocation::Storage, paramType) :
|
||||
make_shared<ArrayType>(DataLocation::Storage);
|
||||
// get the current length
|
||||
ArrayUtils(m_context).retrieveLength(arrayType);
|
||||
ArrayUtils(m_context).retrieveLength(*arrayType);
|
||||
m_context << eth::Instruction::DUP1;
|
||||
cout << "After DUP1 " << m_context.stackHeight() << endl;
|
||||
// stack: ArrayReference currentLength currentLength
|
||||
m_context << u256(1) << eth::Instruction::ADD;
|
||||
// stack: ArrayReference currentLength newLength
|
||||
m_context << eth::Instruction::DUP3 << eth::Instruction::DUP2;
|
||||
ArrayUtils(m_context).resizeDynamicArray(arrayType);
|
||||
cout << "After Resize Dynamic Array " << m_context.stackHeight() << endl;
|
||||
ArrayUtils(m_context).resizeDynamicArray(*arrayType);
|
||||
m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
|
||||
// stack: newLength ArrayReference oldLength
|
||||
ArrayUtils(m_context).accessIndex(arrayType, false);
|
||||
cout << "After Access Index " << m_context.stackHeight() << endl;
|
||||
ArrayUtils(m_context).accessIndex(*arrayType, false);
|
||||
|
||||
// stack: newLength storageSlot slotOffset
|
||||
arguments[0]->accept(*this);
|
||||
@ -657,9 +659,6 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
StorageItem(m_context, *paramType).storeValue(*type, _functionCall.location(), true);
|
||||
break;
|
||||
}
|
||||
case Location::ByteArrayPush:
|
||||
// TODO
|
||||
break;
|
||||
default:
|
||||
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Invalid function type."));
|
||||
}
|
||||
@ -852,7 +851,6 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
|
||||
}
|
||||
else
|
||||
solAssert(false, "Illegal array member.");
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -3493,9 +3493,28 @@ BOOST_AUTO_TEST_CASE(array_push)
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 2));
|
||||
BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3));
|
||||
}
|
||||
|
||||
#if 0 // reactivate once ByteArrayPush is properly implemented
|
||||
BOOST_AUTO_TEST_CASE(byte_array_push)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract c {
|
||||
bytes data;
|
||||
function test() returns (byte x, byte y, byte z, uint l) {
|
||||
data.push(5);
|
||||
x = data[0];
|
||||
data.push(4);
|
||||
y = data[1];
|
||||
l = data.push(3);
|
||||
z = data[2];
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction("test()") == encodeArgs(5, 4, 3, 3));
|
||||
}
|
||||
#endif
|
||||
BOOST_AUTO_TEST_CASE(external_array_args)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user