mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implementing Byte array push() and pop()
This commit is contained in:
@@ -12,6 +12,7 @@ contract c {
|
||||
l = data.length;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 2, 1, 1
|
||||
|
||||
@@ -9,5 +9,7 @@ contract c {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> FAILURE
|
||||
|
||||
@@ -13,6 +13,7 @@ contract c {
|
||||
if (l != 0x03) return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> false
|
||||
|
||||
@@ -13,6 +13,7 @@ contract c {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
contract c {
|
||||
bytes data;
|
||||
function test_short() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 15; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
|
||||
function test_long() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 33; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
|
||||
function test_pop() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 32; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
data.pop();
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test_short() -> 1780731860627700044960722568376587075150542249149356309979516913770823710
|
||||
// test_long() -> 67
|
||||
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979440702
|
||||
@@ -0,0 +1,21 @@
|
||||
// Tests transition between short and long encoding both ways
|
||||
contract c {
|
||||
bytes data;
|
||||
|
||||
function test() public returns (uint256) {
|
||||
for (uint8 i = 0; i < 33; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
for (uint8 i = 0; i < data.length; i++)
|
||||
if (data[i] != bytes1(i)) return i;
|
||||
data.pop();
|
||||
data.pop();
|
||||
for (uint8 i = 0; i < data.length; i++)
|
||||
if (data[i] != bytes1(i)) return i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
||||
Reference in New Issue
Block a user