aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-03-21 00:26:30 +0800
committerobscuren <geffobscura@gmail.com>2014-03-21 00:26:30 +0800
commit59d8dc39505981d1ae07b05a71d3f4cf1f33319a (patch)
tree9c973a115c6b2746ebb060bfcc316041ea46c517
parent38ea6a6d5dffb7573b29541c2a6687145bdcc495 (diff)
downloadgo-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar.gz
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar.bz2
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar.lz
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar.xz
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.tar.zst
go-tangerine-59d8dc39505981d1ae07b05a71d3f4cf1f33319a.zip
Fixed issue with stack where it sliced of the wrong values
-rw-r--r--ethchain/stack.go68
1 files changed, 63 insertions, 5 deletions
diff --git a/ethchain/stack.go b/ethchain/stack.go
index 13b0f247b..349e7817a 100644
--- a/ethchain/stack.go
+++ b/ethchain/stack.go
@@ -2,6 +2,7 @@ package ethchain
import (
"fmt"
+ "github.com/ethereum/eth-go/ethutil"
"math/big"
)
@@ -60,6 +61,10 @@ const (
oBALANCE = 0x3c
oMKTX = 0x3d
oSUICIDE = 0x3f
+
+ // TODO FIX OPCODES
+ oCALL = 0x40
+ oRETURN = 0x41
)
// Since the opcodes aren't all in order we can't use a regular slice
@@ -114,6 +119,9 @@ var opCodeToString = map[OpCode]string{
oBALANCE: "BALANCE",
oMKTX: "MKTX",
oSUICIDE: "SUICIDE",
+
+ oCALL: "CALL",
+ oRETURN: "RETURN",
}
func (o OpCode) String() string {
@@ -141,6 +149,56 @@ func NewStack() *Stack {
}
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)
str := st.data[s-1]
@@ -149,7 +207,7 @@ func (st *Stack) Pop() *big.Int {
return str
}
-func (st *Stack) Popn() (*big.Int, *big.Int) {
+func (st *ValueStack) Popn() (*ethutil.Value, *ethutil.Value) {
s := len(st.data)
ints := st.data[s-2:]
@@ -158,7 +216,7 @@ func (st *Stack) Popn() (*big.Int, *big.Int) {
return ints[0], ints[1]
}
-func (st *Stack) Peek() *big.Int {
+func (st *ValueStack) Peek() *ethutil.Value {
s := len(st.data)
str := st.data[s-1]
@@ -166,7 +224,7 @@ func (st *Stack) Peek() *big.Int {
return str
}
-func (st *Stack) Peekn() (*big.Int, *big.Int) {
+func (st *ValueStack) Peekn() (*ethutil.Value, *ethutil.Value) {
s := len(st.data)
ints := st.data[s-2:]
@@ -174,10 +232,10 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
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)
}
-func (st *Stack) Print() {
+func (st *ValueStack) Print() {
fmt.Println("### STACK ###")
if len(st.data) > 0 {
for i, val := range st.data {