yakvm

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

README

Yak Virtual Machine

字节码定义:Opcode Definition

助记符(Opcode Verbose) Unary Op1 Op2 补充描述
type-cast - - - 类型转换:从栈中取出两个值,第一个值为类型,第二个值为具体需要转换的值,进行类型转换,并把结果推入栈中
bang - - - 单目运算符:!,从栈中取出一个值,进行计算,把结果再推入栈
neg - - - 单目运算符:-,从栈中取出一个值,进行计算,把结果再推入栈
plus - - - 单目运算符:+,从栈中取出一个值,进行计算,把结果再推入栈
chan-recv - - - 单目运算符:<-,从栈中取出一个 channel,读取 channel 的结果,把结果再推入栈
self-add-one - - - 自增赋值:栈中取出一个值,进行自增,把结果压栈
self-minus-one - - - 自增赋值:栈中取出一个值,进行自减,把结果压栈
shl - - - 双目位运算符:<<,从栈中取出两个值,进行计算,把结果再压入栈
shr - - - 双目位运算符:>>,从栈中取出两个值,进行计算,把结果再压入栈
and - - - 双目位运算符:&,从栈中取出两个值,进行计算,把结果再压入栈
and-not - - - 双目位运算符:&^,从栈中取出两个值,进行计算,把结果再压入栈
or - - - 双目位运算符:|,从栈中取出两个值,进行计算,把结果再压入栈
xor - - - 双目位运算符:^,从栈中取出两个值,进行计算,把结果再压入栈
add - - - 双目运算符:+,从栈中取出两个值,进行相加,把结果再压入栈
sub - - - 双目运算符:-,从栈中取出两个值,进行相减,把结果再压入栈
mul - - - 双目运算符:*,从栈中取出两个值,进行计算(乘),把结果再压入栈
div - - - 双目运算符:/,从栈中取出两个值,进行计算(除),把结果再压入栈
mod - - - 双目运算符:%,从栈中取出两个值,进行计算(取模),把结果再压入栈
gt - - - 双目逻辑运算符:>,从栈中取出两个值,进行计算(大于),把结果再压入栈
lt - - - 双目逻辑运算符:<,从栈中取出两个值,进行计算(大于),把结果再压入栈
gt-eq - - - 双目逻辑运算符:>=,从栈中取出两个值,进行计算(大于等于),把结果再压入栈
lt-eq - - - 双目逻辑运算符:<=,从栈中取出两个值,进行计算(小于等于),把结果再压入栈
eq - - - 双目逻辑运算符:==,从栈中取出两个值,进行计算(是否相等),把结果再压入栈
neq - - - 双目逻辑运算符:!=,从栈中取出两个值,进行计算(是否不等),把结果再压入栈
self-plus-eq - - - 赋值运算符:+=,从栈中取出两个值,进行计算(相加),把结果赋值到第一位值中(左)
self-minus-eq - - - 赋值运算符:-=,从栈中取出两个值,进行计算(相减),把结果赋值到第一位值中(左)
self-mul-eq - - - 赋值运算符:*=,从栈中取出两个值,进行计算(乘),把结果赋值到第一位值中(左)
self-div-eq - - - 赋值运算符:/=,从栈中取出两个值,进行计算(除),把结果赋值到第一位值中(左)
self-mod-eq - - - 赋值运算符:%=,从栈中取出两个值,进行计算(模),把结果赋值到第一位值中(左)
self-and-eq - - - 赋值运算符:&=,从栈中取出两个值,进行计算(位与),把结果赋值到第一位值中(左)
self-or-eq - - - 赋值运算符:|=,从栈中取出两个值,进行计算(位或),把结果赋值到第一位值中(左)
self-xor-eq - - - 赋值运算符:^=,从栈中取出两个值,进行计算(位异或),把结果赋值到第一位值中(左)
self-shl-eq - - - 赋值运算符:<<=,从栈中取出两个值,进行计算(位左移),把结果赋值到第一位值中(左)
self-shr-eq - - - 赋值运算符:>>=,从栈中取出两个值,进行计算(位右移),把结果赋值到第一位值中(左)
self-and-not-eq - - - 赋值运算符:&^=,从栈中取出两个值,进行计算(相加),把结果赋值到第一位值中(左)
in - - - 双目运算符:in 判断元素是否是包含关系,栈中取两个值,结果压栈
chan-send - - - 双目运算符,为一个 channel 写入数据
type - - - 从栈中取出两个值,必须为类型,为这两个值构建相应的数据类型
make 参数数量 - - 从栈中取出若干个值,创建一个的新的值压入栈,取出 uanry 个参数,根据类型构建新值
push - 直接压栈的值 - 基础压栈操作
pushf - 压栈原值 - 把 Op1 的值,进行 fuzztag 运算,并把结果压如栈(Slice)
range-next - - - 触发 Forange 的下一次循环计数
in-next - - - 触发 Forin 的下一次循环计数
enter-for-range 循环次数 - - 进入 ForEach 循环模式
exit-for-range - - - 退出 ForEach 循环模式,判断当前计数栈中值是否大于0,如果不大于零直接退出,否则计数-1
list 合并值数量 - - 合并栈中的值的数量
assign - - - 从栈中取两个值,进行赋值操作
fast-assign - - - 快速复制,从栈中取一个左值,一个右值,为左值赋值,同时把赋值之后的左值压入栈
pushr 符号 - - 栈中压入一个符号对应的值
pushleftr 符号左值 - - 栈中压入符号左值
jmp 跳转位置 - - 无条件跳转到 Unary
jmpt 跳转位置 - - 出栈一个值,为 true 时跳转到 uanry
jmpf 跳转位置 - - 出栈一个值,为 false 时跳转到 uanry
jmpt-or-pop 跳转位置 - - 查看栈一个值,为 true 时跳转到 uanry,否则出栈
jmpf-or-pop 跳转位置 - - 查看栈一个值,为 false 时跳转到 uanry,否则出栈
break 跳转位置 - - -
continue 跳转位置 - - -
call 参数数量 - - 出栈 unary,出栈函数,进行调用
callvar 参数数量 - - 出栈 unary,出栈函数,进行调用(可变参数模式)
pushid - 无符号的变量名 - 把一个无符号的变量名引入程序中,这个变量名可通过外部注入虚拟机
pop - - - 普通出栈
newmap map 大小 - - 这个指令用于创建一个 map,从栈中取出 unary * 2 个数据,然后俩俩组合,左边为 key 右边为 value
newslice 大小 - - 用于从栈中创建 Slice,取出 unary 个数据,推断类型,然后组合成 slice
typedslice 构建类型限定的 slice 大小 - - 从栈中创建 Slice,取出 unary 个操作数,再取出 Type,组合成 Slice
iterablecall - - - 调用 Silce 的索引部分
return - - - 函数返回值
defer - - - 设定一组字节码在当前虚拟机结束的时候调用!
assert - 错误信息 - 出栈,判定栈中值是否为 true,否则 op1 作为错误信息
membercall - - - 出栈两个参数,第一个为 map 或结构体,获取map或结构体的成员变量或方法
async-call - - - 异步调用,基本同 call,但是是异步调用的
new-scope 符号表编号 - - 新建一个定义域
end-scope - - - 结束当前激活的定义域
include - - - 包含一个文件,并执行
panic - - - 主动触发程序崩溃
recover - - - 让程序从崩溃中恢复,把恢复的 panic 推入栈中
ellipsis - - - 函数参数是不确定的时候,可以用 ellipsis 拆包

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IdtoSymbolTable = new(sync.Map)
View Source
var OpcodeVerboseName = map[OpcodeFlag]string{
	OpBitwiseNot: `not`,
	OpAnd:        `and`,
	OpAndNot:     `and-not`,
	OpOr:         `or`,
	OpXor:        `xor`,
	OpShl:        `shl`,
	OpShr:        `shr`,
	OpTypeCast:   `type-cast`,
	OpPlusPlus:   `self-add-one`,
	OpMinusMinus: `self-minus-one`,
	OpNot:        `bang`,
	OpNeg:        `neg`,
	OpPlus:       `plus`,
	OpChan:       `chan-recv`,
	OpAdd:        `add`,
	OpSub:        `sub`,
	OpMod:        `mod`,
	OpMul:        `mul`,
	OpDiv:        `div`,
	OpGt:         `gt`,
	OpLt:         `lt`,
	OpLtEq:       `lt-eq`,
	OpGtEq:       `gt-eq`,
	OpNotEq:      `neq`,
	OpEq:         `eq`,
	OpPlusEq:     `self-plus-eq`,
	OpMinusEq:    `self-minus-eq`,
	OpMulEq:      `self-mul-eq`,
	OpDivEq:      `self-div-eq`,
	OpModEq:      `self-mod-eq`,
	OpAndEq:      `self-and-eq`,
	OpOrEq:       `self-or-eq`,
	OpXorEq:      `self-xor-eq`,
	OpShlEq:      `self-shl-eq`,
	OpShrEq:      `self-shr-eq`,
	OpAndNotEq:   `self-and-not-eq`,

	OpIn:       `in`,
	OpSendChan: `chan-send`,

	OpRangeNext: `range-next`,
	OpInNext:    `in-next`,
	OpEnterFR:   `enter-for-range`,
	OpExitFR:    `exit-for-range`,

	OpType:        `type`,
	OpMake:        `make`,
	OpPush:        `push`,
	OpList:        `list`,
	OpAssign:      `assign`,
	OpFastAssign:  `fast-assign`,
	OpPushRef:     `pushr`,
	OpPushLeftRef: `pushleftr`,
	OpJMP:         `jmp`,
	OpJMPT:        `jmpt`,
	OpJMPF:        `jmpf`,
	OpJMPTOP:      `jmpt-or-pop`,
	OpJMPFOP:      `jmpf-or-pop`,

	OpCall:             `call`,
	OpVariadicCall:     `callvar`,
	OpPushId:           `pushid`,
	OpPop:              `pop`,
	OpPushfuzz:         `pushf`,
	OpNewMap:           `newmap`,
	OpNewMapWithType:   `typedmap`,
	OpNewSlice:         `newslice`,
	OpNewSliceWithType: `typedslice`,
	OpIterableCall:     `iterablecall`,
	OpReturn:           `return`,
	OpAssert:           `assert`,
	OpDefer:            `defer`,
	OpMemberCall:       `membercall`,
	OpBreak:            `break`,
	OpContinue:         `continue`,
	OpAsyncCall:        "async-call",

	OpScope:    `new-scope`,
	OpScopeEnd: `end-scope`,

	OpInclude: `include`,

	OpRecover:  `recover`,
	OpPanic:    `panic`,
	OpEllipsis: `ellipsis`,

	OpCatchError:     `catch-error`,
	OpStopCatchError: `stop-catch-error`,
	OpExit:           `exit`,
}

Functions

func GetBytesBuildInMethod added in v1.2.9

func GetBytesBuildInMethod() map[string]*buildinMethod

func GetCodeNumber added in v1.2.6

func GetCodeNumber(code *Code) (int, int, int, int)

func GetIndexedVariableCount added in v1.2.6

func GetIndexedVariableCount(v interface{}) int

func GetMapBuildInMethod

func GetMapBuildInMethod() map[string]*buildinMethod

func GetNamedVariableCount added in v1.2.6

func GetNamedVariableCount(v interface{}) int

func GetSliceBuildInMethod

func GetSliceBuildInMethod() map[string]*buildinMethod

func GetStringBuildInMethod

func GetStringBuildInMethod() map[string]*buildinMethod

var _title = http.CanonicalHeaderKey

func GuessBasicType

func GuessBasicType(vals ...interface{}) reflect.Type

func GuessValuesKindToBasicType

func GuessValuesKindToBasicType(vals ...*Value) reflect.Kind
func ImplicitTypeConversionForPlus(vals ...*Value) reflect.Type {
	resultType := GuessValuesTypeToBasicType(vals...)
	if resultType.Kind() == literalReflectType_Interface.Kind() {
		isString := true
		for _, val := range vals {
			if !val.IsString() && !val.IsInt() {
				isString = false
				break
			}
		}
		if isString {
			resultType = literalReflectType_String
		}
	}
	return resultType
}

func GuessValuesTypeToBasicType

func GuessValuesTypeToBasicType(vals ...*Value) reflect.Type

func ImportBinaryOperator

func ImportBinaryOperator(vmType YVMMode, flag OpcodeFlag, handler func(*Value, *Value) *Value)

func ImportLuaBinaryOperator added in v1.2.3

func ImportLuaBinaryOperator(flag OpcodeFlag, handler func(*Value, *Value) *Value)

lua

func ImportLuaUnaryOperator added in v1.2.3

func ImportLuaUnaryOperator(flag OpcodeFlag, handler func(*Value) *Value)

func ImportNaslBinaryOperator added in v1.2.3

func ImportNaslBinaryOperator(flag OpcodeFlag, handler func(*Value, *Value) *Value)

nasl

func ImportNaslUnaryOperator added in v1.2.3

func ImportNaslUnaryOperator(flag OpcodeFlag, handler func(*Value) *Value)

func ImportRuntimeLib added in v1.2.8

func ImportRuntimeLib(frame *Frame)

func ImportUnaryOperator

func ImportUnaryOperator(vmType YVMMode, flag OpcodeFlag, handler func(*Value) *Value)

func ImportYakBinaryOperator added in v1.2.3

func ImportYakBinaryOperator(flag OpcodeFlag, handler func(*Value, *Value) *Value)

yak

func ImportYakUnaryOperator added in v1.2.3

func ImportYakUnaryOperator(flag OpcodeFlag, handler func(*Value) *Value)

func IsBytesOrRunes added in v1.2.6

func IsBytesOrRunes(v interface{}) bool

func IsFloat

func IsFloat(v interface{}) bool

func IsInt

func IsInt(v interface{}) bool

关于类型的描述,我们通过一些简单的方式可以保证

  1. 在 golang => yak 的时候,清理到不好的类型,比如 uint 与 float32,其他的类型均是可以接受的 但是因为有限的情况下,int64 和 int 是可以接受的,但是再大就有点小问题了(需要注意的是,一般 x64 系统中,int64 和 int 是一样的)
  2. 所以在计算过程中 yak => golang 的过程中,我们不希望调用到任何 uint 类型的东西

func IsUndefined

func IsUndefined(v *Value) bool

func IsVMPanic added in v1.2.6

func IsVMPanic(err error) bool

func LuaVMValuesToFunctionMap

func LuaVMValuesToFunctionMap(f *Function, vs []*Value) map[int]*Value

func NewSwitchBundle added in v1.2.6

func NewSwitchBundle() *switchBundle

func OpcodeToName

func OpcodeToName(op OpcodeFlag) string

func OpcodesString

func OpcodesString(c []*Code) string

func ShowOpcodes

func ShowOpcodes(c []*Code)

func ShowOpcodesWithSource added in v1.2.3

func ShowOpcodesWithSource(src string, c []*Code)

func YakVMValuesToFunctionMap

func YakVMValuesToFunctionMap(f *Function, vs []*Value, argumentCheck bool) map[int]*Value

Types

type BaseIterator

type BaseIterator struct {
	Current, N int
	// contains filtered or unexported fields
}

func (*BaseIterator) IsEnd

func (i *BaseIterator) IsEnd() bool

func (*BaseIterator) Next

func (i *BaseIterator) Next() (data []interface{}, hadEnd bool)

func (*BaseIterator) Type

func (i *BaseIterator) Type() IteratorType

type BreakPointFactoryFun

type BreakPointFactoryFun func(v *VirtualMachine) bool

type Breakpoint

type Breakpoint struct {
	ID                      int
	On                      bool
	CodeIndex, LineIndex    int
	Condition, HitCondition string
	State                   string

	HitCount int // 命中次数
}

func (*Breakpoint) Disable

func (bp *Breakpoint) Disable()

func (*Breakpoint) Enable

func (bp *Breakpoint) Enable()

type BreakpointMap added in v1.2.6

type BreakpointMap = map[int]*Breakpoint

type ChannelIterator

type ChannelIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

func (*ChannelIterator) Next

func (i *ChannelIterator) Next() (data []interface{}, hadEnd bool)

type Code

type Code struct {
	Opcode OpcodeFlag

	Unary int
	Op1   *Value
	Op2   *Value

	// 记录 Opcode 的位置
	SourceCodeFilePath *string
	SourceCodePointer  *string
	StartLineNumber    int
	StartColumnNumber  int
	EndLineNumber      int
	EndColumnNumber    int
}

func (*Code) Dump

func (c *Code) Dump()

func (*Code) GetJmpIndex

func (c *Code) GetJmpIndex() int

func (*Code) IsJmp

func (c *Code) IsJmp() bool

func (*Code) RangeVerbose

func (c *Code) RangeVerbose() string

func (*Code) String

func (c *Code) String() string

type CodeState

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

func NewCodeState

func NewCodeState(codeIndex int, state string) *CodeState

type CodesMarshaller

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

func NewCodesMarshaller

func NewCodesMarshaller() *CodesMarshaller

func (*CodesMarshaller) Marshal

func (c *CodesMarshaller) Marshal(tbl *SymbolTable, codes []*Code) ([]byte, error)

func (*CodesMarshaller) MarshalWithDebugInfo

func (c *CodesMarshaller) MarshalWithDebugInfo(tbl *SymbolTable, codes []*Code) ([]byte, error)

func (*CodesMarshaller) SetSourceCode added in v1.2.3

func (c *CodesMarshaller) SetSourceCode(s string)

func (*CodesMarshaller) Unmarshal

func (c *CodesMarshaller) Unmarshal(buf []byte) (*SymbolTable, []*Code, error)

type CompilerWrapperInterface

type CompilerWrapperInterface interface {
	NewWithSymbolTable(*SymbolTable) CompilerWrapperInterface
	Compiler(code string) bool
	GetNormalErrors() (bool, error)
	GetOpcodes() []*Code
}
var (
	// 由yakast包注入
	YakDebugCompiler CompilerWrapperInterface
)

type Coroutine added in v1.3.0

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

func NewCoroutine added in v1.3.0

func NewCoroutine() *Coroutine

type Debugger

type Debugger struct {

	// 堆栈跟踪
	StackTraces      map[int]*vmstack.Stack // threadID -> stacktraces
	ThreadStackTrace map[int]*DebuggerState // 每个线程对应的当前的stackTrace

	// Reference,用于存储帧,作用域,变量引用的信息
	Reference *Reference
	// contains filtered or unexported fields
}

func NewDebugger

func NewDebugger(vm *VirtualMachine, sourceCode string, codes []*Code, init, callback func(*Debugger)) *Debugger

func (*Debugger) Add

func (g *Debugger) Add()

func (*Debugger) AddBreakPointRef added in v1.2.6

func (g *Debugger) AddBreakPointRef(b *Breakpoint) int

func (*Debugger) AddFrameRef added in v1.2.6

func (g *Debugger) AddFrameRef(frame *Frame) int

func (*Debugger) AddObserveBreakPoint

func (g *Debugger) AddObserveBreakPoint(expr string) error

func (*Debugger) AddObserveExpression

func (g *Debugger) AddObserveExpression(expr string) error

func (*Debugger) AddScopeRef added in v1.2.6

func (g *Debugger) AddScopeRef(scope *Scope) int

func (*Debugger) AddVariableRef added in v1.2.6

func (g *Debugger) AddVariableRef(v interface{}) int

func (*Debugger) Breakpoints

func (g *Debugger) Breakpoints() map[int]*Breakpoint

func (*Debugger) Callback

func (g *Debugger) Callback()

func (*Debugger) ClearAllBreakPoints

func (g *Debugger) ClearAllBreakPoints()

func (*Debugger) ClearBreakpointsInLine

func (g *Debugger) ClearBreakpointsInLine(lineIndex int)

func (*Debugger) ClearOtherBreakpointsWithSource added in v1.2.6

func (g *Debugger) ClearOtherBreakpointsWithSource(path string, existLines []int)

func (*Debugger) Codes

func (g *Debugger) Codes() []*Code

func (*Debugger) CodesInState added in v1.2.4

func (g *Debugger) CodesInState(state string) []*Code

func (*Debugger) Compile

func (g *Debugger) Compile(code string) (*Frame, CompilerWrapperInterface, error)

func (*Debugger) CompileWithFrame added in v1.2.6

func (g *Debugger) CompileWithFrame(code string, frame *Frame) (*Frame, CompilerWrapperInterface, error)

func (*Debugger) CompileWithFrameID added in v1.2.6

func (g *Debugger) CompileWithFrameID(code string, frameID int) (*Frame, CompilerWrapperInterface, error)

func (*Debugger) CurrentCodeIndex

func (g *Debugger) CurrentCodeIndex() int

func (*Debugger) CurrentFrameID added in v1.2.6

func (g *Debugger) CurrentFrameID() int

func (*Debugger) CurrentLine

func (g *Debugger) CurrentLine() int

func (*Debugger) CurrentStackTrace added in v1.2.6

func (g *Debugger) CurrentStackTrace() *vmstack.Stack

func (*Debugger) CurrentStackTracePop added in v1.2.6

func (g *Debugger) CurrentStackTracePop()

func (*Debugger) CurrentThreadID added in v1.2.6

func (g *Debugger) CurrentThreadID() int

func (*Debugger) Description

func (g *Debugger) Description() string

func (*Debugger) DisableAllBreakPoints

func (g *Debugger) DisableAllBreakPoints()

func (*Debugger) DisableBreakpointsInLine

func (g *Debugger) DisableBreakpointsInLine(lineIndex int)

func (*Debugger) EnableAllBreakPoints

func (g *Debugger) EnableAllBreakPoints()

func (*Debugger) EnableBreakpointsInLine

func (g *Debugger) EnableBreakpointsInLine(lineIndex int)

func (*Debugger) EvalExpression

func (g *Debugger) EvalExpression(expr string) (*Value, error)

func (*Debugger) EvalExpressionWithFrameID added in v1.2.6

func (g *Debugger) EvalExpressionWithFrameID(expr string, frameID int) (*Value, error)

func (*Debugger) ExistBreakPointInLineWithSource added in v1.2.6

func (g *Debugger) ExistBreakPointInLineWithSource(path string, lineIndex int) (*Breakpoint, bool)

func (*Debugger) Finished

func (g *Debugger) Finished() bool

func (*Debugger) ForceSetVariableRef added in v1.2.6

func (g *Debugger) ForceSetVariableRef(id int, v interface{})

func (*Debugger) Frame added in v1.2.4

func (g *Debugger) Frame() *Frame

func (*Debugger) GetAllObserveBreakPoint added in v1.2.6

func (g *Debugger) GetAllObserveBreakPoint() map[string]*Value

func (*Debugger) GetAllObserveExpressions

func (g *Debugger) GetAllObserveExpressions() map[string]*Value

func (*Debugger) GetCode

func (g *Debugger) GetCode(state string, codeIndex int) *Code

func (*Debugger) GetLineFirstCode

func (g *Debugger) GetLineFirstCode(lineIndex int) (*Code, int, string)

func (*Debugger) GetScopesByFrameID added in v1.2.6

func (g *Debugger) GetScopesByFrameID(frameID int) map[int]*Scope

func (*Debugger) GetStackTraces added in v1.2.6

func (g *Debugger) GetStackTraces() map[int]*StackTraces

func (*Debugger) GetVariablesByRef added in v1.2.6

func (g *Debugger) GetVariablesByRef(ref int) (interface{}, bool)

func (*Debugger) GetVariablesRef added in v1.2.6

func (g *Debugger) GetVariablesRef(v interface{}) (int, bool)

func (*Debugger) HandleForBreakPoint added in v1.2.6

func (g *Debugger) HandleForBreakPoint()

func (*Debugger) HandleForNormallyFinished added in v1.2.6

func (g *Debugger) HandleForNormallyFinished()

func (*Debugger) HandleForPanic added in v1.2.6

func (g *Debugger) HandleForPanic(vmPanic *VMPanic)

func (*Debugger) HandleForPause added in v1.2.6

func (g *Debugger) HandleForPause()

func (*Debugger) HandleForStepIn

func (g *Debugger) HandleForStepIn()

func (*Debugger) HandleForStepNext

func (g *Debugger) HandleForStepNext()

func (*Debugger) HandleForStepOut

func (g *Debugger) HandleForStepOut()

func (*Debugger) HitCount added in v1.2.6

func (g *Debugger) HitCount(breakpoint *Breakpoint) bool

func (*Debugger) InRootState

func (g *Debugger) InRootState() bool

func (*Debugger) Init

func (g *Debugger) Init(codes []*Code)

func (*Debugger) InitCallBack

func (g *Debugger) InitCallBack()

func (*Debugger) InitCode added in v1.2.7

func (g *Debugger) InitCode(codes []*Code)

func (*Debugger) IsPause added in v1.2.6

func (g *Debugger) IsPause() bool

func (*Debugger) NewBreakPoint added in v1.2.6

func (g *Debugger) NewBreakPoint(codeIndex, lineIndex int, condition, hitCondition, state string) *Breakpoint

func (*Debugger) Pause added in v1.2.6

func (g *Debugger) Pause()

func (*Debugger) RemoveObserveBreakPoint

func (g *Debugger) RemoveObserveBreakPoint(expr string) error

func (*Debugger) RemoveObserveExpression

func (g *Debugger) RemoveObserveExpression(expr string) error

func (*Debugger) ResetDescription

func (g *Debugger) ResetDescription()

func (*Debugger) ResetStopReason added in v1.2.6

func (g *Debugger) ResetStopReason()

func (*Debugger) SetBreakPoint

func (g *Debugger) SetBreakPoint(lineIndex int, condition, hitCondition string) (int, error)

func (*Debugger) SetBreakPointWithSource added in v1.2.6

func (g *Debugger) SetBreakPointWithSource(path string, lineIndex int, condition, hitCondition string) (int, error)

func (*Debugger) SetDescription added in v1.2.6

func (g *Debugger) SetDescription(desc string)

func (*Debugger) SetFinished added in v1.2.6

func (g *Debugger) SetFinished()

func (*Debugger) SetNormalBreakPoint

func (g *Debugger) SetNormalBreakPoint(lineIndex int) (int, error)

func (*Debugger) SetStopReason added in v1.2.6

func (g *Debugger) SetStopReason(desc string)

func (*Debugger) SetVMPanic added in v1.2.6

func (g *Debugger) SetVMPanic(p *VMPanic)

func (*Debugger) ShouldCallback added in v1.2.6

func (g *Debugger) ShouldCallback(frame *Frame)

func (*Debugger) SourceCodeLines

func (g *Debugger) SourceCodeLines() []string

func (*Debugger) StartWGAdd added in v1.2.6

func (g *Debugger) StartWGAdd()

func (*Debugger) StartWGDone added in v1.2.6

func (g *Debugger) StartWGDone()

func (*Debugger) StartWGWait added in v1.2.6

func (g *Debugger) StartWGWait()

func (*Debugger) State

func (g *Debugger) State() string

func (*Debugger) StateName

func (g *Debugger) StateName() string

func (*Debugger) StepIn

func (g *Debugger) StepIn() error

func (*Debugger) StepNext

func (g *Debugger) StepNext() error

func (*Debugger) StepOut

func (g *Debugger) StepOut() error

func (*Debugger) StopReason added in v1.2.6

func (g *Debugger) StopReason() string

func (*Debugger) SwitchByOtherFileOpcode added in v1.2.6

func (g *Debugger) SwitchByOtherFileOpcode(code *Code)

func (*Debugger) UpdateByFrame added in v1.2.4

func (g *Debugger) UpdateByFrame(frame *Frame)

func (*Debugger) VM

func (g *Debugger) VM() *VirtualMachine

func (*Debugger) VMPanic added in v1.2.6

func (g *Debugger) VMPanic() *VMPanic

func (*Debugger) Wait

func (g *Debugger) Wait()

func (*Debugger) WaitGroupDone

func (g *Debugger) WaitGroupDone()

type DebuggerState added in v1.2.6

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

type Defer

type Defer struct {
	Codes []*Code
	Scope *Scope
}

type ExecFlag

type ExecFlag int
const (
	None   ExecFlag = 1 << iota // 默认创建新栈帧执行代码,执行后出栈
	Trace                       // 执行后不出站
	Sub                         // 使用栈顶的数据继续执行
	Inline                      // 使用上一次执行的Trace继续执行
	Asnyc                       // 异步执行
	Sandbox
)

func GetFlag

func GetFlag(flags ...ExecFlag) ExecFlag

type ExitCodeType

type ExitCodeType int
const (
	ErrorExit ExitCodeType = 1 << iota
	NormallyExit
	NoneExit
	TryExit
	ReturnExit
)

type Frame

type Frame struct {

	// 运算符的 Opcode
	BinaryOperatorTable map[OpcodeFlag]func(*Value, *Value) *Value
	UnaryOperatorTable  map[OpcodeFlag]func(*Value) *Value

	// yak函数, 内置函数,乃至变量聚集地
	GlobalVariables map[string]interface{}

	ThreadID int // 当前线程的ID
	// contains filtered or unexported fields
}

func NewFrame

func NewFrame(vm *VirtualMachine) *Frame

func NewSubFrame

func NewSubFrame(parent *Frame) *Frame

func (*Frame) AutoConvertReflectValueByType

func (v *Frame) AutoConvertReflectValueByType(
	reflectValue *reflect.Value,
	reflectType reflect.Type,
) error

func (*Frame) AutoConvertYakValueToNativeValue

func (v *Frame) AutoConvertYakValueToNativeValue(val *Value) (reflect.Value, error)

func (*Frame) CallLuaFunction

func (vm *Frame) CallLuaFunction(asyncCall bool, f *Function, vs []*Value) interface{}

func (*Frame) CallYakFunction

func (vm *Frame) CallYakFunction(asyncCall bool, f *Function, vs []*Value) interface{}

func (*Frame) CheckExit added in v1.2.7

func (v *Frame) CheckExit() error

func (*Frame) CreateAndSwitchSubScope

func (v *Frame) CreateAndSwitchSubScope(table *SymbolTable)

func (*Frame) CurrentCode

func (v *Frame) CurrentCode() *Code

func (*Frame) CurrentScope

func (v *Frame) CurrentScope() *Scope

func (*Frame) DebugExec

func (v *Frame) DebugExec(codes []*Code)

func (*Frame) EnableDebuggerEval

func (v *Frame) EnableDebuggerEval()

func (*Frame) Exec

func (v *Frame) Exec(codes []*Code)

func (*Frame) ExitScope

func (v *Frame) ExitScope()

func (*Frame) ExitScopeWithCount

func (v *Frame) ExitScopeWithCount(count int)

func (*Frame) GetCodes

func (v *Frame) GetCodes() []*Code

func (*Frame) GetContext

func (v *Frame) GetContext() context.Context

func (*Frame) GetFunction

func (v *Frame) GetFunction() *Function

func (*Frame) GetLastStackValue

func (v *Frame) GetLastStackValue() *Value

func (*Frame) GetVerbose

func (v *Frame) GetVerbose() string

func (*Frame) GetVirtualMachine

func (v *Frame) GetVirtualMachine() *VirtualMachine

func (*Frame) NewScope

func (v *Frame) NewScope(table *SymbolTable) *Scope

func (*Frame) NormalExec

func (v *Frame) NormalExec(codes []*Code)

func (*Frame) SetFunction

func (v *Frame) SetFunction(f *Function)

func (*Frame) SetOriginCode added in v1.2.3

func (v *Frame) SetOriginCode(s string)

func (*Frame) SetScope

func (v *Frame) SetScope(scope *Scope)

func (*Frame) SetVerbose

func (v *Frame) SetVerbose(s string)

type Function

type Function struct {
	FreeValue []int
	// contains filtered or unexported fields
}

func NewFunction

func NewFunction(codes []*Code, tbl *SymbolTable) *Function

func (*Function) Copy added in v1.2.4

func (f *Function) Copy(s *Scope) *Function

func (*Function) GetActualName

func (f *Function) GetActualName() string

func (*Function) GetBindName

func (f *Function) GetBindName() string

func (*Function) GetCodes

func (f *Function) GetCodes() []*Code

func (*Function) GetName

func (f *Function) GetName() string

func (*Function) GetNumIn added in v1.2.7

func (f *Function) GetNumIn() int

func (*Function) GetSymbolId

func (f *Function) GetSymbolId() int

func (*Function) GetUUID

func (f *Function) GetUUID() string

func (*Function) IsVariableParameter

func (f *Function) IsVariableParameter() bool

func (*Function) SetIsVariableParameter

func (f *Function) SetIsVariableParameter(v bool)

func (*Function) SetName

func (f *Function) SetName(name string)

func (*Function) SetParamSymbols

func (f *Function) SetParamSymbols(i []int)

func (*Function) SetSourceCode added in v1.2.3

func (f *Function) SetSourceCode(s string)

func (*Function) SetSymbol

func (f *Function) SetSymbol(id int)

func (*Function) String

func (f *Function) String() string

type IteratorInterface

type IteratorInterface interface {
	IsEnd() bool
	Next() (data []interface{}, hadEnd bool)
	Type() IteratorType
}

func NewIterator

func NewIterator(i interface{}, v *Frame) (IteratorInterface, error)

type IteratorType

type IteratorType int
const (
	SliceIteratorType IteratorType = iota
	MapIteratorType
	ChannelIteratorType
	RepeatIteratorType
)

type LinesFirstCodeStateMap added in v1.2.6

type LinesFirstCodeStateMap = map[int]*CodeState

type MapIterator

type MapIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

func (*MapIterator) Next

func (i *MapIterator) Next() (data []interface{}, hadEnd bool)

type MethodFactory

type MethodFactory func(*Frame, interface{}) interface{}

func NewArrayMethodFactory

func NewArrayMethodFactory(f func(*Frame, *Value, interface{}) interface{}) MethodFactory

func NewBytesMethodFactory

func NewBytesMethodFactory(f func([]byte) interface{}) MethodFactory

func NewMapMethodFactory

func NewMapMethodFactory(f func(frame *Frame, v *Value) interface{}) MethodFactory

func NewStringMethodFactory

func NewStringMethodFactory(f func(string) interface{}) MethodFactory

type ObserveBreakPointMap added in v1.2.6

type ObserveBreakPointMap = map[string]*Value

type OpcodeFlag

type OpcodeFlag int
const (
	OpNop OpcodeFlag = iota

	// OpTypeCast 从栈中取出两个值,第一个值为类型,第二个值为具体需要转换的值,进行类型转换,并把结果推入栈中
	OpTypeCast // type convert
	// Unary
	OpNot  // !
	OpNeg  // -
	OpPlus // +
	OpChan // <-

	OpPlusPlus   // ++
	OpMinusMinus // --

	// Binary
	OpShl    // <<
	OpShr    // >>
	OpAnd    // &
	OpAndNot // &^
	OpOr     // |
	OpXor    // ^

	OpAdd  // +
	OpSub  // -
	OpMul  // *
	OpDiv  // /
	OpMod  // %
	OpGt   // >
	OpLt   // <
	OpGtEq // >=
	OpLtEq // <=

	OpEq       // ==
	OpNotEq    // != <>
	OpPlusEq   // +=
	OpMinusEq  // -=
	OpMulEq    // *=
	OpDivEq    // /=
	OpModEq    // %=
	OpAndEq    // &=
	OpOrEq     // |=
	OpXorEq    // ^=
	OpShlEq    // <<=
	OpShrEq    // >>=
	OpAndNotEq // &^=

	OpIn       // in
	OpSendChan // <-

	OpType // type
	OpMake // make

	OpPush     // 把一个 Op1 压入栈
	OpPushfuzz // 把一个 Op1,执行 Fuzz String 操作,并且压入栈

	/*
		for range 和 for in 需要对右值表达式结果进行迭代,需要配合 Op 实现
	*/
	OpRangeNext // 从栈中取出一个元素,然后迭代, 并且压入栈
	OpInNext    // 从栈中取出一个元素,然后迭代, 并且压入栈, 与range稍微有点区别,比如可以解包slice以及迭代slice时第一个值时value而不是index
	OpEnterFR   // 进入for range, 从栈中peek值创建迭代器,并往IteratorStack栈中压入迭代器
	OpExitFR    // 退出for range, 判断IteratorStack是否已经结束,如果未结束则跳到for range开头(Unary),否则将pop IteratorStack并继续执行后续代码

	OpList // 这个操作有一个参数,从栈中取多少个元素组成 list,用 unary: int 标记

	// OpAssign 这个操作有两个参数
	// 左右值一般都会是 ValueList,所以 TypeVerbose 为 list, 将会设定类型断言 []*Value
	// popArgN 后,0 为右值,1 为左值
	OpAssign

	// OpFastAssign 快速赋值,存在于特殊的赋值中
	// 从栈中取两个值,arg1 为符号左,arg2 为具体值
	// 进行快速赋值,直接把值赋值给符号左,并且把 arg2 继续压入栈
	OpFastAssign

	// push 一个符号对应的值,这个值没有操作数 op1 op2 只操作 unary
	OpPushRef
	// 左值引用,是一个专属 push 一般用于赋值需要替换 **Value 的时候
	// 这个只操作了 Unary,Unary 传递具体的符号
	OpPushLeftRef

	// 除了跳转指令之外,其他指令都不应该直接操作 index!
	// JMP 无条件跳转到第几条指令,unary 记录指令数
	OpJMP
	// 从栈中取出一个值,如果值为 true 跳转到 unary 的指令中
	OpJMPT
	// 从栈中取出一个值,值为 false 跳转到 unary 的指令中
	OpJMPF
	// 从栈中查看最近的一个值,值为 true 则跳转到 unary 位置,否则 pop 出栈数据
	OpJMPTOP
	// 从栈中查看最近的一个值,值为 false 则跳转到 unary 位置,否则 pop 出栈数据
	OpJMPFOP

	// OpBreak 这个语句是为 break 设置的语句,一般是用来记录跳转到的位置,基本等同于 JMP
	// 不一样的是 Break 的位置,其实是无法事先预知的,
	// 所以需要 for 循环结束的最后一步,去寻找当前 for 循环中没有被设置过的 break 语句
	// 没有被设置之前,Unary 应该是小于等于零的
	// 因为 Break 也操作了指针,所以 OpBreak 结束后也不应该操作指针
	//
	// 和 JMP 不一样的地方是,Break/Continue 会破坏 scope 栈的平衡
	// 所以,这两个执行的时候,需要附带栈推出
	OpBreak
	OpContinue

	// OpCall / OpVariadicCall 从 unary 中取应该 pop 多少个数
	// 并且再重栈中 pop 出应该调用的内容
	OpCall
	OpVariadicCall /*这个是针对可变参数的调用*/

	// OpPushId push 一个引用名字,这个名字可能是无法获取到符号表中的符号,但是被使用了
	// 所以这个不能使用 unary,使用 op1 类型为 Identifier 作为操作数,找不到就是 nil 或者 undefined
	OpPushId

	// OpPop 一般用于维持栈平衡,比如说 push 一个表达式语句,一般不会 pop,需要用 OpPop 来弹出
	OpPop

	// OpNewMap 这个指令用于创建一个 map,从栈中取出 unary * 2 个数据,然后俩俩组合,左边为 key 右边为 value
	OpNewMap

	// OpNewMapWithType 这个指令用于创建一个 map,从栈中取出 unary * 2 个数据,然后俩俩组合,左边为 key 右边为 value, 再取出 Type,组合成 Map
	OpNewMapWithType

	// OpNewSlice 用于从栈中创建 Slice,取出 unary 个数据,推断类型,然后组合成 slice
	OpNewSlice

	// OpNewSliceWithType 从栈中创建 Slice,取出 unary 个操作数,再取出 Type,组合成 Slice
	OpNewSliceWithType

	// OpSliceCall 索引Silice
	OpIterableCall

	// OpReturn 从栈取一个数据出来,复制给返回值缓存数据,一般来说,可以用 lastStackValue 来取数
	OpReturn

	// OpDefer 执行 op1,一般 op1 的值必须是 codes 也就是 []*Opcode
	// 作为虚拟机退出的时候需要执行的值
	OpDefer
	// OpAssert 从栈中取出几一个或两个参数,然后断言类型,如果是false,就 panic参数第二个参数
	OpAssert

	// OpMemberCall 获取map或结构体的成员变量或方法
	OpMemberCall

	// OpAsyncCall 执行 goroutine
	// unary 为
	OpAsyncCall

	// OpScope 会新创建一个定义域,通过 OpScopeEnd 来停止定义域
	// 定义域是一个树形结构,保存了父定义域的引用,因为需要看到父定义域的内容
	OpScope
	OpScopeEnd

	// include 会直接从栈中pop文件路径然后执行
	OpInclude

	// OpPanic 主动 panic 掉,然后把错误交给 Defer 的 Recover 实现
	OpPanic
	OpRecover

	// OpEllipsis 函数不定参数调用拆包
	OpEllipsis
	// OpBitwiseNot 按位取反
	OpBitwiseNot

	OpCatchError
	OpStopCatchError
	OpExit
)

func (OpcodeFlag) IsJmp

func (f OpcodeFlag) IsJmp() bool

type PanicInfo

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

func (*PanicInfo) SetPositionVerbose added in v1.2.8

func (p *PanicInfo) SetPositionVerbose(s string)

func (*PanicInfo) String

func (p *PanicInfo) String() string

type Reference added in v1.2.6

type Reference struct {
	FrameHM      *frameHandlesMap
	BreakPointHM *breakPointHandlesMap
	VarHM        *handlesMap // 这里会存储Scope, yakvm.Value, 或者golang的value
}

func NewReference added in v1.2.6

func NewReference() *Reference

type RepeatIterator

type RepeatIterator struct {
	BaseIterator
}

func (*RepeatIterator) Next

func (i *RepeatIterator) Next() (data []interface{}, hadEnd bool)

type Scope

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

func NewScope

func NewScope(table *SymbolTable) *Scope

NewScope Create Root Scope NewVirtualMachine Called Generally

func (*Scope) CreateSubScope

func (s *Scope) CreateSubScope(table *SymbolTable) *Scope

func (*Scope) GetAllIdInScopes

func (s *Scope) GetAllIdInScopes() []int

func (*Scope) GetAllNameAndValueInAllScopes

func (s *Scope) GetAllNameAndValueInAllScopes() (results map[string]*Value)

func (*Scope) GetAllNameAndValueInScopes

func (s *Scope) GetAllNameAndValueInScopes() (results map[string]*Value)

func (*Scope) GetIdByName added in v1.2.6

func (s *Scope) GetIdByName(name string) int

func (*Scope) GetNameById

func (s *Scope) GetNameById(id int) string

func (*Scope) GetSymTable

func (s *Scope) GetSymTable() *SymbolTable

func (*Scope) GetValueByID

func (s *Scope) GetValueByID(id int) (*Value, bool)

func (*Scope) GetValueByName

func (s *Scope) GetValueByName(name string) (*Value, bool)

func (*Scope) InCurrentScope

func (s *Scope) InCurrentScope(id int) bool

func (*Scope) IsRoot

func (s *Scope) IsRoot() bool

func (*Scope) Len added in v1.2.6

func (s *Scope) Len() int

func (*Scope) NewValueByID

func (s *Scope) NewValueByID(id int, v *Value)

func (*Scope) SetSymTable

func (s *Scope) SetSymTable(symtbl *SymbolTable)

func (*Scope) SetVerbose

func (s *Scope) SetVerbose(v string)

type SliceIterator

type SliceIterator struct {
	BaseIterator
	// contains filtered or unexported fields
}

func (*SliceIterator) Next

func (i *SliceIterator) Next() (data []interface{}, hadEnd bool)

type StackTrace added in v1.2.6

type StackTrace struct {
	ID   int
	Name string

	Frame *Frame

	Source             *string
	SourceCode         *string
	Line, Column       int
	EndLine, EndColumn int
}

type StackTraces added in v1.2.6

type StackTraces struct {
	ThreadID    int
	StackTraces []StackTrace
}

type SymbolTable

type SymbolTable struct {
	Verbose string

	InitedId map[int]struct{}
	// contains filtered or unexported fields
}

func NewSymbolTable

func NewSymbolTable() *SymbolTable

func (*SymbolTable) CreateSubSymbolTable

func (s *SymbolTable) CreateSubSymbolTable(verbose ...string) *SymbolTable

func (*SymbolTable) GetLocalSymbolByVariableName

func (s *SymbolTable) GetLocalSymbolByVariableName(name string) (int, bool)

func (*SymbolTable) GetNameByVariableId

func (s *SymbolTable) GetNameByVariableId(id int) (string, bool)

func (*SymbolTable) GetParentSymbolTable

func (s *SymbolTable) GetParentSymbolTable() *SymbolTable

func (*SymbolTable) GetRoot

func (s *SymbolTable) GetRoot() (*SymbolTable, error)

func (*SymbolTable) GetSymbolByVariableName

func (s *SymbolTable) GetSymbolByVariableName(name string) (int, bool)

func (*SymbolTable) GetSymbolTableById

func (s *SymbolTable) GetSymbolTableById(id int) *SymbolTable

func (*SymbolTable) GetTableCount

func (s *SymbolTable) GetTableCount() int

func (*SymbolTable) GetTableIndex

func (s *SymbolTable) GetTableIndex() int

func (*SymbolTable) IdIsInited

func (s *SymbolTable) IdIsInited(id int) bool

func (*SymbolTable) IsNew

func (s *SymbolTable) IsNew() bool

func (*SymbolTable) MustRoot

func (s *SymbolTable) MustRoot() *SymbolTable

func (*SymbolTable) NewSymbolWithReturn

func (s *SymbolTable) NewSymbolWithReturn(name string) (int, error)

func (*SymbolTable) NewSymbolWithoutName

func (s *SymbolTable) NewSymbolWithoutName() int

func (*SymbolTable) SetIdIsInited

func (s *SymbolTable) SetIdIsInited(id int)

type SymbolTableDesc

type SymbolTableDesc struct {
	Verbose string

	Index    int
	Parent   int
	Children []int
	NameToId map[string]int
	// contains filtered or unexported fields
}

type VMPanic

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

func NewVMPanic

func NewVMPanic(i interface{}) *VMPanic

func (*VMPanic) Error

func (v *VMPanic) Error() string

func (*VMPanic) GetData

func (v *VMPanic) GetData() interface{}

func (*VMPanic) GetDataDescription added in v1.2.6

func (v *VMPanic) GetDataDescription() string

type VMPanicSignal

type VMPanicSignal struct {
	Info           interface{}
	AdditionalInfo interface{}
}

type Value

type Value struct {
	TypeVerbose string
	Value       interface{}
	Literal     string

	// Identifier = expr
	// 当变量被赋值时,SymbolId 应该为赋值操作的根本
	SymbolId int
	// MemberCall 和 SliceCall 的 Caller 和 Collee
	// 一般来说 Caller.Callee 的时候,Callee 应该取 Identifier 的 Value 值
	// Caller[Callee] 的时候,Callee 取 Value
	// 这几个操作用反射都可以很容易做到
	CallerRef *Value
	CalleeRef *Value
	ExtraInfo map[string]interface{}
}

func ChannelValueListToValue

func ChannelValueListToValue(op *Value) *Value

func GetUndefined

func GetUndefined() *Value

func NewAutoValue

func NewAutoValue(b interface{}) *Value

func NewBoolValue

func NewBoolValue(b bool) *Value

func NewEmptyMap

func NewEmptyMap(lit string) *Value

func NewGeneralMap

func NewGeneralMap(lit string) *Value

func NewGenericMap

func NewGenericMap(lit string) *Value

func NewIdentifierValue

func NewIdentifierValue(i string) *Value

func NewInt64Value

func NewInt64Value(i int64) *Value

func NewIntValue

func NewIntValue(i int) *Value

func NewStringSliceValue

func NewStringSliceValue(i []string) *Value

func NewStringValue

func NewStringValue(i string) *Value

func NewType

func NewType(typeStr string, value reflect.Type) *Value

func NewUndefined

func NewUndefined(id int) *Value

func NewValue

func NewValue(typeStr string, value interface{}, lit string) *Value

func NewValueRef

func NewValueRef(id int) *Value

func NewValues

func NewValues(val []*Value) *Value

func (*Value) AddExtraInfo

func (v *Value) AddExtraInfo(key string, info interface{})

func (*Value) AsString

func (v *Value) AsString() string

func (*Value) Assign

func (_v *Value) Assign(vir *Frame, right *Value)

func (*Value) AssignBySymbol

func (v *Value) AssignBySymbol(table *Scope, val *Value)

func (*Value) AsyncCall

func (v *Value) AsyncCall(vm *Frame, wavy bool, vs ...*Value)

func (*Value) Bool

func (v *Value) Bool() bool

func (*Value) Bytes

func (v *Value) Bytes() []byte

func (*Value) Call

func (v *Value) Call(vm *Frame, wavy bool, vs ...*Value) interface{}

func (*Value) CallLua

func (v *Value) CallLua(vm *Frame, vs ...*Value) interface{}

func (*Value) CallSliceIndex

func (v *Value) CallSliceIndex(i int) interface{}

func (*Value) Callable

func (v *Value) Callable() bool

func (*Value) Codes

func (v *Value) Codes() []*Code

func (*Value) ConvertToLeftValue

func (v *Value) ConvertToLeftValue() (*Value, error)

ConvertToLeftValue 当前值能不能转成左值? 这个是方法调用赋值的关键

func (*Value) Equal

func (_v *Value) Equal(value *Value) bool

func (*Value) False

func (v *Value) False() bool

func (*Value) Float64

func (v *Value) Float64() float64

func (*Value) GetExtraInfo

func (v *Value) GetExtraInfo(key string) interface{}

func (*Value) GetIndexedVariableCount added in v1.2.6

func (v *Value) GetIndexedVariableCount() int

func (*Value) GetLeftCallerNIndex

func (v *Value) GetLeftCallerNIndex() (*Value, *Value)

func (*Value) GetNamedVariableCount added in v1.2.6

func (v *Value) GetNamedVariableCount() int

func (*Value) GetNativeCallFunctionName

func (v *Value) GetNativeCallFunctionName() string

func (*Value) GlobalAssign

func (_v *Value) GlobalAssign(vir *Frame, right *Value)

func (*Value) GlobalAssignBySymbol

func (v *Value) GlobalAssignBySymbol(table *Scope, val *Value)

func (*Value) Int

func (v *Value) Int() int

func (*Value) Int64

func (v *Value) Int64() int64

func (*Value) IntBool added in v1.2.6

func (v *Value) IntBool() bool

func (*Value) IsBool

func (v *Value) IsBool() bool

func (*Value) IsByte

func (v *Value) IsByte() bool

func (*Value) IsBytes

func (v *Value) IsBytes() bool

func (*Value) IsBytesOrRunes added in v1.2.6

func (v *Value) IsBytesOrRunes() bool

func (*Value) IsChannel

func (v *Value) IsChannel() bool

func (*Value) IsChannelValueList

func (v *Value) IsChannelValueList() bool

func (*Value) IsCodes

func (v *Value) IsCodes() bool

func (*Value) IsFloat

func (v *Value) IsFloat() bool

func (*Value) IsIdentifier

func (v *Value) IsIdentifier() bool

func (*Value) IsInt

func (v *Value) IsInt() bool

func (*Value) IsInt64

func (v *Value) IsInt64() bool

func (*Value) IsInt64EX

func (v *Value) IsInt64EX() (int64, bool)

func (*Value) IsIterable

func (v *Value) IsIterable() bool

func (*Value) IsLeftMemberCall

func (v *Value) IsLeftMemberCall() bool

func (*Value) IsLeftSliceCall

func (v *Value) IsLeftSliceCall() bool

func (*Value) IsLeftValueRef

func (v *Value) IsLeftValueRef() bool

func (*Value) IsMap

func (v *Value) IsMap() bool

func (*Value) IsString

func (v *Value) IsString() bool

func (*Value) IsStringOrBytes

func (v *Value) IsStringOrBytes() bool

func (*Value) IsType

func (v *Value) IsType() bool

func (*Value) IsUndefined

func (v *Value) IsUndefined() bool

func (*Value) IsValueList

func (v *Value) IsValueList() bool

func (*Value) IsYakFunction

func (v *Value) IsYakFunction() bool

func (*Value) LeftMemberAssignTo

func (v *Value) LeftMemberAssignTo(vir *Frame, val *Value)

func (*Value) LeftSliceAssignTo

func (v *Value) LeftSliceAssignTo(vir *Frame, val *Value)

func (*Value) Len

func (v *Value) Len() int

func (*Value) LuaFalse

func (v *Value) LuaFalse() bool

func (*Value) LuaFunctionNCall

func (v *Value) LuaFunctionNCall(vm *Frame, vs ...*Value) interface{}

func (*Value) LuaLeftSliceAssignTo

func (v *Value) LuaLeftSliceAssignTo(vir *Frame, val *Value)

func (*Value) LuaTrue

func (v *Value) LuaTrue() bool

func (*Value) NativeAsyncCall

func (v *Value) NativeAsyncCall(vm *Frame, wavy bool, vs ...*Value) interface{}

func (*Value) NativeCall

func (v *Value) NativeCall(vm *Frame, wavy bool, vs ...*Value) interface{}

func (*Value) NativeCallable

func (v *Value) NativeCallable() bool

func (*Value) Rangeable

func (v *Value) Rangeable() bool

func (*Value) String

func (v *Value) String() string

func (*Value) True

func (v *Value) True() bool

func (*Value) Type

func (v *Value) Type() reflect.Type

func (*Value) TypeStr added in v1.2.6

func (v *Value) TypeStr() string

func (*Value) ValueList

func (v *Value) ValueList() []*Value

func (*Value) ValueListToInterface

func (v *Value) ValueListToInterface() interface{}

func (*Value) YakFunctionNAsyncCall

func (v *Value) YakFunctionNAsyncCall(vm *Frame, vs ...*Value)

func (*Value) YakFunctionNCall

func (v *Value) YakFunctionNCall(vm *Frame, vs ...*Value) interface{}

type VirtualMachine

type VirtualMachine struct {
	VMStack *vmstack.Stack

	BreakPoint    []BreakPointFactoryFun
	ThreadIDCount uint64

	GetExternalVar func(name string) (any, bool)
	// contains filtered or unexported fields
}

func New

func New() *VirtualMachine

func NewWithSymbolTable

func NewWithSymbolTable(table *SymbolTable) *VirtualMachine

func (*VirtualMachine) AddBreakPoint

func (v *VirtualMachine) AddBreakPoint(fun BreakPointFactoryFun)

func (*VirtualMachine) AsyncEnd added in v1.2.9

func (v *VirtualMachine) AsyncEnd()

func (*VirtualMachine) AsyncStart added in v1.2.9

func (v *VirtualMachine) AsyncStart()

func (*VirtualMachine) AsyncWait added in v1.2.9

func (v *VirtualMachine) AsyncWait()

func (*VirtualMachine) CurrentFM

func (v *VirtualMachine) CurrentFM() *Frame

func (*VirtualMachine) Exec

func (v *VirtualMachine) Exec(ctx context.Context, f func(frame *Frame), flags ...ExecFlag) error

func (*VirtualMachine) ExecAsyncYakFunction

func (v *VirtualMachine) ExecAsyncYakFunction(ctx context.Context, f *Function, args map[int]*Value) error

func (*VirtualMachine) ExecYakCode

func (v *VirtualMachine) ExecYakCode(ctx context.Context, sourceCode string, codes []*Code, flags ...ExecFlag) error

func (*VirtualMachine) ExecYakFunction

func (v *VirtualMachine) ExecYakFunction(ctx context.Context, f *Function, args map[int]*Value, flags ...ExecFlag) (interface{}, error)

func (*VirtualMachine) GetConfig

func (v *VirtualMachine) GetConfig() *VirtualMachineConfig

func (*VirtualMachine) GetDebugger added in v1.2.6

func (n *VirtualMachine) GetDebugger() *Debugger

func (*VirtualMachine) GetExternalVariableNames

func (n *VirtualMachine) GetExternalVariableNames() []string

func (*VirtualMachine) GetGlobalVar

func (n *VirtualMachine) GetGlobalVar() map[string]interface{}

func (*VirtualMachine) GetVar

func (n *VirtualMachine) GetVar(name string) (interface{}, bool)

func (*VirtualMachine) ImportLibs

func (n *VirtualMachine) ImportLibs(libs map[string]interface{})

ImportLibs 导入库到引擎的全局变量中

func (*VirtualMachine) InlineExecYakCode

func (v *VirtualMachine) InlineExecYakCode(ctx context.Context, codes []*Code, flags ...ExecFlag) error

func (*VirtualMachine) RegisterGlobalVariableFallback

func (n *VirtualMachine) RegisterGlobalVariableFallback(h func(string) interface{})

func (*VirtualMachine) RegisterMapMemberCallHandler

func (n *VirtualMachine) RegisterMapMemberCallHandler(caller, callee string, h func(interface{}) interface{})

func (*VirtualMachine) SetConfig

func (v *VirtualMachine) SetConfig(config *VirtualMachineConfig)

func (*VirtualMachine) SetDebug

func (v *VirtualMachine) SetDebug(debug bool)

func (*VirtualMachine) SetDebugMode

func (v *VirtualMachine) SetDebugMode(debug bool, sourceCode string, codes []*Code, debugInit, debugCallback func(*Debugger))

func (*VirtualMachine) SetSandboxMode added in v1.3.1

func (v *VirtualMachine) SetSandboxMode(mode bool)

func (*VirtualMachine) SetSymboltable

func (v *VirtualMachine) SetSymboltable(table *SymbolTable)

func (*VirtualMachine) SetVar

func (n *VirtualMachine) SetVar(k string, v interface{})

SetVar 导入变量到引擎的全局变量中

func (*VirtualMachine) SetYaiktFeedbacker

func (n *VirtualMachine) SetYaiktFeedbacker(i YakitFeedbacker)

type VirtualMachineConfig

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

func NewVMConfig

func NewVMConfig() *VirtualMachineConfig

func (*VirtualMachineConfig) GetClosureSupport

func (c *VirtualMachineConfig) GetClosureSupport() bool

func (*VirtualMachineConfig) GetFunctionNumberCheck

func (c *VirtualMachineConfig) GetFunctionNumberCheck() bool

func (*VirtualMachineConfig) GetStopRecover

func (c *VirtualMachineConfig) GetStopRecover() bool

func (*VirtualMachineConfig) SetClosureSupport

func (c *VirtualMachineConfig) SetClosureSupport(b bool)

func (*VirtualMachineConfig) SetFunctionNumberCheck

func (c *VirtualMachineConfig) SetFunctionNumberCheck(b bool)

func (*VirtualMachineConfig) SetStopRecover

func (c *VirtualMachineConfig) SetStopRecover(b bool)

func (*VirtualMachineConfig) SetYVMMode

func (c *VirtualMachineConfig) SetYVMMode(mode YVMMode)

type YVMMode

type YVMMode string
const (
	NASL YVMMode = "NASL"
	LUA  YVMMode = "LUA"
	YAK  YVMMode = "YAK"
)

type YakitFeedbacker

type YakitFeedbacker interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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