evaluator

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package evaluator contains the core of our interpreter, which walks the AST produced by the parser and evaluates user code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(ctx context.Context, args ...object.Object) object.Object

func Any

func Any(ctx context.Context, args ...object.Object) object.Object

func Assert added in v0.0.9

func Assert(ctx context.Context, args ...object.Object) object.Object

func Bool

func Bool(ctx context.Context, args ...object.Object) object.Object

func Call added in v0.0.12

func Call(ctx context.Context, args ...object.Object) object.Object

Call the given function with the provided arguments

func Chr added in v0.0.12

func Chr(ctx context.Context, args ...object.Object) object.Object

func Delete added in v0.0.9

func Delete(ctx context.Context, args ...object.Object) object.Object

func Err added in v0.0.9

func Err(ctx context.Context, args ...object.Object) object.Object

func Error added in v0.0.13

func Error(ctx context.Context, args ...object.Object) object.Object

func Exit added in v0.0.13

func Exit(ctx context.Context, args ...object.Object) object.Object

func Fetch added in v0.0.9

func Fetch(ctx context.Context, args ...object.Object) object.Object

func Float added in v0.0.12

func Float(ctx context.Context, args ...object.Object) object.Object

func GetAttr added in v0.0.12

func GetAttr(ctx context.Context, args ...object.Object) object.Object

func GlobalBuiltins added in v0.0.6

func GlobalBuiltins() []*object.Builtin

func Int added in v0.0.12

func Int(ctx context.Context, args ...object.Object) object.Object

func Iter added in v0.0.13

func Iter(ctx context.Context, args ...object.Object) object.Object

func Keys added in v0.0.9

func Keys(ctx context.Context, args ...object.Object) object.Object

func Len added in v0.0.9

func Len(ctx context.Context, args ...object.Object) object.Object

Len returns the length of a string, list, set, or map

func List added in v0.0.12

func List(ctx context.Context, args ...object.Object) object.Object

func Ok added in v0.0.9

func Ok(ctx context.Context, args ...object.Object) object.Object

func Ord added in v0.0.12

func Ord(ctx context.Context, args ...object.Object) object.Object

func Print added in v0.0.9

func Print(ctx context.Context, args ...object.Object) object.Object

output a string to stdout

func Printf added in v0.0.9

func Printf(ctx context.Context, args ...object.Object) object.Object

Printf is the implementation of our `printf` function.

func Reversed added in v0.0.9

func Reversed(ctx context.Context, args ...object.Object) object.Object

func Set added in v0.0.9

func Set(ctx context.Context, args ...object.Object) object.Object

func Sorted added in v0.0.9

func Sorted(ctx context.Context, args ...object.Object) object.Object

func Sprintf added in v0.0.9

func Sprintf(ctx context.Context, args ...object.Object) object.Object

func String added in v0.0.9

func String(ctx context.Context, args ...object.Object) object.Object

func Try added in v0.0.13

func Try(ctx context.Context, args ...object.Object) object.Object

func Type added in v0.0.9

func Type(ctx context.Context, args ...object.Object) object.Object

func Unwrap added in v0.0.7

func Unwrap(ctx context.Context, args ...object.Object) object.Object

func UnwrapOr added in v0.0.7

func UnwrapOr(ctx context.Context, args ...object.Object) object.Object

Types

type Breakpoint added in v0.0.13

type Breakpoint struct {
	// File is the file name of the breakpoint
	File string
	// Line is the line number of the breakpoint
	Line int
	// Disabled is true if the breakpoint is disabled.
	Disabled bool
	// Trace is true if the breakpoint should print a trace of the stack when
	// it is hit.
	Trace bool
	// Stop is true if the breakpoint should stop code execution when it is hit.
	Stop bool
}

func ParseBreakpoints added in v0.0.13

func ParseBreakpoints(desc string) ([]Breakpoint, error)

ParseBreakpoints parses a comma-separated list of breakpoints, where each breakpoint is formatted as "file:line:flags". The flags are optional and can be any combination of "n" (no-stop), "t" (trace), and "d" (disabled).

type Evaluator

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

Evaluator is used to execute Tamarin AST nodes.

func New

func New(opts Opts) *Evaluator

New returns a new Evaluator

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(ctx context.Context, node ast.Node, s *scope.Scope) object.Object

Evaluate an AST node. The context can be used to cancel a running evaluation. If evaluation encounters an error, a Tamarin error object is returned.

func (*Evaluator) GetBreakpoint added in v0.0.13

func (e *Evaluator) GetBreakpoint(tok token.Token) (*Breakpoint, bool)

type Importer

type Importer interface {
	Import(ctx context.Context, e *Evaluator, name string) (*object.Module, error)
}

type Opts

type Opts struct {
	// Importer is used to import Tamarin code modules. If nil, module imports
	// are not supported and an import will result in an error that stops code
	// execution.
	Importer Importer

	// If set to true, the default builtins will not be registered.
	DisableDefaultBuiltins bool

	// Supplies extra and/or override builtins for evaluation.
	Builtins []*object.Builtin

	// Breakpoints for debugging
	Breakpoints []Breakpoint
}

Opts configures Tamarin code evaluation.

type SimpleImporter

type SimpleImporter struct{}

func (*SimpleImporter) Import

func (si *SimpleImporter) Import(ctx context.Context, e *Evaluator, name string) (*object.Module, error)

Jump to

Keyboard shortcuts

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