runtimev2

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const PackageDirectory = ".flmod"

Variables

View Source
var (
	ErrInvalidValue           = fmt.Errorf("invalid value")
	ErrVariableRedeclared     = fmt.Errorf("variable already declared")
	ErrVariableNotDeclared    = fmt.Errorf("variable not declared")
	ErrConstantReassignment   = fmt.Errorf("cannot reassign constant")
	ErrVariableNotFound       = fmt.Errorf("variable not found")
	ErrFunctionRedeclared     = fmt.Errorf("function already declared")
	ErrNamespaceInUse         = fmt.Errorf("namespace already in use")
	ErrNamespaceNotFound      = fmt.Errorf("namespace not found")
	ErrFunctionNotFound       = fmt.Errorf("function not found")
	ErrInvalidArguments       = fmt.Errorf("invalid arguments")
	ErrIndexOutOfBounds       = fmt.Errorf("index out of bounds")
	ErrDefinitionReassignment = fmt.Errorf("cannot reassign this definition")
	ErrThisOutsideMethod      = fmt.Errorf("'this' cannot be used outside of a method")
	ErrUnhandledNodeType      = fmt.Errorf("unhandled node type")
	ErrInvalidIncrementTarget = fmt.Errorf("cannot increment this value")
	ErrEmptyErrorBlock        = fmt.Errorf("error block has no child nodes")
	ErrNamedInlineFunction    = fmt.Errorf("inline function cannot have a name")
	ErrExpectedExpression     = fmt.Errorf("expected expression")
	ErrExpectedBoolean        = fmt.Errorf("%w: expected boolean", ErrInvalidValue)
	ErrExpectedIterable       = fmt.Errorf("%w: expected an iterable value (e.g. array, list, or string)", ErrInvalidValue)
	ErrInvalidIndexAccess     = fmt.Errorf("%w: cannot access value: invalid index or not indexable", ErrInvalidValue)
	ErrKeyNotFound            = fmt.Errorf("key not found in array")
	ErrInvalidObject          = fmt.Errorf("invalid object")
	ErrInvalidObjectAccess    = fmt.Errorf("invalid object member access")
)

Functions

func Error

func Error(err error, debug *models.Debug, customText ...any) error

Error creates a new error with debug information.

Types

type Executer

type Executer struct {
	// contains filtered or unexported fields
}

Executer represents a node executer in the runtime

func NewExecuter

func NewExecuter(scope ExecuterScope, r *Runtime, parent *Executer) *Executer

NewExecuter creates a new runtime executer

func (*Executer) AssignVariable

func (e *Executer) AssignVariable(name string, object lang.Object) error

func (*Executer) BindMethod

func (e *Executer) BindMethod(name string, fn lang.Method)

BindMethod binds a method to the executer

func (*Executer) BindObject

func (e *Executer) BindObject(name string, object lang.Object)

BindObject binds an object to the executer

func (*Executer) Copy

func (e *Executer) Copy() lang.Executer

Copy creates a copy of the executer

func (*Executer) Execute

func (e *Executer) Execute(nodes []*models.Node) (lang.Object, error)

Execute executes the given nodes

func (*Executer) GetMethod

func (e *Executer) GetMethod(name string) (lang.Method, error)

GetMethod gets a method by name

func (*Executer) GetNamespaceExecuter

func (e *Executer) GetNamespaceExecuter(namespace string) (*Executer, error)

func (*Executer) GetNew

func (e *Executer) GetNew() lang.Executer

func (*Executer) GetVariable

func (e *Executer) GetVariable(name string) (lang.Object, error)

GetVariable gets a variable by name

func (*Executer) LoadFile

func (e *Executer) LoadFile(path string) error

func (*Executer) Variables

func (e *Executer) Variables() []string

func (*Executer) WithName

func (e *Executer) WithName(name string) *Executer

WithName sets the name of the executer

type ExecuterScope

type ExecuterScope int

ExecuterScope is the scope of the executer

const (
	// ExecuterScopeGlobal is the global scope
	ExecuterScopeGlobal ExecuterScope = iota
	// ExecuterScopeBlock is the block scope (if, else, for, etc.)
	ExecuterScopeBlock
	// ExecuterScopeFunction is the function scope
	ExecuterScopeFunction
	// ExecuterScopeDefinition is the definition scope
	ExecuterScopeDefinition
)

func (ExecuterScope) String

func (e ExecuterScope) String() string

type Namespace

type Namespace struct {
	Name   string
	Nodes  []*models.Node
	Loaded bool
}

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

RuntimeMode is the runtime mode

func New

func New(provider *state.Provider) (*Runtime, error)

New creates a new runtime

func (*Runtime) BindModule

func (r *Runtime) BindModule(module lang.Module)

BindModule binds the given module to the runtime

func (*Runtime) Exec

func (r *Runtime) Exec(scope ExecuterScope, parent *Executer, namespace string, nodes []*models.Node) (lang.Object, error)

Exec executes the given nodes in the given namespace

func (*Runtime) Execute

func (r *Runtime) Execute(nodes []*models.Node) (lang.Object, error)

Execute executes the given nodes

func (*Runtime) GetNamespace

func (r *Runtime) GetNamespace(nodes []*models.Node) (string, []*models.Node, error)

func (*Runtime) GetNamespaceExecuter

func (r *Runtime) GetNamespaceExecuter(namespace string) (*Executer, error)

GetNamespaceExecuter gets the executer for the given namespace

func (*Runtime) LoadSourceNamespaces

func (r *Runtime) LoadSourceNamespaces() error

func (*Runtime) UseModule

func (r *Runtime) UseModule(module lang.Module) *Executer

UseModule returns a module by its namespace

Jump to

Keyboard shortcuts

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