Commit 59d8dc39 authored by obscuren's avatar obscuren

Fixed issue with stack where it sliced of the wrong values

parent 38ea6a6d
...@@ -2,6 +2,7 @@ package ethchain ...@@ -2,6 +2,7 @@ package ethchain
import ( import (
"fmt" "fmt"
"github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
) )
...@@ -60,6 +61,10 @@ const ( ...@@ -60,6 +61,10 @@ const (
oBALANCE = 0x3c oBALANCE = 0x3c
oMKTX = 0x3d oMKTX = 0x3d
oSUICIDE = 0x3f oSUICIDE = 0x3f
// TODO FIX OPCODES
oCALL = 0x40
oRETURN = 0x41
) )
// Since the opcodes aren't all in order we can't use a regular slice // Since the opcodes aren't all in order we can't use a regular slice
...@@ -114,6 +119,9 @@ var opCodeToString = map[OpCode]string{ ...@@ -114,6 +119,9 @@ var opCodeToString = map[OpCode]string{
oBALANCE: "BALANCE", oBALANCE: "BALANCE",
oMKTX: "MKTX", oMKTX: "MKTX",
oSUICIDE: "SUICIDE", oSUICIDE: "SUICIDE",
oCALL: "CALL",
oRETURN: "RETURN",
} }
func (o OpCode) String() string { func (o OpCode) String() string {
...@@ -141,6 +149,56 @@ func NewStack() *Stack { ...@@ -141,6 +149,56 @@ func NewStack() *Stack {
} }
func (st *Stack) Pop() *big.Int { func (st *Stack) Pop() *big.Int {
str := st.data[0]
st.data = st.data[1:]
return str
}
func (st *Stack) Popn() (*big.Int, *big.Int) {
ints := st.data[:2]
st.data = st.data[2:]
return ints[0], ints[1]
}
func (st *Stack) Peek() *big.Int {
str := st.data[0]
return str
}
func (st *Stack) Peekn() (*big.Int, *big.Int) {
ints := st.data[:2]
return ints[0], ints[1]
}
func (st *Stack) Push(d *big.Int) {
st.data = append(st.data, d)
}
func (st *Stack) Print() {
fmt.Println("### STACK ###")
if len(st.data) > 0 {
for i, val := range st.data {
fmt.Printf("%-3d %v\n", i, val)
}
} else {
fmt.Println("-- empty --")
}
fmt.Println("#############")
}
////////////// TODO this will eventually become the main stack once the big ints are removed from the VM
type ValueStack struct {
data []*ethutil.Value
}
func NewValueStack() *ValueStack {
return &ValueStack{}
}
func (st *ValueStack) Pop() *ethutil.Value {
s := len(st.data) s := len(st.data)
str := st.data[s-1] str := st.data[s-1]
...@@ -149,7 +207,7 @@ func (st *Stack) Pop() *big.Int { ...@@ -149,7 +207,7 @@ func (st *Stack) Pop() *big.Int {
return str return str
} }
func (st *Stack) Popn() (*big.Int, *big.Int) { func (st *ValueStack) Popn() (*ethutil.Value, *ethutil.Value) {
s := len(st.data) s := len(st.data)
ints := st.data[s-2:] ints := st.data[s-2:]
...@@ -158,7 +216,7 @@ func (st *Stack) Popn() (*big.Int, *big.Int) { ...@@ -158,7 +216,7 @@ func (st *Stack) Popn() (*big.Int, *big.Int) {
return ints[0], ints[1] return ints[0], ints[1]
} }
func (st *Stack) Peek() *big.Int { func (st *ValueStack) Peek() *ethutil.Value {
s := len(st.data) s := len(st.data)
str := st.data[s-1] str := st.data[s-1]
...@@ -166,7 +224,7 @@ func (st *Stack) Peek() *big.Int { ...@@ -166,7 +224,7 @@ func (st *Stack) Peek() *big.Int {
return str return str
} }
func (st *Stack) Peekn() (*big.Int, *big.Int) { func (st *ValueStack) Peekn() (*ethutil.Value, *ethutil.Value) {
s := len(st.data) s := len(st.data)
ints := st.data[s-2:] ints := st.data[s-2:]
...@@ -174,10 +232,10 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) { ...@@ -174,10 +232,10 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
return ints[0], ints[1] return ints[0], ints[1]
} }
func (st *Stack) Push(d *big.Int) { func (st *ValueStack) Push(d *ethutil.Value) {
st.data = append(st.data, d) st.data = append(st.data, d)
} }
func (st *Stack) Print() { func (st *ValueStack) Print() {
fmt.Println("### STACK ###") fmt.Println("### STACK ###")
if len(st.data) > 0 { if len(st.data) > 0 {
for i, val := range st.data { for i, val := range st.data {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment