diff options
author | Christian <c@ethdev.com> | 2014-10-25 22:52:22 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-10-29 21:33:25 +0800 |
commit | e08065a2fb67558300a7164d76b3da31f7fcc6d4 (patch) | |
tree | d431e49a41bfdd67c71cbe0cf9b72ee45fc981f7 | |
parent | d706631412f59aac245bab37e3041283f27fdf40 (diff) | |
download | dexon-solidity-e08065a2fb67558300a7164d76b3da31f7fcc6d4.tar.gz dexon-solidity-e08065a2fb67558300a7164d76b3da31f7fcc6d4.tar.zst dexon-solidity-e08065a2fb67558300a7164d76b3da31f7fcc6d4.zip |
Compiler for assignments.
-rw-r--r-- | solidityCompiler.cpp | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index 02a2287d..591330dd 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -200,22 +200,74 @@ BOOST_AUTO_TEST_CASE(arithmetics) BOOST_AUTO_TEST_CASE(unary_operators) { char const* sourceCode = "contract test {\n" - " function f() { var x = !(~+-(--(++1++)--) == 2); }" + " function f() { var x = !(~+-1 == 2); }" "}\n"; bytes code = compileFirstExpression(sourceCode); bytes expectation({byte(eth::Instruction::PUSH1), 0x1, + byte(eth::Instruction::PUSH1), 0x0, + byte(eth::Instruction::SUB), + byte(eth::Instruction::BNOT), + byte(eth::Instruction::PUSH1), 0x2, + byte(eth::Instruction::EQ), + byte(eth::Instruction::NOT)}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(unary_inc_dec) +{ + char const* sourceCode = "contract test {\n" + " function f(uint a) { var x = ((a++ ^ ++a) ^ a--) ^ --a; }" + "}\n"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::DUP9), // will change as soon as we have real stack tracking + byte(eth::Instruction::DUP1), + byte(eth::Instruction::PUSH1), 0x1, + byte(eth::Instruction::ADD), + byte(eth::Instruction::SWAP8), // will change + byte(eth::Instruction::POP), // first ++ + byte(eth::Instruction::DUP9), byte(eth::Instruction::PUSH1), 0x1, byte(eth::Instruction::ADD), + byte(eth::Instruction::SWAP8), // will change + byte(eth::Instruction::POP), // second ++ + byte(eth::Instruction::DUP8), // will change + byte(eth::Instruction::XOR), + byte(eth::Instruction::DUP9), // will change + byte(eth::Instruction::DUP1), byte(eth::Instruction::PUSH1), 0x1, byte(eth::Instruction::SWAP1), byte(eth::Instruction::SUB), - byte(eth::Instruction::PUSH1), 0x0, + byte(eth::Instruction::SWAP8), // will change + byte(eth::Instruction::POP), // first -- + byte(eth::Instruction::XOR), + byte(eth::Instruction::DUP9), + byte(eth::Instruction::PUSH1), 0x1, + byte(eth::Instruction::SWAP1), byte(eth::Instruction::SUB), - byte(eth::Instruction::BNOT), + byte(eth::Instruction::SWAP8), // will change + byte(eth::Instruction::POP), // second ++ + byte(eth::Instruction::DUP8), // will change + byte(eth::Instruction::XOR)}); + BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); +} + +BOOST_AUTO_TEST_CASE(assignment) +{ + char const* sourceCode = "contract test {\n" + " function f(uint a, uint b) { (a += b) * 2; }" + "}\n"; + bytes code = compileFirstExpression(sourceCode); + + bytes expectation({byte(eth::Instruction::DUP9), // will change as soon as we have real stack tracking + byte(eth::Instruction::DUP9), + byte(eth::Instruction::ADD), + byte(eth::Instruction::SWAP8), // will change + byte(eth::Instruction::POP), // first ++ + byte(eth::Instruction::DUP8), byte(eth::Instruction::PUSH1), 0x2, - byte(eth::Instruction::EQ), - byte(eth::Instruction::NOT)}); + byte(eth::Instruction::MUL)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } |