aboutsummaryrefslogtreecommitdiffstats
path: root/ethvm/closure.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-14 17:48:52 +0800
committerobscuren <geffobscura@gmail.com>2014-10-14 17:48:52 +0800
commitc5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28 (patch)
tree5588276a932ac88daaaf9ca1858106ba3ff007b1 /ethvm/closure.go
parent2e894b668a2bde3eb83418cfd9128f3a571e0026 (diff)
downloaddexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.gz
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.tar.zst
dexon-c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28.zip
Refactored VM to two separate VMs; std & debug
Standard VM should be about 10x faster than the debug VM. Some error checking has been removed, all of the log statements and therefor quite some unnecessary if-statements.
Diffstat (limited to 'ethvm/closure.go')
-rw-r--r--ethvm/closure.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/ethvm/closure.go b/ethvm/closure.go
index c047a83b7..0cd3c768c 100644
--- a/ethvm/closure.go
+++ b/ethvm/closure.go
@@ -58,6 +58,26 @@ func (c *Closure) Get(x *big.Int) *ethutil.Value {
return c.Gets(x, big.NewInt(1))
}
+func (c *Closure) GetOp(x int) OpCode {
+ return OpCode(c.GetByte(x))
+}
+
+func (c *Closure) GetByte(x int) byte {
+ if x < len(c.Code) {
+ return c.Code[x]
+ }
+
+ return 0
+}
+
+func (c *Closure) GetBytes(x, y int) []byte {
+ if x >= len(c.Code) || y >= len(c.Code) {
+ return nil
+ }
+
+ return c.Code[x : x+y]
+}
+
func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
if x.Int64() >= int64(len(c.Code)) || y.Int64() >= int64(len(c.Code)) {
return ethutil.NewValue(0)
@@ -76,7 +96,7 @@ func (c *Closure) Address() []byte {
return c.object.Address()
}
-func (c *Closure) Call(vm *Vm, args []byte) ([]byte, *big.Int, error) {
+func (c *Closure) Call(vm VirtualMachine, args []byte) ([]byte, *big.Int, error) {
c.Args = args
ret, err := vm.RunClosure(c)