Documentation ¶
Index ¶
- Constants
- Variables
- func CalcChecksum(input []byte) uint64
- func CallContract(rt *Runtime, state uint32, name string, params *compiler.Map) (any, error)
- func CompileEval(vm *VM, src string, prefix uint32) error
- func ContractBaseCost(cb *compiler.CodeBlock) int64
- func ExecContract(rt *Runtime, name, fields string, params ...any) (any, error)
- func GetContractById(vm *VM, id int32) *compiler.ContractInfo
- func GetSettings(rt *Runtime, cntname, name string) (any, error)
- func MemoryUsage(rt *Runtime) int64
- func ObjectExists(vm *VM, name string, state uint32) bool
- func ParseName(in string) (id int64, name string)
- func ReleaseSmartVMObjects()
- func RollbackSmartVMObjects()
- func Run(vm *VM, block *compiler.CodeBlock, extend map[string]any) (ret []any, err error)
- func RunContractById(vm *VM, id int32, methods []string, extend map[string]any) error
- func RunContractByName(vm *VM, name string, methods []string, extend map[string]any) error
- func SavepointSmartVMObjects()
- func StrToInt64(s string) int64
- func ValueToDecimal(v any) (ret decimal.Decimal, err error)
- func ValueToFloat(v any) (ret float64, err error)
- func ValueToInt(v any) (ret int64, err error)
- type ExtFuncErr
- type GlobalVm
- type Runtime
- func (rt *Runtime) CostRemain() int64
- func (rt *Runtime) CostUsed() int64
- func (rt *Runtime) Run(block *compiler.CodeBlock) (ret []any, err error)
- func (rt *Runtime) RunCode(block *compiler.CodeBlock) (status int, err error)
- func (rt *Runtime) SetCost(cost int64)
- func (rt *Runtime) SubCost(cost int64) error
- type Stack
- type Stacker
- type VM
- func (vm *VM) AppendPreVar(preVar []string) *VM
- func (vm *VM) Call(name string, extend map[string]any) (ret []any, err error)
- func (vm *VM) Compile(input []rune, conf *compiler.CompConfig) error
- func (vm *VM) CompileEval(input string, state uint32) error
- func (vm *VM) EvalIf(input string, state uint32, extend map[string]any) (bool, error)
- func (vm *VM) FlushBlock(root *compiler.CodeBlock)
- func (vm *VM) FlushExtern()
- func (vm *VM) MergeCompConfig(conf *compiler.CompConfig) *compiler.CompConfig
- func (vm *VM) SetExtendCost(ext func(string) int64) *VM
- func (vm *VM) SetFuncCallsDB(funcCallsDB map[string]struct{}) *VM
- type VMError
Constants ¶
const ( // 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 )
const ( ContractError = "Contract" JSONMarshallError = "JSONMarshall" ConversionError = "Conversion" VMErr = "VM" )
const ( ExtendParentContract = `parent_contract` // parent contract name ExtendOriginalContract = `original_contract` // original contract name ExtendThisContract = `this_contract` // current contract name ExtendTimeLimit = `time_limit` // time limit for contract execution ExtendGenBlock = `gen_block` // true then we check the time limit ExtendTxCost = `txcost` // maximum cost limit of the transaction ExtendStack = `stack` // name of the contract stack ExtendSc = `sc` // implements the Stacker interface of struct ExtendRt = `rt` // runtime of the contract ExtendResult = `result` // result of the contract )
const ( // ShiftContractId is the offset of identifiers ShiftContractId = 5000 // MaxArrayIndex is the maximum index of an array MaxArrayIndex = 1000000 // MaxMapCount is the maximum length of map MaxMapCount = 100000 // MaxCallDepth is the maximum call depth of functions MaxCallDepth = 1000 // MemoryLimit is the maximum memory limit of VM MemoryLimit = 128 << 20 // 128 MB )
const MaxErrLen = 150
MaxErrLen is the maximum length of error, over which it will be truncated.
const (
// TagOptional is the tag of the optional parameter in the contract.
TagOptional = "optional"
)
Variables ¶
var ( ErrMemoryLimit = errors.New("memory limit exceeded") ErrVMTimeLimit = errors.New(`time limit exceeded`) )
var ErrStackUnderFlow = errors.New("stack under flow")
ErrStackUnderFlow is an error that is returned when the stack is underflow.
Functions ¶
func CalcChecksum ¶
CalcChecksum is calculates checksum, returns crc64 sum.
func CallContract ¶
CallContract executes the name contract in the state with specified parameters.
func CompileEval ¶
CompileEval compiles the source code and loads the byte-code into the virtual machine.
func ContractBaseCost ¶
ContractBaseCost returns the base cost of the contract.
func ExecContract ¶
ExecContract runs the name contract where fields contains the list of parameters and params are the values of parameters.
func GetContractById ¶
func GetContractById(vm *VM, id int32) *compiler.ContractInfo
GetContractById returns the contract with the specified id.
func GetSettings ¶
GetSettings returns the value of the setting of the contract.
func MemoryUsage ¶
MemoryUsage returns the memory usage of the runtime.
func ObjectExists ¶
ObjectExists checks if the object with the specified name exists in the virtual machine.
func ParseName ¶
ParseName gets a state identifier and the name of the contract or table from the full name like @[id]name
func ReleaseSmartVMObjects ¶
func ReleaseSmartVMObjects()
func RollbackSmartVMObjects ¶
func RollbackSmartVMObjects()
func RunContractById ¶
RunContractById executes the contract with the specified id and methods.
func RunContractByName ¶
RunContractByName executes the contract with the specified name and methods.
func SavepointSmartVMObjects ¶
func SavepointSmartVMObjects()
func ValueToDecimal ¶
ValueToDecimal converts interface (string, float64, Decimal or int64) to Decimal
func ValueToFloat ¶
ValueToFloat converts interface (string, float64 or int64) to float64
func ValueToInt ¶
ValueToInt converts interface (string or int64) to int64
Types ¶
type ExtFuncErr ¶
ExtFuncErr represents error of external function
func (ExtFuncErr) Error ¶
func (e ExtFuncErr) Error() string
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is needed for the execution of the byte-code
func NewRuntime ¶
NewRuntime creates a new Runtime for the virtual machine
func (*Runtime) CostRemain ¶
CostRemain return the remain cost of the execution.
func (*Runtime) Run ¶
Run executes a block of code and returns the result and any error that occurred.
func (*Runtime) RunCode ¶
RunCode executes a block of code and returns the status and any error that occurred.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a stack that contains elements of any type.
func (*Stack) CheckDepth ¶
CheckDepth checks if the stack has at least min elements.
type VM ¶
type VM struct { *compiler.CodeBlock // a function returns the cost of executing an external golang function. ExtCost func(string) int64 // if the function is in the list, the first of result must be a int64 that the cost of executing. FuncCallsDB map[string]struct{} // extern mode of compilation. an inter flag indicating whether a contract is an external contract. // It is set to true when a VM is created. Contracts called are not displayed // when the code is compiled. In other words, it allows to call the contract code // determined in the future; Extern compiler.IgnoreLevel // id of the first contract in the VM. ShiftContract int64 // contains filtered or unexported fields }
VM is the main type of the virtual machine.
func (*VM) AppendPreVar ¶
AppendPreVar appends the predeclared variables to the virtual machine.
func (*VM) Call ¶
Call executes the name object with the specified params and extended variables and functions.
func (*VM) Compile ¶
func (vm *VM) Compile(input []rune, conf *compiler.CompConfig) error
Compile compiles a source code and loads the byte-code into the virtual machine.
func (*VM) CompileEval ¶
CompileEval compiles the source code and stores it in the evals map.
func (*VM) EvalIf ¶
EvalIf runs the conditional expression. It compiles the source code before that if that's necessary.
func (*VM) FlushBlock ¶
FlushBlock loads the compiled CodeBlock into the virtual machine.
func (*VM) FlushExtern ¶
func (vm *VM) FlushExtern()
FlushExtern switches off the extern mode of the compilation.
func (*VM) MergeCompConfig ¶
func (vm *VM) MergeCompConfig(conf *compiler.CompConfig) *compiler.CompConfig
MergeCompConfig merges the virtual machine configuration with the compiler configuration.
func (*VM) SetExtendCost ¶
SetExtendCost sets the cost of calling extended obj in vm.
func (*VM) SetFuncCallsDB ¶
SetFuncCallsDB Set up functions that can edit the database in vm.