1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
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
Value *big.Int
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
}
|