aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMeng-Ying Yang <garfield@dexon.org>2019-02-25 10:46:36 +0800
committerMeng-Ying Yang <garfield@dexon.org>2019-02-25 14:22:44 +0800
commitb1825474db21fdc3d25c07fccacf992c228625e5 (patch)
tree7873050a64358467063fea9b52a31e224f21d0b3
parent02a123eb2cb23cdff9a702d3049bb493068442f3 (diff)
downloaddexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar.gz
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar.bz2
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar.lz
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar.xz
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.tar.zst
dexon-b1825474db21fdc3d25c07fccacf992c228625e5.zip
core: vm: sqlvm: runtime entrypoing error handling
Return error.Error to reveal more information about returned error.
-rw-r--r--core/vm/sqlvm/errors/errors.go2
-rw-r--r--core/vm/sqlvm/runtime/instructions.go7
-rw-r--r--core/vm/sqlvm/runtime/runtime.go10
3 files changed, 14 insertions, 5 deletions
diff --git a/core/vm/sqlvm/errors/errors.go b/core/vm/sqlvm/errors/errors.go
index f6b91ebae..6062ae5d9 100644
--- a/core/vm/sqlvm/errors/errors.go
+++ b/core/vm/sqlvm/errors/errors.go
@@ -63,11 +63,13 @@ const (
ErrorCategorNil ErrorCategory = iota
ErrorCategoryGrammar
ErrorCategorySemantic
+ ErrorCategoryRuntime
)
var errorCategoryMap = [...]string{
ErrorCategoryGrammar: "grammar",
ErrorCategorySemantic: "semantic",
+ ErrorCategoryRuntime: "runtime",
}
func (c ErrorCategory) Error() string {
diff --git a/core/vm/sqlvm/runtime/instructions.go b/core/vm/sqlvm/runtime/instructions.go
index b5d98f956..9ecc41231 100644
--- a/core/vm/sqlvm/runtime/instructions.go
+++ b/core/vm/sqlvm/runtime/instructions.go
@@ -18,9 +18,10 @@ type OpFunction func(ctx *common.Context, ops []*Operand, registers []*Operand,
// Instruction represents single instruction with essential information
// collection.
type Instruction struct {
- Op OpCode
- Input []*Operand
- Output int
+ Op OpCode
+ Input []*Operand
+ Output int
+ Position uint32 // ast tree position
}
// Raw with embedded big.Int value or byte slice which represents the real value
diff --git a/core/vm/sqlvm/runtime/runtime.go b/core/vm/sqlvm/runtime/runtime.go
index 3ea12f119..a8f8db7ee 100644
--- a/core/vm/sqlvm/runtime/runtime.go
+++ b/core/vm/sqlvm/runtime/runtime.go
@@ -3,14 +3,20 @@ package runtime
import (
"github.com/dexon-foundation/dexon/core/vm"
"github.com/dexon-foundation/dexon/core/vm/sqlvm/common"
+ "github.com/dexon-foundation/dexon/core/vm/sqlvm/errors"
)
// Run is runtime entrypoint.
func Run(stateDB vm.StateDB, ins []Instruction, registers []*Operand) (ret []byte, err error) {
for _, in := range ins {
opFunc := jumpTable[in.Op]
- err = opFunc(&common.Context{}, in.Input, registers, in.Output)
- if err != nil {
+ errCode := opFunc(&common.Context{}, in.Input, registers, in.Output)
+ if errCode != nil {
+ err = errors.Error{
+ Position: in.Position,
+ Code: errCode.(errors.ErrorCode),
+ Category: errors.ErrorCategoryRuntime,
+ }
return nil, err
}
}