[Sol->Yul] Implementing empty byte array push.

This commit is contained in:
Djordje Mijovic 2020-12-09 19:29:11 +01:00
parent 052b97e217
commit ab74194ca3
3 changed files with 16 additions and 4 deletions

View File

@ -1339,19 +1339,27 @@ string YulUtilFunctions::storageArrayPushZeroFunction(ArrayType const& _type)
{
solAssert(_type.location() == DataLocation::Storage, "");
solAssert(_type.isDynamicallySized(), "");
solUnimplementedAssert(!_type.isByteArray(), "Byte Arrays not yet implemented!");
solUnimplementedAssert(_type.baseType()->storageBytes() <= 32, "Base type is not yet implemented.");
string functionName = "array_push_zero_" + _type.identifier();
return m_functionCollector.createFunction(functionName, [&]() {
return Whiskers(R"(
function <functionName>(array) -> slot, offset {
let oldLen := <fetchLength>(array)
if iszero(lt(oldLen, <maxArrayLength>)) { <panic>() }
sstore(array, add(oldLen, 1))
<?isBytes>
let data := sload(array)
let oldLen := <extractLength>(data)
<increaseBytesSize>(array, data, oldLen, add(oldLen, 1))
<!isBytes>
let oldLen := <fetchLength>(array)
if iszero(lt(oldLen, <maxArrayLength>)) { <panic>() }
sstore(array, add(oldLen, 1))
</isBytes>
slot, offset := <indexAccess>(array, oldLen)
})")
("functionName", functionName)
("isBytes", _type.isByteArray())
("increaseBytesSize", _type.isByteArray() ? increaseByteArraySizeFunction(_type) : "")
("extractLength", _type.isByteArray() ? extractByteArrayLengthFunction() : "")
("panic", panicFunction())
("fetchLength", arrayLengthFunction(_type))
("indexAccess", storageArrayIndexAccessFunction(_type))

View File

@ -22,6 +22,8 @@ contract C {
return data[0];
}
}
// ====
// compileViaYul: also
// ----
// fromMemory() -> 0x00
// fromCalldata(bytes): 0x40, 0x60, 0x00, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0x00

View File

@ -18,6 +18,8 @@ contract C {
return array[index];
}
}
// ====
// compileViaYul: also
// ----
// l() -> 0
// g(uint256): 70 ->