Documentation
¶
Index ¶
- type Interpreter
- func (i *Interpreter) Eval(ctx context.Context) (*Result, error)
- func (i *Interpreter) EvalDeclarations(ctx context.Context) error
- func (i *Interpreter) EvalFileInREPL(ctx context.Context, filename string) error
- func (i *Interpreter) EvalLine(ctx context.Context, line string) (object.Object, error)
- func (i *Interpreter) EvalString(source string) (object.Object, error)
- func (i *Interpreter) Execute(ctx context.Context, fn *object.Function, args []object.Object, ...) (*Result, error)
- func (i *Interpreter) Files() []*object.FileScope
- func (i *Interpreter) FindFunction(name string) (*object.Function, *object.FileScope, error)
- func (i *Interpreter) GlobalEnvForTest() *object.Environment
- func (i *Interpreter) LoadFile(filename string, source []byte) error
- func (i *Interpreter) LoadGoSourceAsPackage(pkgName, source string) error
- func (i *Interpreter) Register(pkgPath string, symbols map[string]any)
- func (i *Interpreter) RegisterSpecial(name string, fn evaluator.SpecialFormFunction)
- func (i *Interpreter) Scanner() *goscan.Scanner
- type Option
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interpreter ¶
type Interpreter struct { Registry *object.SymbolRegistry // contains filtered or unexported fields }
Interpreter is the main entry point for the minigo language. It holds the state of the interpreter, including the scanner for package resolution and the root environment for script execution.
func New ¶
New creates a new interpreter instance with default I/O streams. It panics if initialization fails.
func NewInterpreter ¶
func NewInterpreter(scanner *goscan.Scanner, options ...Option) (*Interpreter, error)
NewInterpreter creates a new interpreter instance, configured with options.
func (*Interpreter) Eval ¶
func (i *Interpreter) Eval(ctx context.Context) (*Result, error)
Eval executes the loaded files. It first processes all declarations and then runs the main function if it exists.
func (*Interpreter) EvalDeclarations ¶
func (i *Interpreter) EvalDeclarations(ctx context.Context) error
EvalDeclarations evaluates all top-level declarations in the loaded files.
func (*Interpreter) EvalFileInREPL ¶
func (i *Interpreter) EvalFileInREPL(ctx context.Context, filename string) error
EvalFileInREPL parses and evaluates a file's declarations within the persistent REPL scope. This allows loaded files to affect the REPL's state, including imports.
func (*Interpreter) EvalLine ¶
EvalLine evaluates a single line of input for the REPL. It maintains state across calls by using a persistent, single FileScope.
func (*Interpreter) EvalString ¶
func (i *Interpreter) EvalString(source string) (object.Object, error)
EvalString evaluates the given source code string as a complete file. It parses the source, evaluates all declarations, and then executes the main function if it exists.
func (*Interpreter) Execute ¶
func (i *Interpreter) Execute(ctx context.Context, fn *object.Function, args []object.Object, fscope *object.FileScope) (*Result, error)
Execute runs a given function with the provided arguments using the interpreter's persistent evaluator.
func (*Interpreter) Files ¶
func (i *Interpreter) Files() []*object.FileScope
Files returns the file scopes that have been loaded into the interpreter.
func (*Interpreter) FindFunction ¶
FindFunction finds a function in the global scope and the file scope it was defined in.
func (*Interpreter) GlobalEnvForTest ¶
func (i *Interpreter) GlobalEnvForTest() *object.Environment
GlobalEnvForTest returns the interpreter's global environment. This method is intended for use in tests only.
func (*Interpreter) LoadFile ¶
func (i *Interpreter) LoadFile(filename string, source []byte) error
LoadFile parses a file and adds it to the interpreter's state without evaluating it yet. This is the first stage of a multi-file evaluation.
func (*Interpreter) LoadGoSourceAsPackage ¶
func (i *Interpreter) LoadGoSourceAsPackage(pkgName, source string) error
LoadGoSourceAsPackage parses and evaluates a single Go source file as a self-contained package.
func (*Interpreter) Register ¶
func (i *Interpreter) Register(pkgPath string, symbols map[string]any)
Register makes Go symbols (variables or functions) available for import by a script. For example, `interp.Register("strings", map[string]any{"ToUpper": strings.ToUpper})` allows a script to `import "strings"` and call `strings.ToUpper()`.
func (*Interpreter) RegisterSpecial ¶
func (i *Interpreter) RegisterSpecial(name string, fn evaluator.SpecialFormFunction)
RegisterSpecial registers a "special form" function. A special form receives the AST of its arguments directly, without them being evaluated first. This is useful for implementing DSLs or control structures. These functions are available in the global scope.
func (*Interpreter) Scanner ¶
func (i *Interpreter) Scanner() *goscan.Scanner
Scanner returns the underlying goscan.Scanner instance.
type Option ¶
type Option func(*Interpreter)
Option is a functional option for configuring the Interpreter.
func WithGlobals ¶
WithGlobals allows injecting Go variables into the script's global scope. The map key is the variable name in the script. The value can be any Go variable, which will be made available via reflection.
func WithStderr ¶
WithStderr sets the standard error for the interpreter.
func WithStdout ¶
WithStdout sets the standard output for the interpreter.
Directories
¶
Path | Synopsis |
---|---|
Package ffibridge provides helper types for the Foreign Function Interface (FFI) between the MiniGo interpreter and native Go code.
|
Package ffibridge provides helper types for the Foreign Function Interface (FFI) between the MiniGo interpreter and native Go code. |
stdlib
|
|