aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/runtime/instructions.go
diff options
context:
space:
mode:
authorJhih-Ming Huang <jm.huang@cobinhood.com>2019-02-11 15:24:39 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:03 +0800
commitf3e53ca8523363ecd6f203bb30a7e510df85280c (patch)
tree3581661a8ae39e5ecabbbb76abf1f64c06d2ca2e /core/vm/sqlvm/runtime/instructions.go
parentfa7f1118a60685b3bd8b6fed56df70813a367549 (diff)
downloaddexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar.gz
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar.bz2
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar.lz
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar.xz
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.tar.zst
dexon-f3e53ca8523363ecd6f203bb30a7e510df85280c.zip
core: vm: sqlvm: shared interfaces and params
After reconstructing commits, we move shared interfaces and params as first runtime implementation. In this commit we define OP codes, runtime flow and entrypoint, and basic operand structs and minor helper components.
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
+}