Merge pull request #20 from nicksavers/master

Fix typo and remove some unused imports
This commit is contained in:
romanman 2014-06-03 08:49:35 +03:00
commit 57234f2591
5 changed files with 36 additions and 58 deletions

View File

@ -34,7 +34,7 @@ public class ProgramPlayDialog extends JPanel implements ActionListener, ChangeL
program.addListener(this); program.addListener(this);
program.fullTrace(); program.fullTrace();
while(!program.isStoped()) while(!program.isStopped())
vm.step(program); vm.step(program);
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

View File

@ -1,14 +1,11 @@
package org.ethereum.vm; package org.ethereum.vm;
import com.fasterxml.jackson.databind.ser.std.ArraySerializerBase;
import org.spongycastle.util.Arrays; import org.spongycastle.util.Arrays;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import static java.util.Arrays.*;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil

View File

@ -1,11 +1,8 @@
package org.ethereum.vm; package org.ethereum.vm;
import com.google.api.client.util.ByteStreams;
import io.netty.buffer.UnpooledDirectByteBuf;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -65,7 +62,7 @@ public class Program {
this.pc = pc; this.pc = pc;
} }
public boolean isStoped(){ public boolean isStopped(){
return stopped; return stopped;
} }

View File

@ -20,7 +20,7 @@ public class VM {
Logger logger = LoggerFactory.getLogger("VM"); Logger logger = LoggerFactory.getLogger("VM");
public void step(Program program){ public void step(Program program) {
try { try {
@ -28,7 +28,7 @@ public class VM {
byte op = program.getCurrentOp(); byte op = program.getCurrentOp();
logger.debug("Op: {}" ,OpCode.code(op).name()); logger.debug("Op: {}" ,OpCode.code(op).name());
switch (OpCode.code(op)){ switch (OpCode.code(op)) {
/** /**
@ -36,12 +36,10 @@ public class VM {
*/ */
case STOP:{ case STOP:{
program.stop(); program.stop();
} }
break; break;
case ADD:{ case ADD:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
word1.add(word2); word1.add(word2);
@ -50,7 +48,6 @@ public class VM {
} }
break; break;
case MUL:{ case MUL:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
word1.mull(word2); word1.mull(word2);
@ -59,7 +56,6 @@ public class VM {
} }
break; break;
case SUB:{ case SUB:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
word1.sub(word2); word1.sub(word2);
@ -68,7 +64,6 @@ public class VM {
} }
break; break;
case DIV:{ case DIV:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
word1.div(word2); word1.div(word2);
@ -83,7 +78,6 @@ public class VM {
case SMOD: case SMOD:
break; break;
case EXP:{ case EXP:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
word1.exp(word2); word1.exp(word2);
@ -96,7 +90,8 @@ public class VM {
word1.negate(); word1.negate();
program.stackPush(word1); program.stackPush(word1);
program.step(); program.step();
}break; }
break;
case LT:{ case LT:{
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
@ -108,12 +103,13 @@ public class VM {
} }
program.stackPush(word1); program.stackPush(word1);
program.step(); program.step();
}break; }
break;
case SLT: case SLT:
break; break;
case SGT: case SGT:
break; break;
case GT:{ case GT: {
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
if (word1.value().compareTo(word2.value()) == 1){ if (word1.value().compareTo(word2.value()) == 1){
@ -124,8 +120,9 @@ public class VM {
} }
program.stackPush(word1); program.stackPush(word1);
program.step(); program.step();
}break; }
case EQ:{ break;
case EQ: {
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
if (word1.xor(word2).isZero()){ if (word1.xor(word2).isZero()){
@ -150,8 +147,6 @@ public class VM {
} }
break; break;
/** /**
* Bitwise Logic Operations * Bitwise Logic Operations
*/ */
@ -180,20 +175,18 @@ public class VM {
program.step(); program.step();
} }
break; break;
case BYTE:{ case BYTE: {
DataWord word1 = program.stackPull(); DataWord word1 = program.stackPull();
DataWord word2 = program.stackPull(); DataWord word2 = program.stackPull();
DataWord result = null; DataWord result = null;
if (word1.value().compareTo(_32_) == -1){ if (word1.value().compareTo(_32_) == -1){
byte tmp = word2.getData()[word1.value().intValue()]; byte tmp = word2.getData()[word1.value().intValue()];
word2.and(DataWord.ZERO); word2.and(DataWord.ZERO);
word2.getData()[31] = tmp; word2.getData()[31] = tmp;
result = word2; result = word2;
} else } else {
result = new DataWord(); result = new DataWord();
}
program.stackPush(result); program.stackPush(result);
program.step(); program.step();
} }
@ -267,7 +260,6 @@ public class VM {
case SWAP:{ case SWAP:{
DataWord word_1 = program.stackPull(); DataWord word_1 = program.stackPull();
DataWord word_2 = program.stackPull(); DataWord word_2 = program.stackPull();
program.stackPush(word_1); program.stackPush(word_1);
program.stackPush(word_2); program.stackPush(word_2);
program.step(); program.step();
@ -283,13 +275,11 @@ public class VM {
case MSTORE:{ case MSTORE:{
DataWord addr = program.stackPull(); DataWord addr = program.stackPull();
DataWord value = program.stackPull(); DataWord value = program.stackPull();
program.memorySave(addr, value); program.memorySave(addr, value);
program.step(); program.step();
} }
break; break;
case MSTORE8:{ case MSTORE8:{
DataWord addr = program.stackPull(); DataWord addr = program.stackPull();
DataWord value = program.stackPull(); DataWord value = program.stackPull();
byte[] byteVal = {value.getData()[31]}; byte[] byteVal = {value.getData()[31]};
@ -300,8 +290,7 @@ public class VM {
case SLOAD:{ case SLOAD:{
DataWord key = program.stackPull(); DataWord key = program.stackPull();
DataWord val = program.storageLoad(key); DataWord val = program.storageLoad(key);
if (val == null) {
if (val == null){
val = key.and(DataWord.ZERO); val = key.and(DataWord.ZERO);
} }
program.stackPush(val); program.stackPush(val);
@ -311,7 +300,6 @@ public class VM {
case SSTORE:{ case SSTORE:{
DataWord addr = program.stackPull(); DataWord addr = program.stackPull();
DataWord value = program.stackPull(); DataWord value = program.stackPull();
program.storageSave(addr, value); program.storageSave(addr, value);
program.step(); program.step();
} }
@ -324,7 +312,6 @@ public class VM {
case JUMPI:{ case JUMPI:{
DataWord pos = program.stackPull(); DataWord pos = program.stackPull();
DataWord cond = program.stackPull(); DataWord cond = program.stackPull();
if (!cond.isZero()){ if (!cond.isZero()){
program.setPC(pos); program.setPC(pos);
} else{ } else{
@ -335,13 +322,11 @@ public class VM {
case PC:{ case PC:{
int pc = program.getPC(); int pc = program.getPC();
DataWord pcWord = new DataWord(pc); DataWord pcWord = new DataWord(pc);
program.stackPush(pcWord); program.stackPush(pcWord);
program.step(); program.step();
} }
break; break;
case MEMSIZE:{ case MEMSIZE:{
int memSize = program.getMemSize(); int memSize = program.getMemSize();
DataWord wordMemSize = new DataWord(memSize); DataWord wordMemSize = new DataWord(memSize);
program.stackPush(wordMemSize); program.stackPush(wordMemSize);

View File

@ -1,6 +1,5 @@
package org.ethereum.vm; package org.ethereum.vm;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -444,7 +443,7 @@ public class VMTest {
program.fullTrace(); program.fullTrace();
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -460,7 +459,7 @@ public class VMTest {
program.fullTrace(); program.fullTrace();
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -504,7 +503,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -548,7 +547,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -593,7 +592,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -653,7 +652,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -695,7 +694,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -753,7 +752,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -811,7 +810,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -870,7 +869,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -978,7 +977,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1011,7 +1010,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1236,7 +1235,7 @@ public class VMTest {
try { try {
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1296,7 +1295,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1487,7 +1486,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1540,7 +1539,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1615,7 +1614,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1676,7 +1675,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1829,7 +1828,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();
@ -1923,7 +1922,7 @@ public class VMTest {
vm.step(program); vm.step(program);
vm.step(program); vm.step(program);
} catch (RuntimeException e) { } catch (RuntimeException e) {
assertTrue(program.isStoped()); assertTrue(program.isStopped());
return; return;
} }
fail(); fail();