mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #582 from chriseth/sol_varSizeVariables
Variably sized elements on the stack
This commit is contained in:
commit
93722eab8a
@ -125,8 +125,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers)
|
|||||||
byte(Instruction::JUMP), // end of f
|
byte(Instruction::JUMP), // end of f
|
||||||
byte(Instruction::JUMPDEST), // beginning of g
|
byte(Instruction::JUMPDEST), // beginning of g
|
||||||
byte(Instruction::PUSH1), 0x0,
|
byte(Instruction::PUSH1), 0x0,
|
||||||
byte(Instruction::DUP1), // initialized e and h
|
byte(Instruction::PUSH1), 0x0, // initialized e and h
|
||||||
byte(Instruction::PUSH1), byte(0x29 + shift), // ret address
|
byte(Instruction::PUSH1), byte(0x2a + shift), // ret address
|
||||||
byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||||
byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||||
byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND),
|
||||||
|
@ -1025,6 +1025,41 @@ BOOST_AUTO_TEST_CASE(calls_to_this)
|
|||||||
BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(a * b + 10));
|
BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(a * b + 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars)
|
||||||
|
{
|
||||||
|
// note that a reference to another contract's function occupies two stack slots,
|
||||||
|
// so this tests correct stack slot allocation
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract Helper {
|
||||||
|
function multiply(uint a, uint b) returns (uint c) {
|
||||||
|
return a * b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contract Main {
|
||||||
|
Helper h;
|
||||||
|
function callHelper(uint a, uint b) returns (uint c) {
|
||||||
|
var fu = h.multiply;
|
||||||
|
var y = 9;
|
||||||
|
var ret = fu(a, b);
|
||||||
|
return ret + y;
|
||||||
|
}
|
||||||
|
function getHelper() returns (address haddress) {
|
||||||
|
return address(h);
|
||||||
|
}
|
||||||
|
function setHelper(address haddress) {
|
||||||
|
h = Helper(haddress);
|
||||||
|
}
|
||||||
|
})";
|
||||||
|
compileAndRun(sourceCode, 0, "Helper");
|
||||||
|
u160 const helperAddress = m_contractAddress;
|
||||||
|
compileAndRun(sourceCode, 0, "Main");
|
||||||
|
BOOST_REQUIRE(callContractFunction(2, helperAddress) == bytes());
|
||||||
|
BOOST_REQUIRE(callContractFunction(1, helperAddress) == toBigEndian(helperAddress));
|
||||||
|
u256 a(3456789);
|
||||||
|
u256 b("0x282837623374623234aa74");
|
||||||
|
BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(a * b + 9));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user