aboutsummaryrefslogtreecommitdiffstats
path: root/vm.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-28 08:46:18 +0800
committerobscuren <obscuren@obscura.com>2013-12-28 08:46:18 +0800
commitc7dc92e1270c3e2522edc10d9e757d9be48c0789 (patch)
tree26e9bb53fb0330a58ac7adb3c83a4a5e7976bb65 /vm.go
parent0f656652e6d76deebcfc7834923adf99eadc050f (diff)
downloadgo-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar.gz
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar.bz2
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar.lz
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar.xz
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.tar.zst
go-tangerine-c7dc92e1270c3e2522edc10d9e757d9be48c0789.zip
Reset stack pointer on run
Diffstat (limited to 'vm.go')
-rw-r--r--vm.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/vm.go b/vm.go
index 353f4f39e..dc026f318 100644
--- a/vm.go
+++ b/vm.go
@@ -60,8 +60,6 @@ type TxCallback func(opType OpType) bool
type Vm struct {
// Memory stack
stack map[string]string
- // Index ptr
- iptr int
memory map[string]map[string]string
}
@@ -71,7 +69,10 @@ func NewVm() *Vm {
stackSize := uint(256)
fmt.Println("stack size =", stackSize)
- return &Vm{make(map[string]string), 0, make(map[string]map[string]string)}
+ return &Vm{
+ stack: make(map[string]string),
+ memory: make(map[string]map[string]string),
+ }
}
func (vm *Vm) RunTransaction(tx *Transaction, cb TxCallback) {
@@ -84,6 +85,8 @@ func (vm *Vm) RunTransaction(tx *Transaction, cb TxCallback) {
vm.stack["0"] = tx.sender
vm.stack["1"] = "100" //int(tx.value)
vm.stack["1"] = "1000" //int(tx.fee)
+ // Stack pointer
+ stPtr := 0
//vm.memory[tx.addr] = make([]int, 256)
vm.memory[tx.addr] = make(map[string]string)
@@ -93,13 +96,13 @@ func (vm *Vm) RunTransaction(tx *Transaction, cb TxCallback) {
// Instructions are shorthanded as Ix/y/z
x := 0; y := 1; z := 2; //a := 3; b := 4; c := 5
out:
- for vm.iptr < len(tx.data) {
+ for stPtr < len(tx.data) {
// The base big int for all calculations. Use this for any results.
base := new(big.Int)
// XXX Should Instr return big int slice instead of string slice?
- op, args, _ := Instr(tx.data[vm.iptr])
+ op, args, _ := Instr(tx.data[stPtr])
- fmt.Printf("%-3d %d %v\n", vm.iptr, op, args)
+ fmt.Printf("%-3d %d %v\n", stPtr, op, args)
opType := OpType(tNorm)
// Determine the op type (used for calculating fees by the block manager)
@@ -113,7 +116,7 @@ out:
// If the callback yielded a negative result abort execution
if !cb(opType) { break out }
- nptr := vm.iptr
+ nptr := stPtr
switch op {
case oSTOP:
fmt.Println("exiting (oSTOP), idx =", nptr)
@@ -171,10 +174,10 @@ out:
break
}
- if vm.iptr == nptr {
- vm.iptr++
+ if stPtr == nptr {
+ stPtr++
} else {
- vm.iptr = nptr
+ stPtr = nptr
fmt.Println("... JMP", nptr, "...")
}
}