Documentation ¶
Index ¶
- Constants
- func CopyVar(ptr *interface{}, value interface{})
- func ErrorText(id int) string
- type Array
- type Buffer
- type CmdAnyFunc
- type CmdBinary
- type CmdBlock
- type CmdCommand
- type CmdCommon
- type CmdConst
- type CmdRet
- type CmdType
- type CmdUnary
- type CmdValue
- type CmdVar
- type ConstObject
- func (constObj *ConstObject) GetLex() *Lex
- func (constObj *ConstObject) GetName() string
- func (constObj *ConstObject) GetNext() IObject
- func (constObj *ConstObject) GetParams() []*TypeObject
- func (constObj *ConstObject) GetType() ObjectType
- func (constObj *ConstObject) Result() *TypeObject
- func (constObj *ConstObject) SetNext(next IObject)
- type EmbedObject
- func (embedObj *EmbedObject) GetLex() *Lex
- func (embedObj *EmbedObject) GetName() string
- func (embedObj *EmbedObject) GetNext() IObject
- func (embedObj *EmbedObject) GetParams() []*TypeObject
- func (embedObj *EmbedObject) GetType() ObjectType
- func (embedObj *EmbedObject) Result() *TypeObject
- func (embedObj *EmbedObject) SetNext(next IObject)
- type FuncObject
- func (funcObj *FuncObject) GetLex() *Lex
- func (funcObj *FuncObject) GetName() string
- func (funcObj *FuncObject) GetNext() IObject
- func (funcObj *FuncObject) GetParams() []*TypeObject
- func (funcObj *FuncObject) GetType() ObjectType
- func (funcObj *FuncObject) Result() *TypeObject
- func (funcObj *FuncObject) SetNext(next IObject)
- type ICmd
- type IObject
- type KeyValue
- type Lex
- type Map
- type Object
- type ObjectType
- type Range
- type RunTime
- type RunTimeBlock
- type Struct
- type StructType
- type Token
- type TypeObject
- func (typeObj *TypeObject) GetLex() *Lex
- func (typeObj *TypeObject) GetName() (ret string)
- func (typeObj *TypeObject) GetNext() IObject
- func (typeObj *TypeObject) GetParams() []*TypeObject
- func (typeObj *TypeObject) GetType() ObjectType
- func (typeObj *TypeObject) Result() *TypeObject
- func (typeObj *TypeObject) SetNext(next IObject)
- type Unit
- func (unit *Unit) NameToType(name string) IObject
- func (unit *Unit) NewConst(name string, value interface{}, redefined bool)
- func (unit *Unit) NewEmbed(Func interface{})
- func (unit *Unit) NewEmbedExt(Func interface{}, in string, out string)
- func (unit *Unit) NewEmbedTypes(Func interface{}, inTypes []*TypeObject, outType *TypeObject)
- func (unit *Unit) NewObject(obj IObject) IObject
- func (unit *Unit) NewType(name string, original reflect.Type, indexOf IObject) IObject
- func (unit *Unit) TypeByGoType(goType reflect.Type) *TypeObject
- type UnitType
- type VirtualMachine
Constants ¶
const ( // ConstDepth is the name of the max depth of calling functions ConstDepth = `DEPTH` // ConstCycle is the name of the max count of cycle ConstCycle = `CYCLE` // ConstIota is the name of iota for constants ConstIota = `IOTA` // ConstVersion is the version of Gentee compiler ConstVersion = `VERSION` // NotIota means that constant doesn't use IOTA NotIota = -1 // Version is the current version of the compiler Version = `1.0.0-beta.1` )
const ( // RcBreak means break command RcBreak = 1 + iota // RcContinue means continue command RcContinue )
const ( // StackBlock executes function StackBlock = 1 + iota // StackReturn returns values from the function StackReturn // StackIf is the condition statement StackIf // StackWhile is the while statement StackWhile // StackAssign is an assign operator StackAssign // StackAnd is a logical AND StackAnd // StackOr is a logical OR StackOr // StackQuestion is ?(condition, exp1, exp2) StackQuestion // StackIncDec is ++ -- StackIncDec // StackFor is the for statement StackFor // StackInit inits array and map variables StackInit // StackNew creates a new array or map StackNew )
const ( // DefAssignIntInt equals int = int DefAssignIntInt = `AssignºIntInt` // DefAssignStructStruct equals struct = struct DefAssignStructStruct = `AssignºStructStruct` // DefNewKeyValue returns a pair of key value DefNewKeyValue = `NewKeyValue` )
const ( // ErrRunIndex is returned when Run has been executed with wrong index ErrRunIndex = iota + 1 // ErrDepth is returned when maximum depth of recursion has been reached ErrDepth // ErrDivZero is returned when there is division by zero ErrDivZero // ErrCycle is returned when maximum cycle count has been reached ErrCycle // ErrShift is returned when << or >> are used with the negative right operand ErrShift // ErrStrToInt is returned when the conversion string to integer is invalid ErrStrToInt // ErrStrToFloat is returned when the conversion string to float is invalid ErrStrToFloat // ErrEmptyCommand is returned if empty command is specified in $ ErrEmptyCommand // ErrQuoteCommand is returned if there is an unclosed quotation mark in $ command ErrQuoteCommand // ErrIndexOut means that int index is out of the length of the array ErrIndexOut // ErrMapIndex is returned when there is not the key in the map ErrMapIndex // ErrAssignment is returned when there is a recursive assignment ErrAssignment // ErrUndefined means that the value of the variable is undefined ErrUndefined // ErrByteOut is returned when value for buf is greater 255 ErrByteOut // ErrInvalidParam is returned when the function gets invalid parameter(s) ErrInvalidParam // ErrRuntime error. It means bug ErrRuntime )
const (
// DefName is the key name for stdlib
DefName = `stdlib`
)
const (
// Undefined index
Undefined = -1
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CmdAnyFunc ¶
type CmdAnyFunc struct { CmdCommon Object IObject Result *TypeObject Children []ICmd }
CmdAnyFunc calls a function with more than 2 parameters
func (*CmdAnyFunc) GetResult ¶
func (cmd *CmdAnyFunc) GetResult() *TypeObject
GetResult returns the type of the result
func (*CmdAnyFunc) GetToken ¶
func (cmd *CmdAnyFunc) GetToken() int
GetToken returns teh index of the token
type CmdBinary ¶
type CmdBinary struct { CmdCommon Object IObject Result *TypeObject Left ICmd Right ICmd }
CmdBinary calls a binary function
func (*CmdBinary) GetResult ¶
func (cmd *CmdBinary) GetResult() *TypeObject
GetResult returns the type of the result
type CmdBlock ¶
type CmdBlock struct { CmdCommon Parent *CmdBlock Object IObject ID uint32 // cmdType Vars []*TypeObject ParCount int // the count of parameters VarNames map[string]int Result *TypeObject Children []ICmd }
CmdBlock calls a stack command
type CmdCommand ¶
CmdCommand is a runtime command
func (*CmdCommand) GetResult ¶
func (cmd *CmdCommand) GetResult() *TypeObject
GetResult returns result
func (*CmdCommand) GetToken ¶
func (cmd *CmdCommand) GetToken() int
GetToken returns the index of the token
type CmdCommon ¶
type CmdCommon struct {
TokenID uint32 // the index of the token in lexeme
}
CmdCommon is a common structure for all commands
type CmdConst ¶
CmdConst pushes a value of the constant into stack
type CmdRet ¶
type CmdRet struct { Cmd ICmd // the value of the index Type *TypeObject // the type of the result }
CmdRet is the command for getting index values
type CmdType ¶
type CmdType uint32
CmdType is used for types of commands
const ( // CtValue pushes value into stack CtValue CmdType = iota + 1 // CtVar pushes the value of the variable into stack CtVar // CtConst pushes the value of the constant into stack CtConst // CtStack is a stack command CtStack // CtUnary is an unary function CtUnary // CtBinary is binary function CtBinary // CtFunc is other functions CtFunc // CtCommand is a command of vm like break continue CtCommand )
type CmdUnary ¶
type CmdUnary struct { CmdCommon Object IObject Result *TypeObject Operand ICmd }
CmdUnary calls an unary function
func (*CmdUnary) GetResult ¶
func (cmd *CmdUnary) GetResult() *TypeObject
GetResult returns the type of the result
type CmdValue ¶
type CmdValue struct { CmdCommon Value interface{} Result *TypeObject }
CmdValue pushes a value into stack
type CmdVar ¶
type CmdVar struct { CmdCommon Block *CmdBlock // pointer to the block of the variable Index int // the index of the variable in the block Indexes []CmdRet // the indexes list of the variable }
CmdVar pushes the value of the variable into stack
type ConstObject ¶
type ConstObject struct { Object Redefined bool Exp ICmd // expression Return *TypeObject // the type of the constant Iota int64 // iota }
ConstObject contains information about the constant
func (*ConstObject) GetLex ¶
func (constObj *ConstObject) GetLex() *Lex
GetLex returns the lex structure of the object
func (*ConstObject) GetName ¶
func (constObj *ConstObject) GetName() string
GetName returns the name of the object
func (*ConstObject) GetNext ¶
func (constObj *ConstObject) GetNext() IObject
GetNext returns the next object with the same name
func (*ConstObject) GetParams ¶
func (constObj *ConstObject) GetParams() []*TypeObject
GetParams returns the slice of parameters
func (*ConstObject) GetType ¶
func (constObj *ConstObject) GetType() ObjectType
GetType returns ObjType
func (*ConstObject) Result ¶
func (constObj *ConstObject) Result() *TypeObject
Result returns the type of the result
func (*ConstObject) SetNext ¶
func (constObj *ConstObject) SetNext(next IObject)
SetNext sets the next with the same name
type EmbedObject ¶
type EmbedObject struct { Object Func interface{} // golang function Return *TypeObject // the type of the result Params []*TypeObject // the types of parameters }
EmbedObject contains information about the golang function
func (*EmbedObject) GetLex ¶
func (embedObj *EmbedObject) GetLex() *Lex
GetLex returns the lex structure of the object
func (*EmbedObject) GetName ¶
func (embedObj *EmbedObject) GetName() string
GetName returns the name of the object
func (*EmbedObject) GetNext ¶
func (embedObj *EmbedObject) GetNext() IObject
GetNext returns the next object with the same name
func (*EmbedObject) GetParams ¶
func (embedObj *EmbedObject) GetParams() []*TypeObject
GetParams returns the slice of parameters
func (*EmbedObject) GetType ¶
func (embedObj *EmbedObject) GetType() ObjectType
GetType returns ObjEmbedded
func (*EmbedObject) Result ¶
func (embedObj *EmbedObject) Result() *TypeObject
Result returns the type of the result
func (*EmbedObject) SetNext ¶
func (embedObj *EmbedObject) SetNext(next IObject)
SetNext sets the next with the same name
type FuncObject ¶
FuncObject contains information about the function
func (*FuncObject) GetLex ¶
func (funcObj *FuncObject) GetLex() *Lex
GetLex returns the lex structure of the object
func (*FuncObject) GetName ¶
func (funcObj *FuncObject) GetName() string
GetName returns the name of the object
func (*FuncObject) GetNext ¶
func (funcObj *FuncObject) GetNext() IObject
GetNext returns the next object with the same name
func (*FuncObject) GetParams ¶
func (funcObj *FuncObject) GetParams() []*TypeObject
GetParams returns the slice of parameters
func (*FuncObject) GetType ¶
func (funcObj *FuncObject) GetType() ObjectType
GetType returns ObjFunc
func (*FuncObject) Result ¶
func (funcObj *FuncObject) Result() *TypeObject
Result returns the type of the result
func (*FuncObject) SetNext ¶
func (funcObj *FuncObject) SetNext(next IObject)
SetNext sets the next with the same name
type ICmd ¶
type ICmd interface { GetType() CmdType GetResult() *TypeObject GetObject() IObject GetToken() int }
ICmd is an interface for stack commands
type IObject ¶
type IObject interface { GetName() string GetNext() IObject Result() *TypeObject GetLex() *Lex GetParams() []*TypeObject GetType() ObjectType SetNext(IObject) }
IObject describes interface for all objects
type KeyValue ¶
type KeyValue struct { Key interface{} Value interface{} }
KeyValue is the type for key value :
type Lex ¶
type Lex struct { Source []rune Tokens []Token Lines []int // offsets of lines Strings []string // array of constant strings Header string // # header Path string // full path to the source }
Lex contains the result of the lexical parsing
func (Lex) LineColumn ¶
LineColumn return the line and the column of the ind-th token
type Map ¶
type Map struct { Keys []string // it is required for 'for' statement and String interface Data map[string]interface{} }
Map is a map
type Object ¶
type Object struct { // Type ObjectType Name string Next IObject // Next object with the same name LexID int // the identifier of source code in Lexeme of Unit Unit *Unit }
Object contains infromation about any compiled object of the virtual machine
type ObjectType ¶
type ObjectType int
ObjectType is used for types of objects
const ( // ObjType is a type ObjType ObjectType = iota + 1 // ObjEmbedded is a embedded golang function ObjEmbedded // ObjFunc is a gentee function ObjFunc // ObjConst is a constant ObjConst )
type RunTime ¶
type RunTime struct { VM *VirtualMachine Stack []interface{} // the stack of values Calls []ICmd // the stack of calling functions Blocks []RunTimeBlock Result interface{} // result value Command uint32 Consts map[string]interface{} }
RunTime is the structure for running compiled functions
type RunTimeBlock ¶
type RunTimeBlock struct { Vars []interface{} Block *CmdBlock }
RunTimeBlock is a structure for storing variables
type Struct ¶
type Struct struct { Type *TypeObject Values []interface{} // Values of fields }
Struct is used for custom struct types
type StructType ¶
type StructType struct { Fields map[string]int64 // Names of fields with indexes of the order Types []*TypeObject // Types of fields }
StructType is used for custom struct types
type Token ¶
type Token struct { Type int32 Index int32 // index in Lex.Strings if Type is tkStr Offset int Length int }
Token is a lexical token.
type TypeObject ¶
type TypeObject struct { Object Original reflect.Type // Original golang type IndexOf *TypeObject // consists of elements Custom *StructType // for custom struct type }
TypeObject contains information about the type
func (*TypeObject) GetLex ¶
func (typeObj *TypeObject) GetLex() *Lex
GetLex returns the lex structure of the object
func (*TypeObject) GetName ¶
func (typeObj *TypeObject) GetName() (ret string)
GetName returns the name of the object
func (*TypeObject) GetNext ¶
func (typeObj *TypeObject) GetNext() IObject
GetNext returns the next object with the same name
func (*TypeObject) GetParams ¶
func (typeObj *TypeObject) GetParams() []*TypeObject
GetParams returns the slice of parameters
func (*TypeObject) GetType ¶
func (typeObj *TypeObject) GetType() ObjectType
GetType returns ObjType
func (*TypeObject) Result ¶
func (typeObj *TypeObject) Result() *TypeObject
Result returns the type of the result
func (*TypeObject) SetNext ¶
func (typeObj *TypeObject) SetNext(next IObject)
SetNext sets the next with the same name
type Unit ¶
type Unit struct { Type UnitType Objects []IObject Names map[string]IObject Lexeme []*Lex // The array of source code RunID int // The index of run function. Undefined (-1) - run has not yet been defined Name string // The name of the unit }
Unit is a common structure for Library and Run packages
func (*Unit) NameToType ¶
NameToType searches the type by its name. It accepts names like name.name.name. It creates a new type if it absents.
func (*Unit) NewEmbed ¶
func (unit *Unit) NewEmbed(Func interface{})
NewEmbed adds a new EmbedObject to Unit
func (*Unit) NewEmbedExt ¶
NewEmbedExt adds a new EmbedObject to Unit with string types
func (*Unit) NewEmbedTypes ¶
func (unit *Unit) NewEmbedTypes(Func interface{}, inTypes []*TypeObject, outType *TypeObject)
NewEmbedTypes adds a new EmbedObject to Unit with types
func (*Unit) TypeByGoType ¶
func (unit *Unit) TypeByGoType(goType reflect.Type) *TypeObject
TypeByGoType returns the type by the go type name
type VirtualMachine ¶
type VirtualMachine struct { Units []*Unit Names map[string]int Compiled int // the index of the latest compiled unit }
VirtualMachine contains information of compiled source code
func (*VirtualMachine) Run ¶
func (vm *VirtualMachine) Run(name string) (interface{}, error)
Run executes run block
func (*VirtualMachine) StdLib ¶
func (vm *VirtualMachine) StdLib() *Unit
StdLib returns the pointer to Standard Library Unit
func (*VirtualMachine) Unit ¶
func (vm *VirtualMachine) Unit(name string) *Unit
Unit returns the pointer to Unit by its name