mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Compiler for assignments.
This commit is contained in:
parent
d706631412
commit
e08065a2fb
@ -200,16 +200,11 @@ 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), 0x1,
|
||||
byte(eth::Instruction::ADD),
|
||||
byte(eth::Instruction::PUSH1), 0x1,
|
||||
byte(eth::Instruction::SWAP1),
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::PUSH1), 0x0,
|
||||
byte(eth::Instruction::SUB),
|
||||
byte(eth::Instruction::BNOT),
|
||||
@ -219,6 +214,63 @@ BOOST_AUTO_TEST_CASE(unary_operators)
|
||||
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::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::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::MUL)});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user