Documentation ¶
Overview ¶
borrowed from bytebufferpool
Index ¶
- Constants
- Variables
- func EvalConstInstructions(instructions []Instruction) interface{}
- func FormatError(ctx antlr.ParserRuleContext, message string) string
- func IsBuiltIn(name string) bool
- func IsError(i Instruction) bool
- func IsFloat(d *DataType) bool
- func IsInteger(d *DataType) bool
- func IsNumber(d *DataType) bool
- func NewAnyValue(params ...interface{}) interface{}
- func NewBoolValue(params ...interface{}) interface{}
- func NewBytesValue(params ...interface{}) interface{}
- func NewChannelValue(params ...interface{}) interface{}
- func NewFloat32Value(params ...interface{}) interface{}
- func NewFloat64Value(params ...interface{}) interface{}
- func NewInt32Value(params ...interface{}) interface{}
- func NewInt64Value(params ...interface{}) interface{}
- func NewMapBoolValue(params ...interface{}) interface{}
- func NewMapFloat32Value(params ...interface{}) interface{}
- func NewMapFloat64Value(params ...interface{}) interface{}
- func NewMapInt32Value(params ...interface{}) interface{}
- func NewMapInt64Value(params ...interface{}) interface{}
- func NewMapStringValue(params ...interface{}) interface{}
- func NewMapUInt32Value(params ...interface{}) interface{}
- func NewMapUInt64Value(params ...interface{}) interface{}
- func NewMapValue(params ...interface{}) interface{}
- func NewMessageValue(params ...interface{}) interface{}
- func NewNilValue(params ...interface{}) interface{}
- func NewSliceValue(params ...interface{}) interface{}
- func NewStringValue(params ...interface{}) interface{}
- func NewUInt32Value(params ...interface{}) interface{}
- func NewUInt64Value(params ...interface{}) interface{}
- func NewUInt8Value(params ...interface{}) interface{}
- func Put(b *Stack)
- func RegisterLib(name string, lib FunctionLib)
- type CompileErr
- type Constant
- type Constructor
- type DataKind
- type DataType
- func CanAddSubMulPow(d *DataType, b *DataType) *DataType
- func CanAndOr(d *DataType, b *DataType) *DataType
- func CanCompare(d *DataType, b *DataType) *DataType
- func CanDiv(d *DataType, b *DataType) *DataType
- func CanEqual(d *DataType, b *DataType) *DataType
- func CanMod(d *DataType, b *DataType) *DataType
- type DataTypeBuilder
- func (d *DataTypeBuilder) SetField(fieldName string, fieldType *DataType)
- func (d *DataTypeBuilder) SetItem(itemType *DataType)
- func (d *DataTypeBuilder) SetKey(keyType *DataType)
- func (d *DataTypeBuilder) SetKind(k int)
- func (d *DataTypeBuilder) SetOneOf(oneOfName string, fieldName string)
- func (d *DataTypeBuilder) SetValue(valType *DataType)
- type Function
- type FunctionLib
- type FunctionMeta
- type IndexErr
- type InitializationErr
- type Instruction
- type MathErr
- type Memory
- type MismatchErr
- type Pool
- type Scope
- type ScriptError
- func NewCompileErr(message string) ScriptError
- func NewIndexErr(message string) ScriptError
- func NewInitializationErr(message string) ScriptError
- func NewMathErr(message string) ScriptError
- func NewMismatchErr(message string) ScriptError
- func NewSymbolErr(message string) ScriptError
- func NewTypeErr(message string) ScriptError
- func NewTypeNotFoundErr(message string) ScriptError
- type ScriptErrorType
- type Stack
- func (s *Stack) Call(inst Instruction, mem *Memory, stk *Stack, params int)
- func (s *Stack) Get(v *Symbol) interface{}
- func (s *Stack) MustGet(v *Symbol) *interface{}
- func (s *Stack) Pop()
- func (s *Stack) PopN(i int)
- func (s *Stack) Push(i interface{})
- func (s *Stack) Reset() *Stack
- func (s *Stack) ReturnValue(val interface{})
- func (s *Stack) ReturnValues(values ...interface{})
- func (s *Stack) Set(spOffset int, i interface{})
- func (s *Stack) Top() interface{}
- func (s *Stack) TopIndex(i int) interface{}
- type Symbol
- type SymbolErr
- type SymbolType
- type TypeErr
- type TypeNotFoundErr
- type TypeRegistry
- func (t *TypeRegistry) AddBuiltType(dtb *DataTypeBuilder)
- func (t *TypeRegistry) AddEnum(name string, e map[string]int32)
- func (t *TypeRegistry) AddType(name string, dType *DataType)
- func (t *TypeRegistry) AddTypePlaceHolderInBuild(name string) *DataType
- func (t *TypeRegistry) FindChanType(name string) *DataType
- func (t *TypeRegistry) FindFuncType(meta *FunctionMeta) *DataType
- func (t *TypeRegistry) FindMapType(key, val string) *DataType
- func (t *TypeRegistry) FindSliceType(name string) *DataType
- func (t *TypeRegistry) FindType(name string) *DataType
- func (t *TypeRegistry) GetEnums(name string) interface{}
- func (t *TypeRegistry) GetREnums(name string) map[int32]string
- func (t *TypeRegistry) MakeChanType(name string) *DataType
- func (t *TypeRegistry) MakeFuncType(meta *FunctionMeta) *DataType
- func (t *TypeRegistry) MakeMapType(key, val string) *DataType
- func (t *TypeRegistry) MakeSliceType(name string) *DataType
Constants ¶
View Source
const ( UInt8 = iota UInt32 UInt64 Int32 Int64 Float32 Float64 Bool Bytes String Slice Map Message Channel Nil Enum Func ReflectType Any Illegal )
View Source
const ( UInt8Type = "uint8" UInt32Type = "uint32" UInt64Type = "uint64" Int32Type = "int32" Int64Type = "int64" Float32Type = "float32" Float64Type = "float64" BoolType = "bool" BytesType = "bytes" StringType = "string" SliceType = "slice" MapType = "map" MessageType = "message" AnyType = "any" )
Variables ¶
View Source
var BasicTypeMap = map[string]*DataType{ "uint8": { Type: "uint8", Kind: KindMap[UInt8], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadInt32() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[UInt8], }, "int32": { Type: "int32", Kind: KindMap[Int32], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadInt32() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Int32], }, "int64": { Type: "int64", Kind: KindMap[Int64], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadInt64() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Int64], }, "uint32": { Type: "uint32", Kind: KindMap[UInt32], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadUint32() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[UInt32], }, "uint64": { Type: "uint64", Kind: KindMap[UInt64], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadUint32() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[UInt64], }, "float32": { Type: "float32", Kind: KindMap[Float32], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadFloat32() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Float32], }, "float64": { Type: "float64", Kind: KindMap[Float64], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadFloat64() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Float64], }, "string": { Type: "string", Kind: KindMap[String], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadString() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[String], }, "bytes": { Type: "bytes", Kind: KindMap[Bytes], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return []byte(iter.ReadString()) }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Bytes], }, "bool": { Type: "bool", Kind: KindMap[Bool], Unmarshal: func(iter *jsoniter.Iterator) interface{} { return iter.ReadBool() }, Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Bool], }, "nil": { Type: "nil", Kind: KindMap[Nil], }, "reflect": { Type: "reflect", Method: map[string]*FunctionMeta{}, Kind: KindMap[ReflectType], }, "any": { Type: "any", Kind: KindMap[Any], Method: map[string]*FunctionMeta{}, Constructor: ConstructorMap[Any], }, "illegal": { Type: "illegal", Kind: KindMap[Illegal], }, }
View Source
var ConstructorMap = map[int]Constructor{ UInt8: NewUInt8Value, Int32: NewInt32Value, Int64: NewInt64Value, UInt32: NewUInt32Value, UInt64: NewUInt64Value, Float32: NewFloat32Value, Float64: NewFloat64Value, Bool: NewBoolValue, String: NewStringValue, Bytes: NewBytesValue, Nil: NewNilValue, Message: NewMessageValue, Slice: NewSliceValue, Channel: NewChannelValue, Any: NewAnyValue, }
View Source
var KindMap = map[int]*DataKind{ UInt8: { Kind: UInt8, }, Int32: { Kind: Int32, }, Int64: { Kind: Int64, }, UInt32: { Kind: UInt32, }, UInt64: { Kind: UInt64, }, Float32: { Kind: Float32, }, Float64: { Kind: Float64, }, Bool: { Kind: Bool, }, String: { Kind: String, }, Bytes: { Kind: Bytes, }, Slice: { Kind: Slice, }, Map: { Kind: Map, }, Message: { Kind: Message, }, Channel: { Kind: Channel, }, Nil: { Kind: Nil, }, Enum: { Kind: Enum, }, Func: { Kind: Func, }, ReflectType: { Kind: ReflectType, }, Any: { Kind: Any, }, Illegal: { Kind: Illegal, }, }
View Source
var MapConstructorMap = map[int]Constructor{ Int32: NewMapInt32Value, Int64: NewMapInt64Value, UInt32: NewMapUInt32Value, UInt64: NewMapUInt64Value, Float32: NewMapFloat32Value, Float64: NewMapFloat64Value, Bool: NewMapBoolValue, String: NewMapStringValue, }
View Source
var RegisteredLibs = map[string]FunctionLib{}
Functions ¶
func EvalConstInstructions ¶
func EvalConstInstructions(instructions []Instruction) interface{}
func FormatError ¶
func FormatError(ctx antlr.ParserRuleContext, message string) string
func IsError ¶
func IsError(i Instruction) bool
func NewAnyValue ¶
func NewAnyValue(params ...interface{}) interface{}
func NewBoolValue ¶
func NewBoolValue(params ...interface{}) interface{}
func NewBytesValue ¶
func NewBytesValue(params ...interface{}) interface{}
func NewChannelValue ¶
func NewChannelValue(params ...interface{}) interface{}
func NewFloat32Value ¶
func NewFloat32Value(params ...interface{}) interface{}
func NewFloat64Value ¶
func NewFloat64Value(params ...interface{}) interface{}
func NewInt32Value ¶
func NewInt32Value(params ...interface{}) interface{}
func NewInt64Value ¶
func NewInt64Value(params ...interface{}) interface{}
func NewMapBoolValue ¶
func NewMapBoolValue(params ...interface{}) interface{}
func NewMapFloat32Value ¶
func NewMapFloat32Value(params ...interface{}) interface{}
func NewMapFloat64Value ¶
func NewMapFloat64Value(params ...interface{}) interface{}
func NewMapInt32Value ¶
func NewMapInt32Value(params ...interface{}) interface{}
func NewMapInt64Value ¶
func NewMapInt64Value(params ...interface{}) interface{}
func NewMapStringValue ¶
func NewMapStringValue(params ...interface{}) interface{}
func NewMapUInt32Value ¶
func NewMapUInt32Value(params ...interface{}) interface{}
func NewMapUInt64Value ¶
func NewMapUInt64Value(params ...interface{}) interface{}
func NewMapValue ¶
func NewMapValue(params ...interface{}) interface{}
func NewMessageValue ¶
func NewMessageValue(params ...interface{}) interface{}
func NewNilValue ¶
func NewNilValue(params ...interface{}) interface{}
func NewSliceValue ¶
func NewSliceValue(params ...interface{}) interface{}
func NewStringValue ¶
func NewStringValue(params ...interface{}) interface{}
func NewUInt32Value ¶
func NewUInt32Value(params ...interface{}) interface{}
func NewUInt64Value ¶
func NewUInt64Value(params ...interface{}) interface{}
func Put ¶
func Put(b *Stack)
Put returns byte buffer to the pool.
ByteBuffer.B mustn't be touched after returning it to the pool. Otherwise data races will occur.
func RegisterLib ¶
func RegisterLib(name string, lib FunctionLib)
Types ¶
type CompileErr ¶
type CompileErr struct {
// contains filtered or unexported fields
}
func (*CompileErr) Error ¶
func (t *CompileErr) Error() string
func (*CompileErr) Type ¶
func (t *CompileErr) Type() ScriptErrorType
type Constructor ¶
type Constructor func(...interface{}) interface{}
type DataKind ¶
type DataKind struct { // maybe this struct will be useful, so I just keep it here Kind int // int/float/message/slice/map/... }
type DataType ¶
type DataType struct { Type string Kind *DataKind FieldType map[string]*DataType // for complex OneOf map[string]string OneOfGroup map[string][]string ItemType *DataType // for sequence item type KeyType *DataType // map key ValueType *DataType // map val Method map[string]*FunctionMeta LambdaMeta *FunctionMeta // for closure Unmarshal func(iterator *jsoniter.Iterator) interface{} Constructor Constructor }
func CanAddSubMulPow ¶
func CanCompare ¶
func (*DataType) CanConvertTo ¶
type DataTypeBuilder ¶
type DataTypeBuilder struct {
T *DataType
}
func NewDataTypeBuilder ¶
func NewDataTypeBuilder(name string) *DataTypeBuilder
func (*DataTypeBuilder) SetField ¶
func (d *DataTypeBuilder) SetField(fieldName string, fieldType *DataType)
func (*DataTypeBuilder) SetItem ¶
func (d *DataTypeBuilder) SetItem(itemType *DataType)
func (*DataTypeBuilder) SetKey ¶
func (d *DataTypeBuilder) SetKey(keyType *DataType)
func (*DataTypeBuilder) SetKind ¶
func (d *DataTypeBuilder) SetKind(k int)
func (*DataTypeBuilder) SetOneOf ¶
func (d *DataTypeBuilder) SetOneOf(oneOfName string, fieldName string)
func (*DataTypeBuilder) SetValue ¶
func (d *DataTypeBuilder) SetValue(valType *DataType)
type Function ¶
type Function struct { Type *DataType F *Instruction }
type FunctionLib ¶
type FunctionLib interface {
Init(tr *TypeRegistry) map[string]*Function
}
type FunctionMeta ¶
type FunctionMeta struct { In []*DataType Out []*DataType TailArray bool ConstExpr bool // for future optimization }
func (*FunctionMeta) GenerateTypeName ¶
func (f *FunctionMeta) GenerateTypeName() string
type IndexErr ¶
type IndexErr struct {
// contains filtered or unexported fields
}
func (*IndexErr) Type ¶
func (t *IndexErr) Type() ScriptErrorType
type InitializationErr ¶
type InitializationErr struct {
// contains filtered or unexported fields
}
func (*InitializationErr) Error ¶
func (t *InitializationErr) Error() string
func (*InitializationErr) Type ¶
func (t *InitializationErr) Type() ScriptErrorType
type Instruction ¶
var ErrorInstruction Instruction = func(m *Memory, stk *Stack) {}
type MathErr ¶
type MathErr struct {
// contains filtered or unexported fields
}
func (*MathErr) Type ¶
func (t *MathErr) Type() ScriptErrorType
type MismatchErr ¶
type MismatchErr struct {
// contains filtered or unexported fields
}
func (*MismatchErr) Error ¶
func (t *MismatchErr) Error() string
func (*MismatchErr) Type ¶
func (t *MismatchErr) Type() ScriptErrorType
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents byte buffer pool.
Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.
type Scope ¶
type Scope struct { Outer *Scope VarIndex *int LocalIndex int ReturnIndex int Variables map[string]*Symbol Parameters map[string]*Symbol Constants map[string]*Symbol EnableCapture bool CaptureOffset int Capture []*Symbol CapturedSet map[string]*Symbol }
func (*Scope) AddConstant ¶
func (*Scope) AddGlobalVariable ¶
func (*Scope) AddLocalVariable ¶
func (*Scope) AddReturnVariable ¶
func (*Scope) SetCaptureMode ¶
func (s *Scope) SetCaptureMode()
type ScriptError ¶
type ScriptError interface { Error() string Type() ScriptErrorType }
func NewCompileErr ¶
func NewCompileErr(message string) ScriptError
func NewIndexErr ¶
func NewIndexErr(message string) ScriptError
func NewInitializationErr ¶
func NewInitializationErr(message string) ScriptError
func NewMathErr ¶
func NewMathErr(message string) ScriptError
func NewMismatchErr ¶
func NewMismatchErr(message string) ScriptError
func NewSymbolErr ¶
func NewSymbolErr(message string) ScriptError
func NewTypeErr ¶
func NewTypeErr(message string) ScriptError
func NewTypeNotFoundErr ¶
func NewTypeNotFoundErr(message string) ScriptError
type ScriptErrorType ¶
type ScriptErrorType int
const ( TypeNotFoundError ScriptErrorType = iota SymbolError IndexError MismatchError TypeError MathError InitializationError CompileError )
type Stack ¶
func Get ¶
func Get() *Stack
Get returns an empty byte buffer from the pool.
Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.
func (*Stack) ReturnValue ¶
func (s *Stack) ReturnValue(val interface{})
func (*Stack) ReturnValues ¶
func (s *Stack) ReturnValues(values ...interface{})
type Symbol ¶
type Symbol struct { Offset int // for slice mem Symbol string SymbolType SymbolType DataType *DataType Scope *Scope Data interface{} }
type SymbolErr ¶
type SymbolErr struct {
// contains filtered or unexported fields
}
func (*SymbolErr) Type ¶
func (t *SymbolErr) Type() ScriptErrorType
type TypeErr ¶
type TypeErr struct {
// contains filtered or unexported fields
}
func (*TypeErr) Type ¶
func (t *TypeErr) Type() ScriptErrorType
type TypeNotFoundErr ¶
type TypeNotFoundErr struct {
// contains filtered or unexported fields
}
func (*TypeNotFoundErr) Error ¶
func (t *TypeNotFoundErr) Error() string
func (*TypeNotFoundErr) Type ¶
func (t *TypeNotFoundErr) Type() ScriptErrorType
type TypeRegistry ¶
type TypeRegistry struct { Types map[string]*DataType Enums map[string]map[string]int32 REnums map[string]map[int32]string TypesInBuild map[string]*DataType }
func NewTypeRegistry ¶
func NewTypeRegistry() *TypeRegistry
func (*TypeRegistry) AddBuiltType ¶
func (t *TypeRegistry) AddBuiltType(dtb *DataTypeBuilder)
func (*TypeRegistry) AddType ¶
func (t *TypeRegistry) AddType(name string, dType *DataType)
not suggested to use, use DataTypeBuilder instead
func (*TypeRegistry) AddTypePlaceHolderInBuild ¶
func (t *TypeRegistry) AddTypePlaceHolderInBuild(name string) *DataType
func (*TypeRegistry) FindChanType ¶
func (t *TypeRegistry) FindChanType(name string) *DataType
func (*TypeRegistry) FindFuncType ¶
func (t *TypeRegistry) FindFuncType(meta *FunctionMeta) *DataType
func (*TypeRegistry) FindMapType ¶
func (t *TypeRegistry) FindMapType(key, val string) *DataType
func (*TypeRegistry) FindSliceType ¶
func (t *TypeRegistry) FindSliceType(name string) *DataType
func (*TypeRegistry) FindType ¶
func (t *TypeRegistry) FindType(name string) *DataType
func (*TypeRegistry) GetEnums ¶
func (t *TypeRegistry) GetEnums(name string) interface{}
func (*TypeRegistry) MakeChanType ¶
func (t *TypeRegistry) MakeChanType(name string) *DataType
func (*TypeRegistry) MakeFuncType ¶
func (t *TypeRegistry) MakeFuncType(meta *FunctionMeta) *DataType
func (*TypeRegistry) MakeMapType ¶
func (t *TypeRegistry) MakeMapType(key, val string) *DataType
func (*TypeRegistry) MakeSliceType ¶
func (t *TypeRegistry) MakeSliceType(name string) *DataType
Click to show internal directories.
Click to hide internal directories.