interpreter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignementTypeChecking

func AssignementTypeChecking(tree parser.VariableAssignStmt, type1 string, type2 string, env *Env) bool

AssignementTypeChecking checks if the type of the variable is the same as the type of the expression. If the type of the variable is any, it returns true else it returns false.

func HandleError

func HandleError(tree parser.VariableAssignStmt, err error, env *Env)

TODO : Remove this function @mkarten

func IndexableAssignmentChecks

func IndexableAssignmentChecks(index parser.IndexableAccessExpr, env *Env) *eclaType.Type

IndexableAssignmentChecks checks if the indexable variable is valid

func IsMultipleBus

func IsMultipleBus(b []*Bus) bool

IsMultipleBus returns true if the bus is a multiple bus.

func Load

func Load(env *Env)

Load executes import statements with their environment.

func Run

func Run(env *Env)

Run executes the environment.

func RunBodyFunction

func RunBodyFunction(fn *eclaType.Function, env *Env) ([]eclaType.Type, error)

RunBodyFunction executes the code associated with the function.

func RunFunctionCallExprWithArgs

func RunFunctionCallExprWithArgs(Name string, env *Env, fn *eclaType.Function, args []eclaType.Type) ([]eclaType.Type, error)

RunFunctionCallExprWithArgs executes a parser.FunctionCallExpr with the given arguments.

func RunFunctionDecl

func RunFunctionDecl(tree parser.FunctionDecl, env *Env)

RunFunctionDecl executes a parser.FunctionDecl.

func RunImportStmt

func RunImportStmt(stmt parser.ImportStmt, env *Env)

RunImportStmt executes a parser.ImportStmt.

func RunMurlocStmt

func RunMurlocStmt(stmt parser.MurlocStmt, env *Env)

RunMurlocStmt executes a parser.MurlocStmt.

func RunReturnStmt

func RunReturnStmt(tree parser.ReturnStmt, env *Env) []eclaType.Type

RunReturnStmt runs the return statement

func RunStructDecl

func RunStructDecl(tree parser.StructDecl, env *Env)

func RunVariableAssignStmt

func RunVariableAssignStmt(tree parser.VariableAssignStmt, env *Env)

RunVariableAssignStmt Run assigns a variable.

func RunVariableDecl

func RunVariableDecl(tree parser.VariableDecl, env *Env)

RunVariableDecl executes a parser.VariableDecl.

Types

type Bus

type Bus struct {
	Type BusType
	Val  eclaType.Type
}

func New

func New(t parser.Literal, env *Env) *Bus

New returns a new eclaType.Type from a parser.Literal.

func NewMainBus

func NewMainBus(Val eclaType.Type) *Bus

NewMainBus returns a new main bus.

func NewNoneBus

func NewNoneBus() *Bus

NewNoneBus returns the Global none bus.

func NewReturnBus

func NewReturnBus(Val eclaType.Type) *Bus

NewReturnBus returns a new return bus.

func RunAnonymousFunctionCallExpr

func RunAnonymousFunctionCallExpr(tree parser.AnonymousFunctionCallExpr, env *Env) []*Bus

func RunAnonymousFunctionExpr

func RunAnonymousFunctionExpr(AnonymousFunc parser.AnonymousFunctionExpr, env *Env) []*Bus

func RunArrayLiteral

func RunArrayLiteral(tree parser.ArrayLiteral, env *Env) *Bus

RunArrayLiteral executes a parser.ArrayLiteral.

func RunBinaryExpr

func RunBinaryExpr(tree parser.BinaryExpr, env *Env) *Bus

RunBinaryExpr executes a parser.BinaryExpr.

func RunBlockScopeStmt

func RunBlockScopeStmt(tree parser.BlockScopeStmt, env *Env) []*Bus

func RunForStmt

func RunForStmt(For parser.ForStmt, env *Env) *Bus

RunForStmt runs the for statement

func RunFunctionCallExpr

func RunFunctionCallExpr(tree parser.FunctionCallExpr, env *Env) []*Bus

RunFunctionCallExpr executes a parser.FunctionCallExpr.

func RunIfStmt

func RunIfStmt(tree parser.IfStmt, env *Env) *Bus

RunIfStmt runs the if statement

func RunIndexableAccessExpr

func RunIndexableAccessExpr(tree parser.IndexableAccessExpr, env *Env) *Bus

RunIndexableAccessExpr executes a parser.IndexableAccessExpr.

func RunMapLiteral

func RunMapLiteral(tree parser.MapLiteral, env *Env) *Bus

RunMapLiteral executes a parser.MapLiteral.

func RunSelectorExpr

func RunSelectorExpr(expr parser.SelectorExpr, env *Env, Struct eclaType.Type) []*Bus

func RunStructInstantiationExpr

func RunStructInstantiationExpr(tree parser.StructInstantiationExpr, env *Env) []*Bus

func RunTree

func RunTree(tree parser.Node, env *Env) []*Bus

RunTree executes a parser.Node

func RunTreeLoad

func RunTreeLoad(tree parser.Node, env *Env) []*Bus

RunTreeLoad is special version of RunTree that is used to load the environment (function, variable, import)

func RunUnaryExpr

func RunUnaryExpr(tree parser.UnaryExpr, env *Env) *Bus

RunUnaryExpr executes a parser.UnaryExpr.

func RunWhileStmt

func RunWhileStmt(tree parser.WhileStmt, env *Env) *Bus

RunWhileStmt runs the while statement

func (*Bus) GetVal

func (b *Bus) GetVal() eclaType.Type

GetVal returns the value of the bus.

func (*Bus) IsMain

func (b *Bus) IsMain() bool

IsMain returns true if the bus is a main bus.

func (*Bus) IsNone

func (b *Bus) IsNone() bool

IsNone returns true if the bus is a none bus.

func (*Bus) IsReturn

func (b *Bus) IsReturn() bool

IsReturn returns true if the bus is a return bus.

func (*Bus) TransformTo

func (b *Bus) TransformTo(busType BusType)

TransformTo transforms the bus to the given type.

type BusType

type BusType int

BusType is the type of bus.

const (
	BUS_MAIN   BusType = iota // Main bus
	BUS_RETURN                // Return bus
	BUS_NONE                  // None bus
)

type Env

type Env struct {
	Vars         *Scope
	OS           string
	ARCH         string
	SyntaxTree   *parser.File
	Tokens       []lexer.Token
	File         string
	Code         string
	Libs         map[string]libs.Lib
	ErrorHandle  *errorHandler.ErrorHandler
	ExecutedFunc []*eclaType.Function
	TypeDecl     []eclaDecl.TypeDecl
}

Env is the environment in which the code is executed.

func NewEnv

func NewEnv() *Env

NewEnv returns a new Env.

func NewTemporaryEnv

func NewTemporaryEnv(ErrorHandler *errorHandler.ErrorHandler) *Env

NewTemporaryEnv returns a new temporary Env. Temporary Env are used to import modules.

func (*Env) AddFunctionExecuted

func (env *Env) AddFunctionExecuted(f *eclaType.Function)

AddFunctionExecuted adds a function to the pile of executed functions.

func (*Env) AddTypeDecl

func (env *Env) AddTypeDecl(t eclaDecl.TypeDecl)

func (*Env) CheckIfVarExistsInCurrentScope

func (env *Env) CheckIfVarExistsInCurrentScope(name string) bool

CheckIfVarExistsInCurrentScope returns true if the variable exists in the current scope.

func (*Env) ConvertToLib

func (env *Env) ConvertToLib(MainEnv *Env) libs.Lib

ConvertToLib converts the Env to a Lib.

func (*Env) EndScope

func (env *Env) EndScope()

EndScope ends the current scope.

func (*Env) Execute

func (env *Env) Execute()

Execute executes Env.Code or Env.File.

func (*Env) ExecuteMetrics

func (env *Env) ExecuteMetrics() met.Metrics

func (*Env) GetFunctionExecuted

func (env *Env) GetFunctionExecuted() *eclaType.Function

GetFunctionExecuted returns the last function executed.

func (*Env) GetTypeDecl

func (env *Env) GetTypeDecl(name string) (eclaDecl.TypeDecl, bool)

func (*Env) GetVar

func (env *Env) GetVar(name string) (*eclaType.Var, bool)

GetVar returns the value of the variable with the given name.

func (*Env) Import

func (env *Env) Import(stmt parser.ImportStmt)

Import executes an import statement.

func (*Env) Load

func (env *Env) Load()

Load the file

func (*Env) NewScope

func (env *Env) NewScope(Type ScopeType)

NewScope creates a new scope.

func (*Env) RemoveFunctionExecuted

func (env *Env) RemoveFunctionExecuted()

RemoveFunctionExecuted removes the last function executed.

func (*Env) SetCode

func (env *Env) SetCode(code string)

SetCode sets the code to be executed.

func (*Env) SetFile

func (env *Env) SetFile(file string)

SetFile sets the file to be executed.

func (*Env) SetFunction

func (env *Env) SetFunction(name string, f *eclaType.Function) error

SetFunction sets the function with the given name.

func (*Env) SetScope

func (env *Env) SetScope(s *Scope)

SetScope sets the most deep scope.

func (*Env) SetVar

func (env *Env) SetVar(name string, value *eclaType.Var)

SetVar sets the value of the variable with the given name.

func (*Env) String

func (env *Env) String() string

type Scope

type Scope struct {
	Var map[string]*eclaType.Var

	Type   ScopeType
	InFunc bool
	// contains filtered or unexported fields
}

Scope is a scope.

func InitBuildIn

func InitBuildIn() *Scope

func NewScopeMain

func NewScopeMain() *Scope

NewScopeMain returns a new main scope.

func (*Scope) CheckIfVarExistsInCurrentScope

func (s *Scope) CheckIfVarExistsInCurrentScope(name string) bool

CheckIfVarExistsInCurrentScope returns true if the variable exists in the current scope.

func (*Scope) Get

func (s *Scope) Get(name string) (*eclaType.Var, bool)

Get returns the value of the variable with the given name.

func (*Scope) GetFunctionScope

func (s *Scope) GetFunctionScope() *Scope

GetFunctionScope returns the function scope.

func (*Scope) GetNextScope

func (s *Scope) GetNextScope() *Scope

GetNextScope returns the next scope.

func (*Scope) GoDeep

func (s *Scope) GoDeep(Type ScopeType)

GoDeep creates a new scope was deeper than the current one.

func (*Scope) GoDeepWithSpecificScope

func (s *Scope) GoDeepWithSpecificScope(Scope *Scope)

GoDeepWithSpecificScope goes deep with a specific scope.

func (*Scope) GoUp

func (s *Scope) GoUp()

GoUp goes up in the scope and deletes the current one.

func (*Scope) InFunction

func (s *Scope) InFunction() bool

InFunction returns true if the scope is in a function.

func (*Scope) Set

func (s *Scope) Set(name string, value *eclaType.Var)

Set sets the value of the variable with the given name.

func (*Scope) SetNextScope

func (s *Scope) SetNextScope(next *Scope)

SetNextScope sets the next scope.

type ScopeType

type ScopeType int

ScopeType is the type of scope.

const (
	SCOPE_MAIN ScopeType = iota
	SCOPE_FUNCTION
	SCOPE_LOOP
	SCOPE_CONDITION
	SCOPE_TRY
	SCOPE_CATCH
	SCOPE_FINALLY
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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