Documentation
¶
Overview ¶
Package vm executes compiled Kukel programs on a stack machine.
Each call has a frame. A frame's slots (parameters, temporaries, locals) sit on the value stack at frame.base, followed by its operand stack. The callee value sits just below the slots.
Index ¶
- Constants
- type Builtins
- type RuntimeError
- type TraceEntry
- type VM
- func (vm *VM) Call(fn value.Value, args []value.Value) (value.Value, error)
- func (vm *VM) Rand() *rand.Rand
- func (vm *VM) Run(args []string) (int, error)
- func (vm *VM) SetStderr(w io.Writer)
- func (vm *VM) Started() time.Time
- func (vm *VM) Stderr() io.Writer
- func (vm *VM) Stdin() *bufio.Reader
- func (vm *VM) Stdout() io.Writer
Constants ¶
const MaxFrames = 10000
MaxFrames bounds the call depth; deeper recursion is a stack overflow.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builtins ¶
type Builtins func(name string) (*value.BuiltinObj, bool)
Builtins resolves built-in functions by name.
type RuntimeError ¶
type RuntimeError struct {
Value value.Value // the thrown value (an Error object for runtime errors)
Kind string // the kind of an Error object; "" for other values
Msg string // the message of an Error object, or the value as text
Trace []TraceEntry // innermost call first
Fatal bool // try cannot catch it (exit, the step limit)
Exit *int // set by exit(code): not an error, the program ends
}
RuntimeError is a thrown exception: the thrown value and the stack trace at the throw. It is what Run returns for an exception nobody caught.
func (*RuntimeError) Error ¶
func (e *RuntimeError) Error() string
Error returns the message and the stack trace. Long traces (deep recursion) show only the first and last traceEnds calls.
type TraceEntry ¶
TraceEntry is one line of a stack trace.
type VM ¶
type VM struct {
// StepLimit, when positive, stops the program with a fatal error after
// that many backward jumps and calls (for tests that run untrusted code).
StepLimit int
// contains filtered or unexported fields
}
VM runs one program.
func New ¶
New prepares prog for running: it binds the functions and built-ins to their global slots.
func (*VM) Call ¶
Call calls fn from a built-in (sort's comparator, for example). The built-in's own arguments stay on the stack below the new call.