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.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index d61bacdde..6fa72d61a 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
+ "math/big"
"regexp"
"sort"
"strings"
@@ -98,6 +99,14 @@ func (op *Operand) toUint64() (result []uint64, err error) {
return
}
+func (op *Operand) toTableRef() (schema.TableRef, error) {
+ t, err := op.toUint8()
+ if err != nil {
+ return 0, err
+ }
+ return schema.TableRef(t[0]), nil
+}
+
func (op *Operand) toUint8() ([]uint8, error) {
result := make([]uint8, len(op.Data))
for i, tuple := range op.Data {
@@ -1881,3 +1890,30 @@ func opFunc(ctx *common.Context, ops, registers []*Operand, output uint) (err er
registers[output] = result
return
}
+
+func uint64ToOperands(numbers []uint64) (*Operand, error) {
+ result := &Operand{
+ Meta: []ast.DataType{ast.ComposeDataType(ast.DataTypeMajorUint, 7)},
+ Data: []Tuple{},
+ }
+ result.Data = make([]Tuple, len(numbers))
+ for i, n := range numbers {
+ result.Data[i] = []*Raw{
+ {
+ Value: decimal.NewFromBigInt(new(big.Int).SetUint64(n), 0),
+ Bytes: nil,
+ },
+ }
+ }
+ return result, nil
+}
+
+func opRepeatPK(ctx *common.Context, input []*Operand, registers []*Operand, output int) (err error) {
+ tableRef, err := input[0].toTableRef()
+ if err != nil {
+ return err
+ }
+ IDs := ctx.Storage.RepeatPK(ctx.Contract.Address(), tableRef)
+ registers[output], err = uint64ToOperands(IDs)
+ return
+}