script

package
v0.0.0-...-b7062c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2017 License: LGPL-3.0-or-later Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (

	// Decimal is the constant string for decimal type
	Decimal = `decimal.Decimal`
	// Interface is the constant string for interface type
	Interface = `interface`
)
View Source
const (

	// ObjUnknown is an unknown object. It means something wrong.
	ObjUnknown = iota
	// ObjContract is a contract object.
	ObjContract
	// ObjFunc is a function object. myfunc()
	ObjFunc
	// ObjExtFunc is an extended function object. $myfunc()
	ObjExtFunc
	// ObjVar is a variable. myvar
	ObjVar
	// ObjExtend is an extended variable. $myvar
	ObjExtend

	// CostCall is the cost of the function calling
	CostCall = 50
	// CostContract is the cost of the contract calling
	CostContract = 100
	// CostExtend is the cost of the extend function calling
	CostExtend = 10
	// CostDefault is the default maximum cost of F
	CostDefault = int64(10000000)
)

Variables

This section is empty.

Functions

func ExContract

func ExContract(rt *RunTime, state uint32, name string, params map[string]interface{}) error

ExContract executes the name contract in the state with spoecified parameters

func ExecContract

func ExecContract(rt *RunTime, name, txs string, params ...interface{}) error

ExecContract runs the name contract where txs contains the list of parameters and params are the values of parameters

func ParseContract

func ParseContract(in string) (id uint64, name string)

ParseContract gets a state identifier and the name of the contract from the full name like @[id]name

func StateName

func StateName(state uint32, name string) string

StateName checks the name of the contract and modifies it to @[state]name if it is necessary.

func ValueToDecimal

func ValueToDecimal(v interface{}) (ret decimal.Decimal)

ValueToDecimal converts interface (string, float64, Decimal or int64) to Decimal

func ValueToFloat

func ValueToFloat(v interface{}) (ret float64)

ValueToFloat converts interface (string, float64 or int64) to float64

func ValueToInt

func ValueToInt(v interface{}) (ret int64)

ValueToInt converts interface (string or int64) to int64

Types

type Block

type Block struct {
	Objects  map[string]*ObjInfo
	Type     int
	Active   bool
	TableID  int64
	Info     interface{}
	Parent   *Block
	Vars     []reflect.Type
	Code     ByteCodes
	Children Blocks
}

Block contains all information about compiled block {...} and its children

type Blocks

type Blocks []*Block

Blocks is a slice of blocks

type ByteCode

type ByteCode struct {
	Cmd   uint16
	Value interface{}
}

ByteCode stores a command and an additional parameter.

type ByteCodes

type ByteCodes []*ByteCode

ByteCodes is the slice of ByteCode items

type ContractInfo

type ContractInfo struct {
	ID      uint32
	Name    string
	Active  bool
	TableID int64
	Used    map[string]bool // Called contracts
	Tx      *[]*FieldInfo
}

ContractInfo contains the contract information

type ExtFuncInfo

type ExtFuncInfo struct {
	Name     string
	Params   []reflect.Type
	Results  []reflect.Type
	Auto     []string
	Variadic bool
	Func     interface{}
}

ExtFuncInfo is the structure for the extrended function

type ExtendData

type ExtendData struct {
	Objects  map[string]interface{}
	AutoPars map[string]string
}

ExtendData is used for the definition of the extended functions and variables

type FieldInfo

type FieldInfo struct {
	Name string
	Type reflect.Type
	Tags string
}

FieldInfo describes the field of the data structure

type FuncInfo

type FuncInfo struct {
	Params   []reflect.Type
	Results  []reflect.Type
	Variadic bool
}

FuncInfo contains the function information

type Lexem

type Lexem struct {
	Type   uint32      // Type of the lexem
	Value  interface{} // Value of lexem
	Line   uint32      // Line of the lexem
	Column uint32      // Position inside the line
}

Lexem contains information about language item

type Lexems

type Lexems []*Lexem

Lexems is a slice of lexems

type ObjInfo

type ObjInfo struct {
	Type  int
	Value interface{}
}

ObjInfo is the common object type

type RunTime

type RunTime struct {
	// contains filtered or unexported fields
}

RunTime is needed for the execution of the byte-code

func (*RunTime) Cost

func (rt *RunTime) Cost() int64

Cost return the remain cost of the execution.

func (*RunTime) Run

func (rt *RunTime) Run(block *Block, params []interface{}, extend *map[string]interface{}) (ret []interface{}, err error)

Run executes Block with the specified parameters and extended variables and functions

func (*RunTime) RunCode

func (rt *RunTime) RunCode(block *Block) (status int, err error)

RunCode executes Block

func (*RunTime) SetCost

func (rt *RunTime) SetCost(cost int64)

SetCost sets the max cost of the execution.

type VM

type VM struct {
	Block
	ExtCost func(string) int64
	Extern  bool // extern mode of compilation
}

VM is the main type of the virtual machine

func NewVM

func NewVM() *VM

NewVM creates a new virtual machine

func (*VM) Call

func (vm *VM) Call(name string, params []interface{}, extend *map[string]interface{}) (ret []interface{}, err error)

Call executes the name object with the specified params and extended variables and functions

func (*VM) Compile

func (vm *VM) Compile(input []rune, state uint32, active bool, tblid int64) error

Compile compiles a source code and loads the byte-code into the virtual machine

func (*VM) CompileBlock

func (vm *VM) CompileBlock(input []rune, idstate uint32, active bool, tblid int64) (*Block, error)

CompileBlock compile the source code into the Block structure with a byte-code

func (*VM) CompileEval

func (vm *VM) CompileEval(input string, state uint32) error

CompileEval compiles conditional exppression

func (*VM) EvalIf

func (vm *VM) EvalIf(input string, state uint32, vars *map[string]interface{}) (bool, error)

EvalIf runs the conditional expression. It compiles the source code before that if that's necessary.

func (*VM) Extend

func (vm *VM) Extend(ext *ExtendData)

Extend sets the extended variables and functions

func (*VM) FlushBlock

func (vm *VM) FlushBlock(root *Block)

FlushBlock loads the compiled Block into the virtual machine

func (*VM) FlushExtern

func (vm *VM) FlushExtern()

FlushExtern switches off the extern mode of the compilation

func (*VM) RunInit

func (vm *VM) RunInit(cost int64) *RunTime

RunInit creates a new RunTime for the virtual machine

type VarInfo

type VarInfo struct {
	Obj   *ObjInfo
	Owner *Block
}

VarInfo contains the variable information

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL