core

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPENONE   = 0
	TYPEINT    = 0x011
	TYPEBOOL   = 0x021
	TYPECHAR   = 0x031
	TYPESTR    = 0x042
	TYPEFLOAT  = 0x053
	TYPEARR    = 0x014
	TYPERANGE  = 0x024
	TYPEMAP    = 0x034
	TYPEBUF    = 0x044
	TYPEFUNC   = 0x054
	TYPEERROR  = 0x064
	TYPESET    = 0x074
	TYPEOBJ    = 0x084
	TYPEFILE   = 0x094
	TYPEHANDLE = 0x0A4
	TYPESTRUCT = 0x104

	BlBreak    = 0x0001
	BlContinue = 0x0002
	BlVars     = 0x0004
	BlPars     = 0x0008
	BlTry      = 0x0010
	BlRecover  = 0x0020
	BlRetry    = 0x0040
)
View Source
const (
	STACKNONE = iota
	STACKINT
	STACKSTR
	STACKFLOAT
	STACKANY
)
View Source
const (
	NOP       = iota
	PUSH32    // + int32
	PUSH64    // + int64
	PUSHFLOAT // + float64
	PUSHSTR   // & (strid << 16 )
	PUSHFUNC  // + id func
	ADD       // int + int
	SUB       // int - int
	MUL       // int * int
	DIV       // int / int
	MOD       // int % int     10
	BITOR     // int | int
	BITXOR    // int ^ int
	BITAND    // int & int
	LSHIFT    // int << int
	RSHIFT    // int >> int
	BITNOT    // ^int
	SIGN      // -int
	EQ        // int == int
	LT        // int < int
	GT        // int > int      20
	NOT       // logical not 1 => 0, 0 => 1
	ADDFLOAT  // float + float
	SUBFLOAT  // float - float
	MULFLOAT  // float * float
	DIVFLOAT  // float / float
	SIGNFLOAT // -float
	EQFLOAT   // float == float
	LTFLOAT   // float < float
	GTFLOAT   // float > float
	ADDSTR    // str + str      30
	EQSTR     // str == str
	LTSTR     // str < str
	GTSTR     // str > str
	GETVAR    // & (block shift<<16) + int16 type + int16 index
	SETVAR    // & (block shift<<16) + int16 type + int16 index + int16 index count + int16 assign
	DUP       // & (type<<16) duplicate top
	POP       // & (type<<16) pop top
	CYCLE     // cycle counter
	JMP       // + int32 jump
	JZE       // + int32 jump if the top value is zero     40
	JNZ       // + int32 jump if the top value is not zero
	JEQ       // & (type<<16) + int32 jump if equals for case statement
	JMPOPT    // & (idvar<<16) jump if defined
	INITVARS  // & (flags<<16) initializing variables + offset break + offset continue +
	// parcount<<16 | var count +
	DELVARS   // delete variables
	OPTPARS   // & (count << 16) + {type<<16 | idvar}
	INITOBJ   // & (count<<16) create a new object + int16 type +int16 type item
	RANGE     // create range
	ARRAY     // &(count<<16) create array + int32 types
	LEN       // & (type<<16) length                        50
	FORINC    // & (index<<16) increment counter
	BREAK     // break
	CONTINUE  // continue
	RECOVER   // recover
	RETRY     // retry
	RET       // & (type<<16) return from function
	END       // end of the function
	CONSTBYID // + int32 id of the object
	CALLBYID  // & (par count<<16) + int32 id of the object
	GOBYID    // & (par count<<16) + int32 id of the object new thread + int32 type of pars   60
	EMBED     // & (embed id << 16) calls embedded func + int32 count for variadic funcs
	// + [variadic types]
	LOCAL // & (par count << 16)+ int32 offset
	CATCH
	IOTA // & (iota<<16)

	INDEX        // & (int32 count) + {(type input<<16) + result type}
	ASSIGNPTR    // & (int16 type << 16)
	ASSIGN       // & (int16 type << 16)
	ASSIGNADD    // int += int  & (int16 type << 16) str += str
	ASSIGNSUB    // int -= int
	ASSIGNMUL    // int *= int
	ASSIGNDIV    // int /= int
	ASSIGNMOD    // int %= int
	ASSIGNBITOR  // int |= int
	ASSIGNBITXOR // int ^= int
	ASSIGNBITAND // int &= int
	ASSIGNLSHIFT // int <<= int
	ASSIGNRSHIFT // int >>= int
	INCDEC

	EMBEDFUNC
)
View Source
const (
	ConstIotaID = iota
	ConstDepthID
	ConstCycleID
	ConstScriptID
)
View Source
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`
	// ConstScript is the script path
	ConstScript = `SCRIPT`
	// ConstVersion is the version of Gentee compiler
	ConstVersion   = `VERSION`
	ConstRecursive = `RECURSIVE`
	ConstOnlyFiles = `ONLYFILES`
	ConstOnlyDirs  = `ONLYDIRS`
	ConstRegExp    = `REGEXP`
	ConstCreate    = `CREATE`
	ConstTrunc     = `TRUNC`
	ConstReadonly  = `READONLY`

	// NotIota means that constant doesn't use IOTA
	NotIota = -1

	// Version is the current version of the compiler
	Version = `1.20.0+2`
)
View Source
const (
	// RcBreak means break command
	RcBreak = 1 + iota
	// RcContinue means continue command
	RcContinue
	// RcLocal means that a local function returns a value
	RcLocal
	// RcRecover means recover command
	RcRecover
	// RcRetry means retry command
	RcRetry
)
View Source
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
	// StackSwitch is the switch statement
	StackSwitch
	// StackCase is the case statement
	StackCase
	// StackDefault is the default statement of switch
	StackDefault
	// 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
	// StackInitPtr inits array and map variables
	StackInitPtr
	// StackNew creates a new array or map
	StackNew
	// StackOptional is used for initialization of optional variables
	StackOptional
	// StackLocal means local function
	StackLocal
	// StackCallLocal means calling local function
	StackCallLocal
	// StackLocret returns value from local function
	StackLocret
	// StackTry is the try statement
	StackTry
	// StackCatch is the try statement
	StackCatch
)
View Source
const (
	// DefAssignAddArr appends the array to array
	DefAssignAddArr = `AssignAddºArr`
	// DefAssignAddArrArr appends the array to array
	DefAssignAddArrArr = `AssignAddºArrArr`
	// DefAssignAddMap appends the map to array
	DefAssignAddMap = `AssignAddºArrMap`
	// DefAssignArr assigns one array to another
	DefAssignArr = `AssignºArrArr`
	// DefAssignMap assigns one map to another
	DefAssignMap = `AssignºMapMap`
	// DefLenArr returns the length of the array
	DefLenArr = `LenºArr`
	// DefLenMap returns the length of the map
	DefLenMap = `LenºMap`
	// DefAssignIntInt equals int = int
	DefAssignIntInt = `#Assign#int#int`
	// DefAssignStructStruct equals struct = struct
	DefAssignStructStruct = `AssignºStructStruct`
	// DefAssignBitAndStructStruct equals struct &= struct
	DefAssignBitAndStructStruct = `AssignBitAndºStructStruct`
	// DefAssignFnFn equals fn = fn
	DefAssignFnFn = `AssignºFnFn`
	// DefAssignFileFile equals file = file
	DefAssignFileFile = `AssignºFileFile`
	// DefAssignHandleHandle equals handle = handle
	DefAssignHandleHandle = `AssignºHandleHandle`
	// DefAssignBitAndArrArr equals arr &= arr
	DefAssignBitAndArrArr = `AssignBitAndºArrArr`
	// DefAssignBitAndMapMap equals map &= map
	DefAssignBitAndMapMap = `AssignBitAndºMapMap`
	// DefNewKeyValue returns a pair of key value
	DefNewKeyValue = `NewKeyValue`
	// DefGetEnv returns an environment variable
	DefGetEnv = `GetEnv`
)
View Source
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
	// ErrNotRun is returned when the executing unit doesn't have run function
	ErrNotRun
	// ErrFnEmpty is returned in case of calling undefined fn variable
	ErrFnEmpty
	// ErrThreadIndex is returned when the index of the thread is out of range
	ErrThreadIndex
	// ErrThreadClosed is generated when the thread has been closed
	ErrThreadClosed
	// ErrPlatform is generated when the function is not supported on the current platform
	ErrPlatform
	// ErrObjValue is returned when obj has wrong type
	ErrObjValue

	// ErrEmbedded means golang error in embedded functions
	ErrEmbedded = 254
	// ErrRuntime error. It means bug
	ErrRuntime = 255
)
View Source
const (

	// NSImported means imported object in NameSpace
	NSImported = 0x10000000
	// NSPub means public object in NameSpace
	NSPub = 0x20000000

	NSIndex = 0x0fffffff
)

Prefixes

View Source
const (
	// DefName is the key name for stdlib
	DefName = `stdlib`

	// PubOne means the only next object is public
	PubOne = 1
	// PubAll means all objects are public
	PubAll = 2
)
View Source
const (
	// MaxSet is the maximum size of the set
	MaxSet = int64(64000000)
)
View Source
const (
	// Undefined index
	Undefined = -1
)

Variables

This section is empty.

Functions

func ErrFormat

func ErrFormat(path string, line, pos int, message string) string

ErrFormat is a function for formating error message

func IsVariadic

func IsVariadic(obj IObject) bool

IsVariadic returns true if th efunction is variadic

func RandName added in v1.14.0

func RandName() string

RandName returns random latin name

Types

type Array

type Array struct {
	Data []interface{}
}

Array is an array

func NewArray

func NewArray() *Array

NewArray creates a new array object

func (*Array) GetIndex added in v1.6.0

func (arr *Array) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Array) Len

func (arr *Array) Len() int

Len is part of sort.Interface.

func (*Array) Less

func (arr *Array) Less(i, j int) bool

Less is part of sort.Interface.

func (*Array) SetIndex added in v1.6.0

func (arr *Array) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

func (Array) String

func (arr Array) String() string

String interface for Array

func (*Array) Swap

func (arr *Array) Swap(i, j int)

Swap is part of sort.Interface.

type AssignAnyFunc added in v1.6.0

type AssignAnyFunc func(interface{}, interface{}) (interface{}, error)

type AssignFloatFunc added in v1.6.0

type AssignFloatFunc func(*float64, float64) (float64, error)

type AssignIntFunc added in v1.6.0

type AssignIntFunc func(*int64, int64) (int64, error)

type AssignStrFunc added in v1.6.0

type AssignStrFunc func(*string, interface{}) (string, error)

type Bcode added in v1.5.0

type Bcode int32

type Buffer

type Buffer struct {
	Data []byte
}

Buffer is []byte

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new buffer object

func (*Buffer) GetIndex added in v1.6.0

func (buf *Buffer) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Buffer) Len added in v1.6.0

func (buf *Buffer) Len() int

Len is part of sort.Interface.

func (*Buffer) SetIndex added in v1.6.0

func (buf *Buffer) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

func (Buffer) String

func (buf Buffer) String() string

String interface for Buffer

type Bytecode added in v1.5.0

type Bytecode struct {
	Code          []Bcode
	Used          map[int32]byte // identifier of used objects
	Init          []int32        // offsets of init funcs
	Strings       map[string]uint16
	StrOffset     []int32 // offsets of PUSHSTR
	Structs       map[string]uint16
	StructsList   []StructInfo
	StructsOffset []int32 // offsets of struct types
	Locals        []Local
	BlockFlags    int16
	Pos           []CodePos
}

Bytecode contains bytecode information

type CmdAnyFunc

type CmdAnyFunc struct {
	CmdCommon
	Object   IObject
	Result   *TypeObject
	Children []ICmd
	FnVar    ICmd
	Optional []int // indexes of optional variables
	IsThread bool
}

CmdAnyFunc calls a function with more than 2 parameters

func (*CmdAnyFunc) GetObject

func (cmd *CmdAnyFunc) GetObject() IObject

GetObject returns Object

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 the index of the token

func (*CmdAnyFunc) GetType

func (cmd *CmdAnyFunc) GetType() CmdType

GetType returns CtFunc

type CmdBinary

type CmdBinary struct {
	CmdCommon
	Object IObject
	Result *TypeObject
	Left   ICmd
	Right  ICmd
}

CmdBinary calls a binary function

func (*CmdBinary) GetObject

func (cmd *CmdBinary) GetObject() IObject

GetObject returns Object

func (*CmdBinary) GetResult

func (cmd *CmdBinary) GetResult() *TypeObject

GetResult returns the type of the result

func (*CmdBinary) GetToken

func (cmd *CmdBinary) GetToken() int

GetToken returns the index of the token

func (*CmdBinary) GetType

func (cmd *CmdBinary) GetType() CmdType

GetType returns CtBinary

type CmdBlock

type CmdBlock struct {
	CmdCommon
	Parent     *CmdBlock
	Object     IObject
	ID         uint32 // cmdType
	Vars       []*TypeObject
	ParCount   int // the count of parameters
	Variadic   bool
	VarNames   map[string]int
	Optional   map[string]int
	Result     *TypeObject
	Locals     []ICmd
	LocalNames map[string]int
	Children   []ICmd
}

CmdBlock calls a stack command

func (*CmdBlock) GetObject

func (cmd *CmdBlock) GetObject() IObject

GetObject returns nil

func (*CmdBlock) GetResult

func (cmd *CmdBlock) GetResult() *TypeObject

GetResult returns result

func (*CmdBlock) GetToken

func (cmd *CmdBlock) GetToken() int

GetToken returns the index of the token

func (*CmdBlock) GetType

func (cmd *CmdBlock) GetType() CmdType

GetType returns CtStack

type CmdCommand

type CmdCommand struct {
	CmdCommon
	ID uint32 // id of the command
}

CmdCommand is a runtime command

func (*CmdCommand) GetObject

func (cmd *CmdCommand) GetObject() IObject

GetObject returns nil

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

func (*CmdCommand) GetType

func (cmd *CmdCommand) GetType() CmdType

GetType returns CtCommand

type CmdCommon

type CmdCommon struct {
	TokenID uint32 // the index of the token in lexeme
}

CmdCommon is a common structure for all commands

type CmdConst

type CmdConst struct {
	CmdCommon
	Object IObject
}

CmdConst pushes a value of the constant into stack

func (*CmdConst) GetObject

func (cmd *CmdConst) GetObject() IObject

GetObject returns nil

func (*CmdConst) GetResult

func (cmd *CmdConst) GetResult() *TypeObject

GetResult returns result

func (*CmdConst) GetToken

func (cmd *CmdConst) GetToken() int

GetToken returns the index of the token

func (*CmdConst) GetType

func (cmd *CmdConst) GetType() CmdType

GetType returns CtConst

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) GetObject

func (cmd *CmdUnary) GetObject() IObject

GetObject returns Object

func (*CmdUnary) GetResult

func (cmd *CmdUnary) GetResult() *TypeObject

GetResult returns the type of the result

func (*CmdUnary) GetToken

func (cmd *CmdUnary) GetToken() int

GetToken returns the index of the token

func (*CmdUnary) GetType

func (cmd *CmdUnary) GetType() CmdType

GetType returns CtUnary

type CmdValue

type CmdValue struct {
	CmdCommon
	Value  interface{}
	Result *TypeObject
}

CmdValue pushes a value into stack

func (*CmdValue) GetObject

func (cmd *CmdValue) GetObject() IObject

GetObject returns nil

func (*CmdValue) GetResult

func (cmd *CmdValue) GetResult() *TypeObject

GetResult returns result

func (*CmdValue) GetToken

func (cmd *CmdValue) GetToken() int

GetToken returns the index of the token

func (*CmdValue) GetType

func (cmd *CmdValue) GetType() CmdType

GetType returns CtValue

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

func (*CmdVar) GetObject

func (cmd *CmdVar) GetObject() IObject

GetObject returns nil

func (*CmdVar) GetResult

func (cmd *CmdVar) GetResult() *TypeObject

GetResult returns result

func (*CmdVar) GetToken

func (cmd *CmdVar) GetToken() int

GetToken returns the index of the token

func (*CmdVar) GetType

func (cmd *CmdVar) GetType() CmdType

GetType returns CtValue

type CodePos added in v1.6.0

type CodePos struct {
	Offset int32  // byte code position
	Path   uint16 // Path index
	Name   uint16 // Name index
	Line   uint16 // Line
	Column uint16 // Column
}

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) GetCode added in v1.5.0

func (constObj *ConstObject) GetCode() *Bytecode

GetCode returns the Bytecode structure

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) 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) GetUnitIndex

func (constObj *ConstObject) GetUnitIndex() uint32

GetUnitIndex returns the index of the unit of this object

func (*ConstObject) Result

func (constObj *ConstObject) Result() *TypeObject

Result returns the type of the result

func (*ConstObject) SetPub

func (constObj *ConstObject) SetPub()

SetPub set Pub state

type Embed added in v1.6.0

type Embed struct {
	Name     string      // name of the function
	Pars     string      // parameters with comma delimiter
	Ret      string      // result type
	Code     uint32      // Bytecode (if Func == nil) or function index
	Func     interface{} // golang function
	Return   uint16      // the type of the result
	Params   []uint16    // the types of parameters
	Variadic bool        // variadic function
	Runtime  bool        // the first parameter is rt
	CanError bool        // can generate error
}

Embed contains information about the golang function

type EmbedObject

type EmbedObject struct {
	Object
	Func     interface{}   // golang function
	Return   *TypeObject   // the type of the result
	Params   []*TypeObject // the types of parameters
	Variadic bool          // variadic function
	Runtime  bool          // the first parameter is rt
	CanError bool          // can generate error
}

EmbedObject contains information about the golang function

func (*EmbedObject) GetCode added in v1.5.0

func (embedObj *EmbedObject) GetCode() *Bytecode

GetCode returns the Bytecode structure

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) 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) GetUnitIndex

func (embedObj *EmbedObject) GetUnitIndex() uint32

GetUnitIndex returns the index of the unit of this object

func (*EmbedObject) Result

func (embedObj *EmbedObject) Result() *TypeObject

Result returns the type of the result

func (*EmbedObject) SetPub

func (embedObj *EmbedObject) SetPub()

SetPub set Pub state

type Exec added in v1.5.0

type Exec struct {
	Code    []Bcode
	Funcs   map[int32]int32
	Init    []int32  // offsets of init funcs (initializing constants)
	Strings []string // string resources
	Structs []StructInfo
	Pos     []CodePos
	Path    string

	CRCStdlib uint64
	CRCCustom uint64
}

type File added in v1.19.0

type File struct {
	Name   string
	Handle *os.File
}

File is a file structure

func NewFile added in v1.19.0

func NewFile() *File

NewFile creates a new file object

func (File) String added in v1.19.0

func (file File) String() string

String interface for File

type Fn added in v1.1.0

type Fn struct {
	Func IObject
}

Fn is used for custom func types

func NewFn added in v1.1.0

func NewFn(ptype *TypeObject) *Fn

NewFn creates a new func var

type FnType added in v1.1.0

type FnType struct {
	Params []*TypeObject // Types of parameters
	Result *TypeObject   // Type of return value
}

FnType is used for func types

type FuncObject

type FuncObject struct {
	Object
	Block CmdBlock
}

FuncObject contains information about the function

func (*FuncObject) GetCode added in v1.5.0

func (funcObj *FuncObject) GetCode() *Bytecode

GetCode returns the Bytecode structure

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) 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) GetUnitIndex

func (funcObj *FuncObject) GetUnitIndex() uint32

GetUnitIndex returns the index of the unit of this object

func (*FuncObject) Result

func (funcObj *FuncObject) Result() *TypeObject

Result returns the type of the result

func (*FuncObject) SetPub

func (funcObj *FuncObject) SetPub()

SetPub set Pub state

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
	Result() *TypeObject
	GetLex() *Lex
	GetParams() []*TypeObject
	GetType() ObjectType
	SetPub()
	GetUnitIndex() uint32
	GetCode() *Bytecode
}

IObject describes interface for all objects

type Indexer added in v1.6.0

type Indexer interface {
	Len() int
	GetIndex(interface{}) (interface{}, bool)
	SetIndex(interface{}, interface{}) int
}

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

func (lp Lex) LineColumn(ind int) (line int, column int)

LineColumn return the line and the column of the ind-th token

func (*Lex) NewToken

func (lp *Lex) NewToken(token, offset, length int)

NewToken appends a new token to lexems

func (*Lex) NewTokens

func (lp *Lex) NewTokens(offset int, tokens ...int)

NewTokens appends one-byte new tokens to lexems

type Local added in v1.6.0

type Local struct {
	Cmd    *CmdBlock
	Offset int
}

type Map

type Map struct {
	Keys []string // it is required for 'for' statement and String interface
	Data map[string]interface{}
}

Map is a map

func NewMap

func NewMap() *Map

NewMap creates a new map object

func (*Map) GetIndex added in v1.6.0

func (pmap *Map) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Map) Len added in v1.6.0

func (pmap *Map) Len() int

Len is part of Indexer interface.

func (*Map) SetIndex added in v1.6.0

func (pmap *Map) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

func (Map) String

func (pmap Map) String() string

String interface for Map

type Obj added in v1.8.0

type Obj struct {
	Data interface{}
}

Object is an object

func NewObj added in v1.8.0

func NewObj() *Obj

NewObj creates a new object

func (*Obj) GetIndex added in v1.8.0

func (obj *Obj) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Obj) Len added in v1.8.0

func (obj *Obj) Len() int

Len is part of sort.Interface.

func (*Obj) SetIndex added in v1.8.0

func (obj *Obj) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

func (Obj) String added in v1.8.0

func (pobj Obj) String() string

String interface for Obj

type Object

type Object struct {
	Name  string
	Unit  *Unit
	Pub   bool  // public object
	ObjID int32 // index in Objects
	BCode Bytecode
}

Object contains information 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 Range

type Range struct {
	From int64
	To   int64
}

Range is the type for operator ..

func (*Range) GetIndex added in v1.6.0

func (prange *Range) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Range) Len added in v1.6.0

func (prange *Range) Len() int

Len is part of Indexer interface.

func (*Range) SetIndex added in v1.6.0

func (prange *Range) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

type RuntimeError

type RuntimeError struct {
	ID      int
	Message string
	Trace   []TraceInfo
}

RuntimeError is a runtime error type

func (*RuntimeError) Error

func (re *RuntimeError) Error() string

type Set added in v1.3.0

type Set struct {
	Data []uint64
}

Set is []bool

func NewSet added in v1.3.0

func NewSet() *Set

NewSet creates a new set object

func (*Set) GetIndex added in v1.6.0

func (set *Set) GetIndex(index interface{}) (interface{}, bool)

GetIndex is part of Indexer interface.

func (*Set) IsSet added in v1.3.0

func (set *Set) IsSet(index int64) bool

IsSet returns the value of set[index]

func (*Set) Len added in v1.6.0

func (set *Set) Len() int

Len is part of sort.Interface.

func (*Set) Set added in v1.3.0

func (set *Set) Set(index int64, b bool) bool

Set sets the value of set[index]

func (*Set) SetIndex added in v1.6.0

func (set *Set) SetIndex(index, value interface{}) int

SetIndex is part of Indexer interface.

func (Set) String added in v1.3.0

func (set Set) String() string

String interface for Set

type Struct

type Struct struct {
	Type   *TypeObject
	Values []interface{} // Values of fields
}

Struct is used for custom struct types

func (Struct) String

func (pstruct Struct) String() string

String interface for Struct

type StructInfo added in v1.6.0

type StructInfo struct {
	Name   string
	Fields []uint16 // types
	Keys   []string
}

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 TraceInfo

type TraceInfo struct {
	Path  string // the full path name of the source
	Entry string // the entry function name
	Func  string // the called function
	Line  int    // line position in the source
	Pos   int    // column position in the line
}

TraceInfo is a structure for stack func info

type TypeObject

type TypeObject struct {
	Object
	Original reflect.Type // Original golang type
	IndexOf  *TypeObject  // consists of elements
	Custom   *StructType  // for custom struct type
	Func     *FnType      // for func type
}

TypeObject contains information about the type

func (*TypeObject) GetCode added in v1.5.0

func (typeObj *TypeObject) GetCode() *Bytecode

GetCode returns the Bytecode structure

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) 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) GetUnitIndex

func (typeObj *TypeObject) GetUnitIndex() uint32

GetUnitIndex returns the index of the unit of this object

func (*TypeObject) Result

func (typeObj *TypeObject) Result() *TypeObject

Result returns the type of the result

func (*TypeObject) SetPub

func (typeObj *TypeObject) SetPub()

SetPub set Pub state

type Unit

type Unit struct {
	VM        *Workspace
	Index     uint32            // Index of the Unit
	NameSpace map[string]uint32 // name space of the unit
	Included  map[uint32]bool   // false - included or true - imported units
	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
	Pub       int               // Public mode
}

Unit is a common structure for source code

func (*Unit) AddConst

func (unit *Unit) AddConst(name string)

AddConst appends a constant to NameSpace

func (*Unit) AddFunc

func (unit *Unit) AddFunc(ind int, obj IObject, pub bool)

AddFunc appends func to NameSpace

func (*Unit) FindConst

func (unit *Unit) FindConst(name string) IObject

FindConst returns the constant object with the specified name

func (*Unit) FindFunc

func (unit *Unit) FindFunc(name string, params []*TypeObject) (IObject, bool)

FindFunc returns the function with the specified name and parameters

func (*Unit) FindObj

func (unit *Unit) FindObj(fullName string) IObject

FindObj returns the object by its name

func (*Unit) FindType

func (unit *Unit) FindType(name string) IObject

FindType returns the type object with the specified name

func (*Unit) GetHeader added in v1.7.0

func (unit *Unit) GetHeader(name string) string

func (*Unit) GetObj

func (unit *Unit) GetObj(ind uint32) IObject

GetObj returns the object by its index

func (*Unit) ImportEmbed added in v1.7.0

func (unit *Unit) ImportEmbed(embed Embed)

ImportEmbed imports Embed funcs to Unit

func (*Unit) NameToType

func (unit *Unit) NameToType(name string) IObject

NameToType searches the type by its name. It accepts names like name.name.name. It creates a new type if it absents.

func (*Unit) NewConst

func (unit *Unit) NewConst(name string, value interface{}, redefined bool) int32

NewConst adds a new ConstObject to Unit

func (*Unit) NewObject

func (unit *Unit) NewObject(obj IObject) IObject

NewObject adds a new IObject to Unit

func (*Unit) NewType

func (unit *Unit) NewType(name string, original reflect.Type, indexOf IObject) IObject

NewType adds a new type to Unit

func (*Unit) TypeByGoType

func (unit *Unit) TypeByGoType(goType reflect.Type) *TypeObject

TypeByGoType returns the type by the go type name

type Workspace added in v1.5.0

type Workspace struct {
	Units     []*Unit
	UnitNames map[string]int
	Objects   []IObject
	Linked    map[string]int // compiled files
	IotaID    int32
	Embedded  []Embed
}

Workspace contains information of compiled source code

func NewVM

func NewVM(Embedded []Embed) *Workspace

NewVM returns a new virtual machine

func (*Workspace) InitUnit added in v1.5.0

func (ws *Workspace) InitUnit() *Unit

InitUnit initialize a unit structure

func (*Workspace) StdLib added in v1.5.0

func (ws *Workspace) StdLib() *Unit

StdLib returns the pointer to Standard Library Unit

func (*Workspace) Unit added in v1.5.0

func (ws *Workspace) Unit(name string) *Unit

Unit returns the pointer to Unit by its name

Jump to

Keyboard shortcuts

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