Replace NEG with BNOT
This commit is contained in:
parent
056bea7f92
commit
bf8163da7a
|
@ -152,6 +152,11 @@ public class DataWord implements Comparable<DataWord> {
|
|||
}
|
||||
}
|
||||
|
||||
public void bnot() {
|
||||
if (this.isZero()) return;
|
||||
this.data = ByteUtil.copyToArray(MAX_VALUE.subtract(this.value()));
|
||||
}
|
||||
|
||||
// By : Holger
|
||||
// From : http://stackoverflow.com/a/24023466/459349
|
||||
public void add(DataWord word) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public enum OpCode {
|
|||
/** (0x08) Exponential operation */
|
||||
EXP(0x08, 2),
|
||||
/** (0x09) Negation operation */
|
||||
NEG(0x09, 1),
|
||||
BNOT(0x09, 1),
|
||||
/** (0x0a) Less-than comparison */
|
||||
LT(0X0a, 2),
|
||||
/** (0x0b) Greater-than comparison */
|
||||
|
|
|
@ -282,9 +282,9 @@ public class VM {
|
|||
program.stackPush(word1);
|
||||
program.step();
|
||||
} break;
|
||||
case NEG:{
|
||||
case BNOT:{
|
||||
DataWord word1 = program.stackPop();
|
||||
word1.negate();
|
||||
word1.bnot();
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
hint = "" + word1.value();
|
||||
|
|
|
@ -998,12 +998,12 @@ public class VMTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test // NEG OP
|
||||
public void testNEG_1() {
|
||||
@Test // BNOT OP
|
||||
public void testBNOT_1() {
|
||||
|
||||
VM vm = new VM();
|
||||
program = new Program(Hex.decode("600109"), invoke);
|
||||
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
|
||||
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE";
|
||||
|
||||
vm.step(program);
|
||||
vm.step(program);
|
||||
|
@ -1011,12 +1011,12 @@ public class VMTest {
|
|||
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
|
||||
}
|
||||
|
||||
@Test // NEG OP
|
||||
public void testNEG_2() {
|
||||
@Test // BNOT OP
|
||||
public void testBNOT_2() {
|
||||
|
||||
VM vm = new VM();
|
||||
program = new Program(Hex.decode("61A00309"), invoke);
|
||||
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFD";
|
||||
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFC";
|
||||
|
||||
vm.step(program);
|
||||
vm.step(program);
|
||||
|
@ -1024,8 +1024,8 @@ public class VMTest {
|
|||
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
|
||||
}
|
||||
|
||||
@Test // NEG OP
|
||||
public void testNEG_3() {
|
||||
@Test // BNOT OP
|
||||
public void testBNOT_3() {
|
||||
|
||||
VM vm = new VM();
|
||||
program = new Program(Hex.decode("61000009"), invoke);
|
||||
|
@ -1037,8 +1037,8 @@ public class VMTest {
|
|||
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
|
||||
}
|
||||
|
||||
@Test(expected=StackTooSmallException.class) // NEG OP
|
||||
public void testNEG_4() {
|
||||
@Test(expected=StackTooSmallException.class) // BNOT OP
|
||||
public void testBNOT_4() {
|
||||
|
||||
VM vm = new VM();
|
||||
program = new Program(Hex.decode("09"), invoke);
|
||||
|
|
Loading…
Reference in New Issue