Documentation
¶
Overview ¶
Package engine defines the Engine and Session interfaces that all scripting engine implementations must satisfy, along with the engine registry.
Concurrency model: a Session is NOT safe for concurrent use from multiple goroutines. The pool (internal/interp/pool) ensures each Session is owned by exactly one goroutine at a time. Parallelism is achieved by maintaining N sessions across N pool workers — no session is shared.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallParams ¶
type CallParams struct {
Fn Value
}
CallParams configures a Session.Call invocation. Fn is the compiled value to run; the buzz engine ignores arguments and return-value counts (callers that need them use the concrete Session.CallValue), so only Fn is carried here.
type DebugReader ¶
type DebugReader interface {
// Frames walks the active call stack from innermost to outermost,
// skipping host (Go/C) frames. The slice is fresh on every call.
Frames() []Frame
// Locals returns the named locals at the frame indicated by level
// (0 = innermost). Returns an empty map if the level is out of range.
Locals(level int) map[string]Value
// Upvalues returns the captured upvalues at the frame indicated by level.
// Returns an empty map if the function has no upvalues or the level is
// out of range.
Upvalues(level int) map[string]Value
// CallDepth reports the number of active call frames. Used by step-over
// to know when a frame boundary is crossed.
CallDepth() int
}
DebugReader is an optional interface that sessions may implement to expose call-stack introspection. magus.pry() type-asserts the session to DebugReader at call time; sessions that don't implement it report no frames.
type DriversProvider ¶
type DriversProvider interface {
Drivers() []ReplDriver
}
DriversProvider is an optional interface for sessions that expose language-specific REPL drivers. The shared REPL calls Drivers() to get the available drivers and picks the appropriate one for each language mode.
type Engine ¶
type Engine interface {
// NewSession returns a fresh session with standard libraries loaded
// and ctx bound for cancellation. Pass context.Background() for no cancellation.
NewSession(ctx context.Context) (Session, error)
}
Engine creates Sessions for script execution. Implementations register themselves at init() time via Register.
type Frame ¶
type Frame struct {
Source string
ShortSrc string
CurrentLine int
Name string // function name when discoverable
What string // engine-reported frame kind (e.g. "main", "tail")
}
Frame describes one entry on a scripting engine's call stack as reported by the engine's debug API. Source is the chunk name as the engine reports it (e.g. "@magusfile.buzz"); ShortSrc is a truncated form suitable for display; CurrentLine is the 1-based line number, or -1 if unknown.
type ReplDriver ¶
type ReplDriver interface {
// Language returns the driver's name (e.g. "buzz").
Language() string
// EvalLine evaluates snippet. Implementations should first try
// "return "+snippet so that bare expressions print a result; if that
// fails with a syntax error they should fall back to running snippet
// as a statement. Returns (nil, nil) if execution succeeded with no
// printable value. Multiple return values are supported.
EvalLine(snippet string) ([]Value, error)
// IsIncomplete returns true when err indicates that snippet is a partial
// statement that needs more input (e.g. an unexpected end-of-input error).
// The REPL accumulates additional lines when this returns true.
IsIncomplete(err error) bool
// LineDelta returns the net open-block delta for this line of source (e.g.
// bracket-depth counting for JS). Engines that rely on error-based
// continuation instead return 0 always. The REPL buffers more input while
// the cumulative delta is positive.
LineDelta(line string) int
// HostBindingNames returns the names injected by the host runtime so the
// REPL can omit them from .globals output.
HostBindingNames() []string
// UserGlobals returns the current user-defined globals with host bindings
// filtered out. Returns nil when the engine does not support listing globals.
UserGlobals() map[string]Value
}
ReplDriver is an optional interface sessions expose to allow the shared REPL to evaluate snippets, detect partial-input continuation, and filter host-injected globals — without knowing the engine's surface language.
Each engine exposes one driver per language it speaks; the REPL switches between drivers by language.
type Session ¶
type Session interface {
Close() error
SetGlobal(name string, v Value)
GetGlobal(name string) Value
NewTable() Table
LoadString(code string) (Value, error)
DoString(code string) error
Call(p CallParams) error
}
Session is a single isolated script-execution context. A Session is NOT safe for concurrent use from multiple goroutines; the pool ensures each Session is owned by exactly one goroutine at a time.
type StepMask ¶
type StepMask int
StepMask selects which engine events the step hook subscribes to. Combine values with bitwise OR.
type Stepper ¶
Stepper is an optional interface for sessions that support line-level step hooks: source-level instrumentation that injects hook trampolines before each statement at compile time, firing a callback as execution crosses statements.
SetStepHook installs cb to fire on the next event matching mask. cb is invoked synchronously on the script execution goroutine and may re-enter the pry REPL (the pry loop is re-entrant). After cb returns, execution resumes. ClearStepHook removes any installed hook.
type Table ¶
type Table interface {
Value
RawSetString(key string, v Value)
RawGetString(key string) Value
RawSetInt(key int, v Value)
RawGetInt(key int) Value
ForEach(fn func(k, v Value))
Len() int
}
Table is a script-side key-value collection. Constructed via Session.NewTable().
type Value ¶
type Value interface {
IsNil() bool
String() string
AsString() (string, bool)
AsNumber() (float64, bool)
AsBool() bool
AsTable() (Table, bool)
AsFunction() (Value, bool)
}
Value is a script-side value handle. Engine implementations choose their own concrete representation; callers use the methods below for type-safe access.
var NilValue Value = nilVal{}
NilValue is the nil Value.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package buzz adapts the standalone Buzz interpreter (magus/gopherbuzz) to magus's engine.Engine/engine.Session interfaces and registers it under the "buzz" key.
|
Package buzz adapts the standalone Buzz interpreter (magus/gopherbuzz) to magus's engine.Engine/engine.Session interfaces and registers it under the "buzz" key. |