aboutsummaryrefslogtreecommitdiffstats
path: root/vm.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-03 06:02:24 +0800
committerobscuren <obscuren@obscura.com>2014-01-03 06:02:24 +0800
commit9df4c745119b3ed10a7ad17887e8dd9cac249af7 (patch)
tree8ae82afaf78a225d685a146a4cc67a77d3ca773d /vm.go
parent5b3d4fae6e03e5471a10c653fc0b016cc5e5dcfa (diff)
downloadgo-tangerine-9df4c745119b3ed10a7ad17887e8dd9cac249af7.tar.gz
go-tangerine-9df4c745119b3ed10a7ad17887e8dd9cac249af7.tar.zst
go-tangerine-9df4c745119b3ed10a7ad17887e8dd9cac249af7.zip
WIP rewrite vm
Diffstat (limited to 'vm.go')
-rw-r--r--vm.go68
1 files changed, 66 insertions, 2 deletions
diff --git a/vm.go b/vm.go
index 787e29295..f38e7be06 100644
--- a/vm.go
+++ b/vm.go
@@ -1,16 +1,18 @@
package main
import (
- "math"
+ _"math"
"math/big"
"fmt"
- "strconv"
+ _"strconv"
_ "encoding/hex"
)
// Op codes
const (
oSTOP int = 0x00
+ oPSH int = 0x30
+ /*
oADD int = 0x10
oSUB int = 0x11
oMUL int = 0x12
@@ -46,6 +48,7 @@ const (
oDATAN int = 0x81
oMYADDRESS int = 0x90
oSUICIDE int = 0xff
+ */
)
type OpType int
@@ -57,6 +60,66 @@ const (
)
type TxCallback func(opType OpType) bool
+// Simple push/pop stack mechanism
+type Stack struct {
+ data []string
+}
+func NewStack() *Stack {
+ return &Stack{}
+}
+func (st *Stack) Pop() string {
+ s := len(st.data)
+
+ str := st.data[s]
+ st.data = st.data[:s-1]
+
+ return str
+}
+
+func (st *Stack) Push(d string) {
+ st.data = append(st.data, d)
+}
+
+type Vm struct {
+ // Stack
+ stack *Stack
+}
+
+func NewVm() *Vm {
+ return &Vm{
+ stack: NewStack(),
+ }
+}
+
+func (vm *Vm) RunTransaction(tx *Transaction, block *Block, cb TxCallback) {
+ // Instruction pointer
+ iptr := 0
+
+ // Index pointer for the memory
+ memIndex := 0
+
+ fmt.Printf("# op arg\n")
+ for iptr < len(tx.data) {
+ memIndex++
+ // The base big int for all calculations. Use this for any results.
+ base := new(big.Int)
+ base.SetString("0",0) // so it doesn't whine about it
+ // XXX Should Instr return big int slice instead of string slice?
+ op, args, _ := Instr(tx.data[iptr])
+
+ if Debug {
+ fmt.Printf("%-3d %-4d %v\n", iptr, op, args)
+ }
+
+ switch op {
+ case oPSH:
+ }
+ // Increment instruction pointer
+ iptr++
+ }
+}
+
+/*
type Vm struct {
// Memory stack
stack map[string]string
@@ -183,3 +246,4 @@ out:
}
}
}
+*/