Skip to content

Commit b6cb527

Browse files
committed
Descriptive function names for closure getters
1 parent 6d99c03 commit b6cb527

3 files changed

Lines changed: 28 additions & 40 deletions

File tree

‎cmd/mist/debugger.go‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
152152
block := self.lib.eth.ChainManager().CurrentBlock
153153

154154
env := utils.NewEnv(statedb, block, account.Address(), value)
155-
/*
156-
callerClosure := vm.NewClosure(&state.Message{}, account, contract, script, gas, gasPrice)
157-
evm := vm.NewDebugVm(env)
158-
evm.Dbg = self.Db
159-
self.vm = evm
160-
self.Db.done = false
161-
*/
162155

163156
self.Logf("callsize %d", len(script))
164157
go func() {

‎vm/closure.go‎

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package vm
22

3-
// TODO Re write VM to use values instead of big integers?
4-
53
import (
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
2118
type 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

6148
func (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+
*/
9581
func (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

11394
func (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+
*/
120104
func (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+
*/
139126
func (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+
}

‎vm/vm_debug.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
737737
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
738738
a := big.NewInt(int64(op) - int64(PUSH1) + 1)
739739
pc.Add(pc, ethutil.Big1)
740-
data := closure.Gets(pc, a)
740+
data := closure.GetRangeValue(pc, a)
741741
val := ethutil.BigD(data.Bytes())
742742
// Push value to stack
743743
stack.Push(val)
@@ -754,7 +754,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
754754

755755
self.Printf(" => [%d] 0x%x", n, stack.Peek().Bytes())
756756

757-
if OpCode(closure.Get(new(big.Int).Add(pc, ethutil.Big1)).Uint()) == POP && OpCode(closure.Get(new(big.Int).Add(pc, big.NewInt(2))).Uint()) == POP {
757+
if OpCode(closure.GetValue(new(big.Int).Add(pc, ethutil.Big1)).Uint()) == POP && OpCode(closure.GetValue(new(big.Int).Add(pc, big.NewInt(2))).Uint()) == POP {
758758
fmt.Println(toValue(v))
759759
}
760760
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:

0 commit comments

Comments
 (0)