aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/runtime/instructions.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/sqlvm/runtime/instructions.go')
-rw-r--r--core/vm/sqlvm/runtime/instructions.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
new file mode 100644
index 000000000..f642a2515
--- /dev/null
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -0,0 +1,63 @@
+package runtime
+
+import (
+ "fmt"
+ "math/big"
+ "strings"
+
+ "github.com/dexon-foundation/dexon/core/vm/sqlvm/ast"
+ "github.com/dexon-foundation/dexon/core/vm/sqlvm/common"
+)
+
+var tupleJoin = "|"
+
+// OpFunction type
+// data could be fields Fields, pattern []byte, order Orders
+type OpFunction func(ctx *common.Context, ops []*Operand, registers []*Operand, output int) error
+
+// Instruction represents single instruction with essential information
+// collection.
+type Instruction struct {
+ op OpCode
+ input []*Operand
+ output int
+}
+
+// Raw with embedded big.Int value or byte slice which represents the real value
+// of basic operand unit.
+type Raw struct {
+ MajorType ast.DataTypeMajor
+ MinorType ast.DataTypeMinor
+
+ // for not bytes
+ Value *big.Int
+ Max, Min *big.Int
+ // for bytes
+ Bytes []byte
+}
+
+func (r *Raw) String() string {
+ return fmt.Sprintf(
+ "MajorType: %v, MinorType: %v, Value: %v, Bytes: %v",
+ r.MajorType, r.MinorType, r.Value, r.Bytes)
+}
+
+// Tuple is collection of Raw.
+type Tuple []*Raw
+
+func (t Tuple) String() string {
+ rawStr := []string{}
+ for i := 0; i < len(t); i++ {
+ rawStr = append(rawStr, t[i].String())
+ }
+ return strings.Join(rawStr, tupleJoin)
+}
+
+// Operand would be array-based value associated with meta to describe type of
+// array element.
+type Operand struct {
+ IsImmediate bool
+ Meta []ast.DataType
+ Data []Tuple
+ RegisterIndex *int
+}