Documentation
¶
Overview ¶
Package runtime is the Writ value universe and evaluator.
Eval takes already-parsed forms. It does not parse source.
Index ¶
- Variables
- func Exported(name string) bool
- func FormatSymbol(name string) string
- func IsName(v Value, name string) bool
- func PluginsSupported() bool
- func Print(v Value) string
- type Clause
- type DefHead
- type Error
- type Func
- type Handler
- type IfClause
- type Importer
- type KeyPat
- type Kind
- type Machine
- func (m *Machine) ApplyLocked(fn Value, args []Value) (Value, error)
- func (m *Machine) BeginBudget()
- func (m *Machine) Checking() bool
- func (m *Machine) Eval(forms []Value) (Value, error)
- func (m *Machine) EvalLocked(forms []Value) (Value, error)
- func (m *Machine) EvalModule(path string, forms []Value) (Value, error)
- func (m *Machine) Expand(forms []Value) (Program, error)
- func (m *Machine) ExpandLocked(forms []Value) (Program, error)
- func (m *Machine) File() string
- func (m *Machine) FireLocked(event string, payload map[string]Value) error
- func (m *Machine) GetPropLocked(path ...string) Value
- func (m *Machine) Loaded(path string) (Value, bool)
- func (m *Machine) LoadingCycle(path string) bool
- func (m *Machine) LoadingPath() []string
- func (m *Machine) Lock()
- func (m *Machine) LookupLocked(name string) (Value, bool)
- func (m *Machine) PopLoading()
- func (m *Machine) PushLoading(path string)
- func (m *Machine) RegisterExtra(name string, fn Func)
- func (m *Machine) RememberPackage(path string, exp Value)
- func (m *Machine) ResetLocked()
- func (m *Machine) SetAfterError(fn func(error))
- func (m *Machine) SetChecking(v bool)
- func (m *Machine) SetEvalLimit(n int)
- func (m *Machine) SetEventKeys(name string, keys []string)
- func (m *Machine) SetFile(file string)
- func (m *Machine) SetPropLocked(val Value, path ...string) error
- func (m *Machine) SetScheduler(s Scheduler)
- func (m *Machine) Unlock()
- type MapPair
- type NamedFn
- type NamedImport
- type Package
- type Params
- type Pattern
- type Program
- type Scheduler
- type Span
- type Value
- func Bool(b bool) Value
- func CallList(xs ...Value) Value
- func Comment(text string) Value
- func EmptyMap() Value
- func FilterComments(xs []Value) []Value
- func Float(f float64) Value
- func Int(v *big.Int) Value
- func Int64(n int64) Value
- func List(xs ...Value) Value
- func MapFrom(pairs ...MapPair) Value
- func MustInt(s string) Value
- func Native(v any) Value
- func PackageValue(p Package) Value
- func ParseInt(s string) (Value, bool)
- func Quote(v Value) Value
- func Splice(v Value) Value
- func String(s string) Value
- func Symbol(name string) Value
- func Unquote(v Value) Value
- func (v Value) As(dst any) bool
- func (v Value) AsFloat64() (float64, bool)
- func (v Value) BigInt() *big.Int
- func (v Value) Blank() bool
- func (v Value) Broke() bool
- func (v Value) CommentText() string
- func (v Value) Equal(o Value) bool
- func (v Value) Float64() float64
- func (v Value) HasSpan() bool
- func (v Value) Inner() Value
- func (v Value) IsBool() bool
- func (v Value) IsFalse() bool
- func (v Value) IsFloat() bool
- func (v Value) IsInt() bool
- func (v Value) IsKey() bool
- func (v Value) IsNil() bool
- func (v Value) IsNum() bool
- func (v Value) IsTrue() bool
- func (v Value) IsVec() bool
- func (v Value) Items() []Value
- func (v Value) KeyName() string
- func (v Value) KeySpans() map[string]Span
- func (v Value) Kind() Kind
- func (v Value) MapGet(key string) (Value, bool)
- func (v Value) Name() string
- func (v Value) Native() (any, bool)
- func (v Value) Pairs() []MapPair
- func (v Value) SetInner(in Value) Value
- func (v Value) Span() (Span, bool)
- func (v Value) String() string
- func (v Value) Text() string
- func (v Value) TrailingComment() string
- func (v Value) Truthy() bool
- func (v Value) WithBlank() Value
- func (v Value) WithBroke() Value
- func (v Value) WithComment(cmt string) Value
- func (v Value) WithKeySpans(spans map[string]Span) Value
- func (v Value) WithSpan(start, end int) Value
Constants ¶
This section is empty.
Variables ¶
var ( True = internSym("true") False = internSym("false") Nil = internSym("nil") )
True, False, and Nil are interned symbols. True and False are booleans; Nil is not.
Functions ¶
func Exported ¶
Exported reports whether a top-level def/defm name is in a module export map. Names that start with '-' are private to the defining script.
func FormatSymbol ¶
FormatSymbol renders a symbol name, quoting with ticks when needed.
func PluginsSupported ¶
func PluginsSupported() bool
PluginsSupported reports whether this platform can load native plugins.
Types ¶
type DefHead ¶
type DefHead struct {
Name string
NameForm Value
Params Params
ParamsForm Value
Body []Value
HeadForm Value
}
DefHead is a parsed (def ...) or (defm ...) head.
type Error ¶
type Error struct {
File string
Start int
End int
Message string
// contains filtered or unexported fields
}
Error is a parse, type, or evaluation error. Start and End are byte offsets into the source when known.
func ErrorIncomplete ¶
ErrorIncomplete is ErrorAt for a source prefix that needs more input.
func (*Error) IsIncomplete ¶
IsIncomplete reports whether this is an incomplete-parse error.
type IfClause ¶
IfClause is one branch of (if ...).
func ParseIfArgs ¶
ParseIfArgs parses (if ...) arguments.
type Importer ¶
Importer loads (import spec) for the machine. The host wires filesystem policy, parsing, and evaluation.
type Machine ¶
type Machine struct {
Import Importer
// contains filtered or unexported fields
}
Machine evaluates already-parsed forms.
func (*Machine) ApplyLocked ¶
ApplyLocked is Apply without taking the lock.
func (*Machine) BeginBudget ¶
func (m *Machine) BeginBudget()
BeginBudget resets the remaining eval step budget.
func (*Machine) EvalLocked ¶
EvalLocked is Eval without taking the lock.
func (*Machine) EvalModule ¶
EvalModule evaluates an imported script without replacing the caller's env.
func (*Machine) ExpandLocked ¶
ExpandLocked is Expand without taking the lock.
func (*Machine) FireLocked ¶
FireLocked is Fire without taking the lock.
func (*Machine) GetPropLocked ¶
GetPropLocked reads the script store. Caller must hold Lock.
func (*Machine) LoadingCycle ¶
func (*Machine) LoadingPath ¶
func (*Machine) LookupLocked ¶
LookupLocked returns a top-level binding. Caller must hold Lock.
func (*Machine) PopLoading ¶
func (m *Machine) PopLoading()
func (*Machine) PushLoading ¶
func (*Machine) RegisterExtra ¶
RegisterExtra installs a host function visible as a call head.
func (*Machine) RememberPackage ¶
RememberPackage caches a native plugin export. Caller must hold Lock.
func (*Machine) ResetLocked ¶
func (m *Machine) ResetLocked()
ResetLocked clears store, env, macros, handlers, and loaded modules. Caller must hold Lock.
func (*Machine) SetAfterError ¶
SetAfterError sets a hook for errors from (after ...) callbacks.
func (*Machine) SetChecking ¶
SetChecking toggles check mode: after is a no-op and plugins stay closed if the host importer honors it.
func (*Machine) SetEvalLimit ¶
SetEvalLimit caps eval/expand steps. Zero means unlimited.
func (*Machine) SetEventKeys ¶
SetEventKeys records payload key order for Fire.
func (*Machine) SetPropLocked ¶
SetPropLocked writes the script store. Caller must hold Lock.
func (*Machine) SetScheduler ¶
SetScheduler replaces the after scheduler.
type NamedImport ¶
NamedImport is a top-level keyed (import name: path ...).
type Package ¶
Package is funcs and values for (import). The checker types funcs as fn(...) -> dynamic(any()) and values as any().
func LoadPlugin ¶
LoadPlugin opens a Go plugin and calls WritPackage.
type Program ¶
type Program struct {
Handlers []Handler
Boot []Value
Fns []NamedFn
Macros []NamedFn
Imports []NamedImport
}
Program is expanded top-level forms.
type Scheduler ¶
Scheduler runs (after seconds ...) bodies. delay is in real time. The default scheduler uses time.AfterFunc; callbacks take the machine lock, so they never overlap eval/Fire/after. A custom Scheduler must not invoke fn on the same goroutine that is still inside Eval, Apply, or Fire (that deadlocks). Overlapping callbacks are serialized by the lock. Default unlimited eval is not a sandbox.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is a Writ value or source form.
func PackageValue ¶
PackageValue builds the map returned by (import) of a native package.
func (Value) CommentText ¶
CommentText is the comment form body, including ';'.
func (Value) Equal ¶
Equal reports value equality. 1 and 1.0 compare equal. Functions never compare equal. Native values use == when the dynamic type is comparable.
func (Value) TrailingComment ¶
TrailingComment is the inline comment after v, if any.
func (Value) WithComment ¶
WithComment returns a copy of v with a trailing comment.
func (Value) WithKeySpans ¶
WithKeySpans records source spans of map keys.