11package vm
22
3- // TODO Re write VM to use values instead of big integers?
4-
53import (
64 "math/big"
75
@@ -17,7 +15,6 @@ type ClosureRef interface {
1715 SetStorage (* big.Int , * ethutil.Value )
1816}
1917
20- // Basic inline closure object which implement the 'closure' interface
2118type Closure struct {
2219 caller ClosureRef
2320 object ClosureRef
@@ -44,18 +41,8 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
4441 return c
4542}
4643
47- // Retuns the x element in data slice
48- func (c * Closure ) GetStorage (x * big.Int ) * ethutil.Value {
49- m := c .object .GetStorage (x )
50- if m == nil {
51- return ethutil .EmptyValue ()
52- }
53-
54- return m
55- }
56-
57- func (c * Closure ) Get (x * big.Int ) * ethutil.Value {
58- return c .Gets (x , big .NewInt (1 ))
44+ func (c * Closure ) GetValue (x * big.Int ) * ethutil.Value {
45+ return c .GetRangeValue (x , big .NewInt (1 ))
5946}
6047
6148func (c * Closure ) GetOp (x int ) OpCode {
@@ -78,7 +65,7 @@ func (c *Closure) GetBytes(x, y int) []byte {
7865 return c .Code [x : x + y ]
7966}
8067
81- func (c * Closure ) Gets (x , y * big.Int ) * ethutil.Value {
68+ func (c * Closure ) GetRangeValue (x , y * big.Int ) * ethutil.Value {
8269 if x .Int64 () >= int64 (len (c .Code )) || y .Int64 () >= int64 (len (c .Code )) {
8370 return ethutil .NewValue (0 )
8471 }
@@ -88,27 +75,21 @@ func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
8875 return ethutil .NewValue (partial )
8976}
9077
91- func (self * Closure ) SetCode (code []byte ) {
92- self .Code = code
93- }
94-
78+ /*
79+ * State storage functions
80+ */
9581func (c * Closure ) SetStorage (x * big.Int , val * ethutil.Value ) {
9682 c .object .SetStorage (x , val )
9783}
9884
99- func (c * Closure ) Address () []byte {
100- return c .object .Address ()
101- }
102-
103- /*
104- func (c *Closure) Call(vm VirtualMachine, args []byte) ([]byte, *big.Int, error) {
105- c.Args = args
106-
107- ret, err := vm.RunClosure(c)
85+ func (c * Closure ) GetStorage (x * big.Int ) * ethutil.Value {
86+ m := c .object .GetStorage (x )
87+ if m == nil {
88+ return ethutil .EmptyValue ()
89+ }
10890
109- return ret, c.UsedGas, err
91+ return m
11092}
111- */
11293
11394func (c * Closure ) Return (ret []byte ) []byte {
11495 // Return the remaining gas to the caller
@@ -117,6 +98,9 @@ func (c *Closure) Return(ret []byte) []byte {
11798 return ret
11899}
119100
101+ /*
102+ * Gas functions
103+ */
120104func (c * Closure ) UseGas (gas * big.Int ) bool {
121105 if c .Gas .Cmp (gas ) < 0 {
122106 return false
@@ -136,6 +120,17 @@ func (c *Closure) ReturnGas(gas, price *big.Int) {
136120 c .UsedGas .Sub (c .UsedGas , gas )
137121}
138122
123+ /*
124+ * Set / Get
125+ */
139126func (c * Closure ) Caller () ClosureRef {
140127 return c .caller
141128}
129+
130+ func (c * Closure ) Address () []byte {
131+ return c .object .Address ()
132+ }
133+
134+ func (self * Closure ) SetCode (code []byte ) {
135+ self .Code = code
136+ }
0 commit comments