aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-12 12:13:42 +0800
committerobscuren <geffobscura@gmail.com>2014-04-12 12:13:42 +0800
commit086acd122b59071255b0c1cfae569748b1d7427a (patch)
tree6ff564b1720298085ad89de53a2b4e4f0db21ca7
parent116516158da637cde50d27d600db6661732fc402 (diff)
downloadgo-tangerine-086acd122b59071255b0c1cfae569748b1d7427a.tar.gz
go-tangerine-086acd122b59071255b0c1cfae569748b1d7427a.tar.zst
go-tangerine-086acd122b59071255b0c1cfae569748b1d7427a.zip
Added pre processing of script data
-rw-r--r--ethchain/closure.go2
-rw-r--r--ethchain/vm.go5
-rw-r--r--ethutil/parsing.go31
3 files changed, 35 insertions, 3 deletions
diff --git a/ethchain/closure.go b/ethchain/closure.go
index de2196499..0fbe48f92 100644
--- a/ethchain/closure.go
+++ b/ethchain/closure.go
@@ -69,7 +69,7 @@ func (c *Closure) Address() []byte {
return c.object.Address()
}
-type DebugHook func(op OpCode, mem *Memory, stack *Stack)
+type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack)
func (c *Closure) Call(vm *Vm, args []byte, hook DebugHook) []byte {
c.Args = args
diff --git a/ethchain/vm.go b/ethchain/vm.go
index fbe0d0439..b88cd2861 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -312,6 +312,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) []byte {
stack.Push(val)
pc.Add(pc, big.NewInt(31))
+ step++
case oPUSH20:
pc.Add(pc, ethutil.Big1)
data := closure.Gets(pc, big.NewInt(20))
@@ -321,7 +322,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) []byte {
stack.Push(val)
pc.Add(pc, big.NewInt(19))
-
+ step++
case oPOP:
stack.Pop()
case oDUP:
@@ -410,7 +411,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) []byte {
pc.Add(pc, ethutil.Big1)
if hook != nil {
- hook(op, mem, stack)
+ hook(step-1, op, mem, stack)
}
}
}
diff --git a/ethutil/parsing.go b/ethutil/parsing.go
index 278414982..328704cae 100644
--- a/ethutil/parsing.go
+++ b/ethutil/parsing.go
@@ -3,6 +3,7 @@ package ethutil
import (
_ "fmt"
"math/big"
+ "regexp"
)
// Op codes
@@ -132,3 +133,33 @@ func Assemble(instructions ...interface{}) (script []byte) {
return
}
+
+/*
+Prepocessing function that takes init and main apart:
+init() {
+ // something
+}
+
+main() {
+ // main something
+}
+*/
+func PreProcess(data string) (mainInput, initInput string) {
+ reg := "\\(\\)\\s*{([\\d\\w\\W\\n\\s]+?)}"
+ mainReg := regexp.MustCompile("main" + reg)
+ initReg := regexp.MustCompile("init" + reg)
+
+ main := mainReg.FindStringSubmatch(data)
+ if len(main) > 0 {
+ mainInput = main[1]
+ } else {
+ mainInput = data
+ }
+
+ init := initReg.FindStringSubmatch(data)
+ if len(init) > 0 {
+ initInput = init[1]
+ }
+
+ return
+}