compiler

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrSuccess means no error
	ErrSuccess = iota
	// ErrDecl is returned when the unexpexted token has been found on the top level
	ErrDecl
	// ErrLCurly is returned when the unexpexted token, expecting {
	ErrLCurly
	// ErrEnd is returned when the unexpexted end of the source, expecting }
	ErrEnd
	// ErrExp is returned when the unexpected token, expecting expression or statement {
	ErrExp
	// ErrName is return when compiler is expecting the identifier
	ErrName
	// ErrValue is returned when the unexpected token, expecting value, identifier or calling func
	ErrValue
	// ErrRun is returned when the compiler has found the second run function.
	ErrRun
	// ErrType is returned when the unexpected token, expecting type name
	ErrType
	// ErrReturn is returned when the function returns a value but it must not return
	ErrReturn
	// ErrMustReturn is returned when the function doesn't return a value but it must return
	ErrMustReturn
	// ErrReturnType is returned when the function returns a wrong type
	ErrReturnType
	// ErrOutOfRange is returned when the number is out of range
	ErrOutOfRange
	// ErrLPar is returned when there is an unclosed left parenthesis
	ErrLPar
	// ErrRPar is returned when extra right parenthesis has been found
	ErrRPar
	// ErrLSBracket is returned when there is an unclosed left square bracket
	ErrLSBracket
	// ErrRSBracket is returned when extra right square bracket has been found
	ErrRSBracket
	// ErrEmptyCode is returned when the source code is empty
	ErrEmptyCode
	// ErrFunction is returned when the compiler could not find a corresponding function
	ErrFunction
	// ErrBoolExp is returned when the compiler expects boolean result but gets different type
	ErrBoolExp
	// ErrFuncExists is returned when the function ahs already been defined
	ErrFuncExists
	// ErrUsedName is returned when the specified name has already been used
	ErrUsedName
	// ErrUnknownIdent is returned when the compiler gets unknown identifier
	ErrUnknownIdent
	// ErrLValue is returned when left operand of assign is not l-value
	ErrLValue
	// ErrOper is return when there is not operator
	ErrOper
	// ErrBoolOper is returned when && or || gets not boolen operands
	ErrBoolOper
	// ErrQuestion is returned when exp1 and exp2 have different types
	ErrQuestion
	// ErrQuestionPars is returned when ?(condition,exp1,exp2) has wrong parameters
	ErrQuestionPars
	// ErrCapitalLetters is returned when the var or func name consists of only capital letters
	ErrCapitalLetters
	// ErrConstName is returned when the name of constant doesn't consist of only capital letters
	ErrConstName
	// ErrMustAssign is returned when the constant is described without assign
	ErrMustAssign
	// ErrIota is returned when IOTA is used outside const expression
	ErrIota
	// ErrIntOper is returned when ++ or -- gets not int value
	ErrIntOper
	// ErrDoubleQuotes is returned when there is a wrong command of backslash in double quotes strings
	ErrDoubleQuotes
	// ErrLink is returned when the script with the same name but different path is already linked
	//	ErrLink
	// ErrConstDef is returned when the constant is redefined
	ErrConstDef
	// ErrChar means that the char literal has wrong format
	ErrChar
	// ErrNoIndex means that there is not a value for index
	ErrNoIndex
	// ErrVarIndex means that there is not a variable for indexing
	ErrVarIndex
	// ErrSupportIndex means that the type of the variable doesn't support indexing
	ErrSupportIndex
	// ErrTypeIndex means that the type of the index value is wrong
	ErrTypeIndex
	// ErrForIn is returned when 'in' is missing in for statement
	ErrForIn
	// ErrIdent is returned when the name contains a dot
	ErrIdent
	// ErrWrongType is returned when we get wrong type
	ErrWrongType
	// ErrNotKeyValue is returned when initialization of map value without
	ErrNotKeyValue
	// ErrKeyValue means that key:value is used outside of map initialization
	ErrKeyValue
	// ErrLineRCurly is returned when the unexpected token, expecting a new line or }
	ErrLineRCurly
	// ErrStructField is returned when the field with this name has already been defined
	ErrStructField
	// ErrTypeExists means that the type has already been defined
	ErrTypeExists
	// ErrStructType is returned when getting field of no struct type
	ErrStructType
	// ErrStruct is returned when struct type doesn't have such field
	ErrStruct
	// ErrStructAssign is returned if structures have different types in assign expression
	ErrStructAssign
	// ErrInitField means that wrong token specified as a field name of struct
	ErrInitField
	// ErrWrongField is returned when unknown field name has been specified
	ErrWrongField
	// ErrBreak returns when break is placed outside of loops
	ErrBreak
	// ErrContinue returns when continue is placed outside of loops
	ErrContinue
	// ErrNotRPar is returned when the compiler gets unexpected token instead of )
	ErrNotRPar
	// ErrNotCase is returned if case missing after switch
	ErrNotCase
	// ErrSwitchType means that type of switch statement is wrong
	ErrSwitchType
	// ErrString is returned when expecting a string value
	ErrString
	// ErrIncludeFile is returned when an include file is incorrect
	ErrIncludeFile
	// ErrDupObject is returned when the duplicate object has been found in include or import
	ErrDupObject
	// ErrImportStr is returned when the string contains an expression
	ErrImportStr
	// ErrNewLine is retuned is case of unexpected token instead of a new line
	ErrNewLine
	// ErrAddrFunc means wrong definition of function address
	ErrAddrFunc
	// ErrNoFuncType is returned when the type is not a fn type
	ErrNoFuncType
	// ErrFnReturn is returned when function and fn type return different types
	ErrFnReturn
	// ErrFnCall is returned when fn var is called with wrong parameters
	ErrFnCall
	// ErrOptional means that the optional variable is defined in the wrong place
	ErrOptional
	// ErrFuncOptional is returned when it doesn't have such optional variable
	ErrFuncOptional
	// ErrFnOptional is returned when fn variable use optional variables
	ErrFnOptional
	// ErrTypeOptional is returned when the optional variable has wrong type
	ErrTypeOptional
	// ErrTwiceOptional is returned when the optional variable is defined more than one time
	ErrTwiceOptional
	// ErrEndOptional is returned when optional parameters are not at the end`
	ErrEndOptional
	// ErrLocalName is returned when such local name has already existed
	ErrLocalName
	// ErrLocalVariadic is returned when there is a variadic parameter in local function
	ErrLocalVariadic
	// ErrGoParam is returned when there is an unnamed parameter in go statement
	ErrGoParam
	// ErrCatch is returned if catch missing after try
	ErrCatch
	// ErrRecover returns when recover is placed outside of catch
	ErrRecover
	// ErrRetry returns when recover is placed outside of catch
	ErrRetry
	// ErrLinkIndex is returned when linker gets incorrect unit index
	ErrLinkIndex
	// ErrFnBuildIn is returned when fn variable assigned to build-in function
	ErrFnBuildIn
	// ErrFnVariadic is returned when fn variable assigned to variadic function
	ErrFnVariadic

	// ErrCompiler error. It means a bug.
	ErrCompiler

	// ErrLetter is returned when an unknown character has been found
	ErrLetter = 0x100
	// ErrWord is returned when a sequence of characters is wrong
	ErrWord = 0x200
	// ErrEnvName is returned when a environment name ${NAME} is wrong
	ErrEnvName = 0x300
	// ErrDoubleColon is returned where there are two colons in one line
	ErrDoubleColon = 0x500
)

Variables

This section is empty.

Functions

func Compile

func Compile(ws *core.Workspace, input, path string) (int, error)

Compile compiles the source code

func CompileFile

func CompileFile(ws *core.Workspace, filename string) (unitID int, err error)

CompileFile compiles the source file

func InitEmbed added in v1.7.0

func InitEmbed(ws *core.Workspace)

InitEmbed imports in-line functions

func InitStdlib added in v1.7.0

func InitStdlib(ws *core.Workspace)

InitStdlib appends stdlib types and functions to the virtual machine

func InitTypes added in v1.7.0

func InitTypes(ws *core.Workspace)

InitTypes appends stdlib types to the virtual machine

func LexParsing

func LexParsing(input []rune) (*core.Lex, int)

LexParsing performs lexical analysis of the input string and returns a sequence of lexical tokens.

func Link(ws *core.Workspace, unitID int) (*core.Exec, error)

Link creates a bytecode

func NewStructType added in v1.7.0

func NewStructType(ws *core.Workspace, name string, fields []string) *core.TypeObject

NewStructType adds a new struct type to Unit

Types

type BlockInfo added in v1.6.0

type BlockInfo struct {
	Block   *core.CmdBlock
	Vars    []int
	IsLocal bool
}

BlockInfo describes block in the linker

type ExpBuf

type ExpBuf struct {
	Oper   int
	Pos    int
	LenExp int
}

ExpBuf is a structure for buffer of expression operations

type Int32Slice added in v1.6.0

type Int32Slice []int32

Int32Slice is a slice of int32

func (Int32Slice) Len added in v1.6.0

func (p Int32Slice) Len() int

func (Int32Slice) Less added in v1.6.0

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Swap added in v1.6.0

func (p Int32Slice) Swap(i, j int)

type Linker added in v1.5.0

type Linker struct {
	Blocks []BlockInfo
	Lex    *core.Lex
}

Linker is the main structure of the linker

type Priority

type Priority struct {
	Priority  int
	RightLeft bool
	Name      string
}

Priority is a structure for operations in expressions

type StateStack

type StateStack struct {
	Origin *cmState
	Pos    int
	State  int
}

StateStack is used for storing a sequence of states

Jump to

Keyboard shortcuts

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