diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-10 18:23:49 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-10 18:23:49 +0800 |
commit | 38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3 (patch) | |
tree | 3877af08004f9dc2de00001257c9fe678de049d1 /core/vm/stack.go | |
parent | ff5b3ef0877978699235d20b3caa9890b35ec6f8 (diff) | |
download | go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar.gz go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar.bz2 go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar.lz go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar.xz go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.tar.zst go-tangerine-38c61f6f2567e7943c9a16e2be0a2bfedb3a1fb3.zip |
core, core/vm: added structure logging
This also reduces the time required spend in the VM
Diffstat (limited to 'core/vm/stack.go')
-rw-r--r-- | core/vm/stack.go | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/core/vm/stack.go b/core/vm/stack.go index bb232d0b9..1d0a018c6 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -5,16 +5,20 @@ import ( "math/big" ) -func newStack() *stack { - return &stack{} +func newStack() *Stack { + return &Stack{} } -type stack struct { +type Stack struct { data []*big.Int ptr int } -func (st *stack) push(d *big.Int) { +func (st *Stack) Data() []*big.Int { + return st.data +} + +func (st *Stack) push(d *big.Int) { // NOTE push limit (1024) is checked in baseCheck stackItem := new(big.Int).Set(d) if len(st.data) > st.ptr { @@ -25,36 +29,36 @@ func (st *stack) push(d *big.Int) { st.ptr++ } -func (st *stack) pop() (ret *big.Int) { +func (st *Stack) pop() (ret *big.Int) { st.ptr-- ret = st.data[st.ptr] return } -func (st *stack) len() int { +func (st *Stack) len() int { return st.ptr } -func (st *stack) swap(n int) { +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(n int) { +func (st *Stack) dup(n int) { st.push(st.data[st.len()-n]) } -func (st *stack) peek() *big.Int { +func (st *Stack) peek() *big.Int { return st.data[st.len()-1] } -func (st *stack) require(n int) error { +func (st *Stack) require(n int) error { if st.len() < n { return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n) } return nil } -func (st *stack) Print() { +func (st *Stack) Print() { fmt.Println("### stack ###") if len(st.data) > 0 { for i, val := range st.data { |