Browse Source

Adjustments for the NEG->BNOT change.

cl-refactor
Christian 10 years ago
parent
commit
0877cf6036
  1. 13
      libsolidity/Compiler.cpp
  2. 4
      test/solidityCompiler.cpp

13
libsolidity/Compiler.cpp

@ -107,13 +107,7 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation)
append(eth::Instruction::NOT);
break;
case Token::BIT_NOT: // ~
// ~a modeled as "a xor (0 - 1)" for now
append(eth::Instruction::PUSH1);
append(1);
append(eth::Instruction::PUSH1);
append(0);
append(eth::Instruction::SUB);
append(eth::Instruction::XOR);
append(eth::Instruction::BNOT);
break;
case Token::DELETE: // delete
// a -> a xor a (= 0).
@ -145,7 +139,10 @@ void ExpressionCompiler::endVisit(UnaryOperation& _unaryOperation)
// unary add, so basically no-op
break;
case Token::SUB: // -
append(eth::Instruction::NEG);
// unary -x translates into "0-x"
append(eth::Instruction::PUSH1);
append(0);
append(eth::Instruction::SUB);
break;
default:
assert(false); // invalid operation

4
test/solidityCompiler.cpp

@ -212,11 +212,9 @@ BOOST_AUTO_TEST_CASE(unary_operators)
byte(eth::Instruction::PUSH1), 0x1,
byte(eth::Instruction::SWAP1),
byte(eth::Instruction::SUB),
byte(eth::Instruction::NEG),
byte(eth::Instruction::PUSH1), 0x1,
byte(eth::Instruction::PUSH1), 0x0,
byte(eth::Instruction::SUB),
byte(eth::Instruction::XOR), // bitwise not
byte(eth::Instruction::BNOT),
byte(eth::Instruction::PUSH1), 0x2,
byte(eth::Instruction::EQ),
byte(eth::Instruction::NOT)});

Loading…
Cancel
Save