diff options
author | jm <jm.huang@cobinhood.com> | 2019-01-15 00:48:13 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:03 +0800 |
commit | 266068a53cdf9e06acacf982d63653c03133a634 (patch) | |
tree | af2d74e6adb309adfe39bafaa2f540fe0bcd1a31 /core/vm/stack.go | |
parent | d41cb421d755b8f0bca87b7476f26aa4b879b9d9 (diff) | |
download | dexon-266068a53cdf9e06acacf982d63653c03133a634.tar dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.gz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.bz2 dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.lz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.xz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.zst dexon-266068a53cdf9e06acacf982d63653c03133a634.zip |
core: vm: refactor file structure
For support other vm types, this pr modified the core/vm file
structures.
Diffstat (limited to 'core/vm/stack.go')
-rw-r--r-- | core/vm/stack.go | 69 |
1 files changed, 23 insertions, 46 deletions
diff --git a/core/vm/stack.go b/core/vm/stack.go index 14b1c289b..45553d499 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -13,83 +13,60 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - package vm import ( "fmt" "math/big" - "sync" ) -var stackPool = sync.Pool{ - New: func() interface{} { - return &Stack{data: make([]*big.Int, 0, 1024)} - }, -} - // Stack is an object for basic stack operations. Items popped to the stack are // expected to be changed and modified. stack does not take care of adding newly // initialised objects. type Stack struct { - data []*big.Int -} - -func newstack() *Stack { - stack := stackPool.Get().(*Stack) - stack.data = stack.data[:0] - return stack -} - -func recyclestack(stack *Stack) { - stackPool.Put(stack) -} - -// Data returns the underlying big.Int array. -func (st *Stack) Data() []*big.Int { - return st.data + Data []*big.Int } -func (st *Stack) push(d *big.Int) { +func (st *Stack) Push(d *big.Int) { // NOTE push limit (1024) is checked in baseCheck //stackItem := new(big.Int).Set(d) - //st.data = append(st.data, stackItem) - st.data = append(st.data, d) + //st.Data = append(st.Data, stackItem) + st.Data = append(st.Data, d) } -func (st *Stack) pushN(ds ...*big.Int) { - st.data = append(st.data, ds...) +func (st *Stack) PushN(ds ...*big.Int) { + st.Data = append(st.Data, ds...) } -func (st *Stack) pop() (ret *big.Int) { - ret = st.data[len(st.data)-1] - st.data = st.data[:len(st.data)-1] +func (st *Stack) Pop() (ret *big.Int) { + ret = st.Data[len(st.Data)-1] + st.Data = st.Data[:len(st.Data)-1] return } -func (st *Stack) len() int { - return len(st.data) +func (st *Stack) Len() int { + return len(st.Data) } -func (st *Stack) swap(n int) { - st.data[st.len()-n], st.data[st.len()-1] = st.data[st.len()-1], st.data[st.len()-n] +func (st *Stack) Swap(n int) { + st.Data[st.Len()-n], st.Data[st.Len()-1] = st.Data[st.Len()-1], st.Data[st.Len()-n] } -func (st *Stack) dup(pool *intPool, n int) { - st.push(pool.get().Set(st.data[st.len()-n])) +func (st *Stack) Dup(pool *IntPool, n int) { + st.Push(pool.Get().Set(st.Data[st.Len()-n])) } -func (st *Stack) peek() *big.Int { - return st.data[st.len()-1] +func (st *Stack) Peek() *big.Int { + return st.Data[st.Len()-1] } // Back returns the n'th item in stack func (st *Stack) Back(n int) *big.Int { - return st.data[st.len()-n-1] + return st.Data[st.Len()-n-1] } -func (st *Stack) require(n int) error { - if st.len() < n { - return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n) +func (st *Stack) Require(n int) error { + if st.Len() < n { + return fmt.Errorf("stack underflow (%d <=> %d)", len(st.Data), n) } return nil } @@ -97,8 +74,8 @@ func (st *Stack) require(n int) error { // Print dumps the content of the stack func (st *Stack) Print() { fmt.Println("### stack ###") - if len(st.data) > 0 { - for i, val := range st.data { + if len(st.Data) > 0 { + for i, val := range st.Data { fmt.Printf("%-3d %v\n", i, val) } } else { |