diff options
author | chriseth <c@ethdev.com> | 2014-12-10 21:49:12 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2014-12-10 21:49:12 +0800 |
commit | 93722eab8ac58bc3e33825f0dc71b60fcc4ddb95 (patch) | |
tree | cfc5e16825330f8e2133b2775fbe2328de6bffcd | |
parent | 8aba43c5e06a03d6f692af3ddf6e783d5e3a6068 (diff) | |
parent | 125e39dd0143e6cdf7519ac86bfebdf0a1ea8d90 (diff) | |
download | dexon-solidity-93722eab8ac58bc3e33825f0dc71b60fcc4ddb95.tar.gz dexon-solidity-93722eab8ac58bc3e33825f0dc71b60fcc4ddb95.tar.zst dexon-solidity-93722eab8ac58bc3e33825f0dc71b60fcc4ddb95.zip |
Merge pull request #582 from chriseth/sol_varSizeVariables
Variably sized elements on the stack
-rw-r--r-- | solidityCompiler.cpp | 4 | ||||
-rw-r--r-- | solidityEndToEndTest.cpp | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index 9862cba8..004740b5 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -125,8 +125,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) byte(Instruction::JUMP), // end of f byte(Instruction::JUMPDEST), // beginning of g byte(Instruction::PUSH1), 0x0, - byte(Instruction::DUP1), // initialized e and h - byte(Instruction::PUSH1), byte(0x29 + shift), // ret address + byte(Instruction::PUSH1), 0x0, // initialized e and h + byte(Instruction::PUSH1), byte(0x2a + shift), // ret address 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), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 9e02438e..3c2bb081 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -1025,6 +1025,41 @@ BOOST_AUTO_TEST_CASE(calls_to_this) 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() } |