Documentation
¶
Overview ¶
Package registry provides a plugin architecture for registering Scheme primitives.
The registry allows extensions to register primitives that are applied to environments at initialization time. Primitives can be registered for different phases: runtime, expand-time, and compile-time.
Key Types ¶
- Registry: central store for primitive registrations
- PrimitiveSpec: defines a single primitive (name, params, implementation)
- Phase: bit flags controlling environment placement (Runtime, Expand, Compile)
- Extension: interface for modular primitive packages
Registration ¶
reg := registry.NewRegistry()
reg.AddPrimitives([]registry.PrimitiveSpec{
{Name: "my-func", ParamCount: 1, Impl: myFuncImpl},
}, registry.PhaseRuntime|registry.PhaseExpand)
Application ¶
After registration, apply the registry to an environment:
err := reg.Apply(ctx, env)
Extensions ¶
Extensions implement the Extension interface and can be composed:
var Extension = registry.NewExtension("myext", AddToRegistry)
The RegistryBuilder type provides a convenient way to compose multiple registration functions into a single extension.
Index ¶
- func ExtractLibraryRegistry(env *environment.EnvironmentFrame) *compilation.LibraryRegistry
- type BindingSpec
- type Closeable
- type Describer
- type DocEntry
- type DocSearchResult
- type Extension
- type ExtensionFunc
- type GlobalValue
- type InitFunc
- type LibraryNamer
- type Phase
- type PrimitiveRegistration
- type PrimitiveSpec
- type Registry
- func (p *Registry) AddBinding(name string)
- func (p *Registry) AddBindingSpecs(specs []BindingSpec)
- func (p *Registry) AddBindings(names []string)
- func (p *Registry) AddDocOnlyPrimitive(spec PrimitiveSpec)
- func (p *Registry) AddDocumentation(name, doc string)
- func (p *Registry) AddGlobalValue(name string, value values.Value)
- func (p *Registry) AddInitFunc(f InitFunc)
- func (p *Registry) AddMacroSource(source string)
- func (p *Registry) AddPrimitive(spec PrimitiveSpec, phases Phase)
- func (p *Registry) AddPrimitives(specs []PrimitiveSpec, phases Phase)
- func (p *Registry) Apply(ctx context.Context, env *environment.EnvironmentFrame) error
- func (p *Registry) ApplyDocs(env *environment.EnvironmentFrame)
- func (p *Registry) BindingCount() int
- func (p *Registry) BindingSpecs() []BindingSpec
- func (p *Registry) Bindings() []string
- func (p *Registry) Clone() *Registry
- func (p *Registry) Docs() []DocEntry
- func (p *Registry) FindPrimitive(name string, phase Phase) (PrimitiveRegistration, bool)
- func (p *Registry) GlobalValues() []GlobalValue
- func (p *Registry) HasPrimitive(name string, phase Phase) bool
- func (p *Registry) InitFuncs() []InitFunc
- func (p *Registry) MacroSources() []string
- func (p *Registry) PrimitiveByName(name string) (PrimitiveRegistration, bool)
- func (p *Registry) PrimitiveCount() int
- func (p *Registry) PrimitiveNames() []string
- func (p *Registry) Primitives() []PrimitiveRegistration
- func (p *Registry) PrimitivesByCategory() map[string][]PrimitiveRegistration
- func (p *Registry) RuntimePrimitiveNamesRange(startIndex, endIndex int) []string
- func (p *Registry) RuntimePrimitiveNamesSince(startIndex int) []string
- func (p *Registry) Without(names ...string) *Registry
- func (p *Registry) WithoutBindings(names ...string) *Registry
- func (p *Registry) WithoutCategory(categories ...string) *Registry
- type RegistryBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractLibraryRegistry ¶ added in v1.12.0
func ExtractLibraryRegistry(env *environment.EnvironmentFrame) *compilation.LibraryRegistry
ExtractLibraryRegistry extracts the *compilation.LibraryRegistry from an environment frame, returning nil if unavailable or a different concrete type.
Types ¶
type BindingSpec ¶ added in v1.10.3
BindingSpec defines a compile-time binding with optional documentation.
type Closeable ¶ added in v1.3.0
type Closeable interface {
Close() error
}
Closeable is an opt-in interface for extensions that hold resources (goroutines, file handles, connections) and need cleanup when the engine is shut down. Extensions that implement this interface will have Close called by Engine.Close().
type Describer ¶ added in v1.11.0
type Describer interface {
Description() string
}
Describer is an optional interface that extensions can implement to provide a human-readable library description. The description is shown by ,doc (wile <ext>) and ,libraries in the REPL.
type DocSearchResult ¶ added in v1.12.0
DocSearchResult holds one search hit from SearchDoc.
func NonPrimitiveDocs ¶ added in v1.12.0
func NonPrimitiveDocs(reg *Registry) []DocSearchResult
NonPrimitiveDocs returns doc search results from binding specs and doc entries. Each entry's Doc, Category, and Keywords are extracted via docparse.ParseDocstring.
func SearchDoc ¶ added in v1.12.0
func SearchDoc(reg *Registry, env *environment.EnvironmentFrame, libReg *compilation.LibraryRegistry, exportIndex *compilation.LibraryExportIndex, pattern string) []DocSearchResult
SearchDoc searches all documentation sources for case-insensitive substring matches on name, doc text, category, or keywords.
Sources searched in order:
- Registry primitives
- Registry binding specs (parsed via docparse)
- Registry doc entries (parsed via docparse)
- Environment bindings (if env is non-nil)
- Loaded libraries (if libReg is non-nil)
- Unloaded library exports (if exportIndex is non-nil)
Primitives take precedence over non-primitives with the same name. Results are sorted by name. env, libReg, and exportIndex may be nil.
type Extension ¶
type Extension interface {
// Name returns the extension name for logging/debugging.
Name() string
// AddToRegistry registers primitives with the registry.
AddToRegistry(r *Registry) error
}
Extension represents a loadable extension that adds primitives to a registry.
func NewDescribedExtension ¶ added in v1.11.0
NewDescribedExtension creates an Extension with a human-readable description. The description is surfaced by ,doc and ,libraries in the REPL.
type ExtensionFunc ¶
type ExtensionFunc struct {
// contains filtered or unexported fields
}
ExtensionFunc adapts a function to the Extension interface.
func (*ExtensionFunc) AddToRegistry ¶
func (p *ExtensionFunc) AddToRegistry(r *Registry) error
AddToRegistry registers primitives with the registry.
func (*ExtensionFunc) Description ¶ added in v1.11.0
func (p *ExtensionFunc) Description() string
Description returns the extension's human-readable description.
type GlobalValue ¶ added in v1.4.0
GlobalValue pairs a name with a value to be registered as a global binding.
type InitFunc ¶
type InitFunc func() error
InitFunc is called after all primitives and global values are registered.
type LibraryNamer ¶ added in v1.4.0
type LibraryNamer interface {
LibraryName() []string
}
LibraryNamer is an optional interface that extensions can implement to control their R7RS library name. Extensions that don't implement this get the default name (wile <ext.Name()>).
type Phase ¶
type Phase int
Phase indicates when a primitive is available.
func (Phase) HasCompile ¶
HasCompile returns true if the phase includes compile time.
func (Phase) HasRuntime ¶
HasRuntime returns true if the phase includes runtime.
type PrimitiveRegistration ¶
type PrimitiveRegistration struct {
Spec PrimitiveSpec
Phases Phase
}
PrimitiveRegistration holds a primitive and its phases.
type PrimitiveSpec ¶
type PrimitiveSpec struct {
Name string
ParamCount int
IsVariadic bool
Impl machine.ForeignFunction
Doc string // optional: brief description
ParamNames []string // optional: parameter names
Category string // optional: grouping category
ParamTypes []values.TypeConstraint // optional: type contract per parameter
ReturnType values.TypeConstraint // optional: return type (nil = unspecified)
Keywords []string // optional: searchable tags
}
PrimitiveSpec defines a primitive to be registered.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the central registry for primitives.
func (*Registry) AddBinding ¶
AddBinding registers a compile-time only binding (no runtime value).
func (*Registry) AddBindingSpecs ¶ added in v1.10.3
func (p *Registry) AddBindingSpecs(specs []BindingSpec)
AddBindingSpecs registers multiple compile-time bindings with optional documentation.
func (*Registry) AddBindings ¶
AddBindings registers multiple compile-time only bindings.
func (*Registry) AddDocOnlyPrimitive ¶ added in v1.10.9
func (p *Registry) AddDocOnlyPrimitive(spec PrimitiveSpec)
AddDocOnlyPrimitive registers a documentation-only primitive entry. It does not create a runtime binding — used for Scheme-defined procedures that are already bound in the environment but need registry visibility for apropos/topics. Skips registration if a primitive with the same name already exists (Go primitives take precedence).
func (*Registry) AddDocumentation ¶ added in v1.10.3
AddDocumentation registers a documentation entry for a named binding. The documentation is applied to existing bindings during ApplyDocs.
func (*Registry) AddGlobalValue ¶ added in v1.4.0
AddGlobalValue registers a named value to be bound as a global variable. Unlike AddPrimitive, this takes an arbitrary Value rather than a ForeignFunction.
func (*Registry) AddInitFunc ¶
AddInitFunc registers an initialization function.
func (*Registry) AddMacroSource ¶
AddMacroSource adds Scheme source code for bootstrap macros.
func (*Registry) AddPrimitive ¶
func (p *Registry) AddPrimitive(spec PrimitiveSpec, phases Phase)
AddPrimitive registers a primitive with the given phases.
func (*Registry) AddPrimitives ¶
func (p *Registry) AddPrimitives(specs []PrimitiveSpec, phases Phase)
AddPrimitives registers multiple primitives with the given phases.
func (*Registry) Apply ¶
func (p *Registry) Apply(ctx context.Context, env *environment.EnvironmentFrame) error
Apply materializes registry contents into an environment: compile-time bindings, runtime/expand-time primitives, global values, and init functions (in that order).
func (*Registry) ApplyDocs ¶ added in v1.10.3
func (p *Registry) ApplyDocs(env *environment.EnvironmentFrame)
ApplyDocs attaches documentation entries to existing bindings in the environment. It searches all phases for each documented name and sets the doc string on every matching binding. This is necessary because some names (e.g., special forms) have bindings in multiple phases (expand and compile), and the REPL's ,doc command may find any of them.
func (*Registry) BindingCount ¶
BindingCount returns the number of compile-time bindings.
func (*Registry) BindingSpecs ¶ added in v1.10.3
func (p *Registry) BindingSpecs() []BindingSpec
BindingSpecs returns a defensive copy of the compile-time binding specs.
func (*Registry) Docs ¶ added in v1.10.3
Docs returns a defensive copy of the documentation entries.
func (*Registry) FindPrimitive ¶ added in v1.3.0
func (p *Registry) FindPrimitive(name string, phase Phase) (PrimitiveRegistration, bool)
FindPrimitive returns the first registered primitive with the given name. If phase is non-zero, only primitives active in that phase are considered. If phase is zero, any phase matches.
func (*Registry) GlobalValues ¶ added in v1.4.0
func (p *Registry) GlobalValues() []GlobalValue
GlobalValues returns a copy of the global value registrations.
func (*Registry) HasPrimitive ¶ added in v1.3.0
HasPrimitive reports whether a primitive with the given name is registered. If phase is non-zero, only primitives active in that phase are considered. If phase is zero, any phase matches.
func (*Registry) MacroSources ¶
MacroSources returns copies of macro source strings.
func (*Registry) PrimitiveByName ¶ added in v1.3.0
func (p *Registry) PrimitiveByName(name string) (PrimitiveRegistration, bool)
PrimitiveByName returns the registration for the named primitive, if any.
func (*Registry) PrimitiveCount ¶
PrimitiveCount returns the number of registered primitives.
func (*Registry) PrimitiveNames ¶ added in v1.3.0
PrimitiveNames returns the names of all registered primitives in registration order.
func (*Registry) Primitives ¶
func (p *Registry) Primitives() []PrimitiveRegistration
Primitives returns a copy of the primitive registrations.
func (*Registry) PrimitivesByCategory ¶ added in v1.3.0
func (p *Registry) PrimitivesByCategory() map[string][]PrimitiveRegistration
PrimitivesByCategory returns registered primitives grouped by category. Primitives with no category are grouped under the empty string key.
func (*Registry) RuntimePrimitiveNamesRange ¶ added in v1.4.0
RuntimePrimitiveNamesRange returns the names of runtime primitives registered in the index range [startIndex, endIndex). If endIndex is negative, all primitives from startIndex onward are included. Negative startIndex is treated as 0.
func (*Registry) RuntimePrimitiveNamesSince ¶ added in v1.4.0
RuntimePrimitiveNamesSince returns the names of primitives registered at index >= startIndex that have PhaseRuntime. If startIndex is negative it is treated as 0. If startIndex exceeds the primitive count, nil is returned.
func (*Registry) Without ¶ added in v1.5.0
Without returns a new Registry with the named primitives removed. Names that don't match any registered primitive are silently ignored. Compile-time bindings, init funcs, macro sources, and global values are copied unchanged.
func (*Registry) WithoutBindings ¶ added in v1.5.0
WithoutBindings returns a new Registry with the named compile-time bindings removed. Use after Without to fully erase a name that exists as both a primitive and a compile-time binding (e.g., set!). Primitives, init funcs, macro sources, and global values are copied unchanged.
func (*Registry) WithoutCategory ¶ added in v1.5.0
WithoutCategory returns a new Registry with all primitives in the named categories removed. Categories are matched against PrimitiveSpec.Category. Compile-time bindings, init funcs, macro sources, and global values are copied unchanged.
type RegistryBuilder ¶
RegistryBuilder collects functions that add primitives to a registry.
func NewRegistryBuilder ¶
func NewRegistryBuilder(funcs ...func(*Registry) error) RegistryBuilder
NewRegistryBuilder creates a builder with the given registration functions.
func (RegistryBuilder) AddToRegistry ¶
func (p RegistryBuilder) AddToRegistry(r *Registry) error
AddToRegistry applies all registration functions to the registry.
func (RegistryBuilder) Build ¶
func (p RegistryBuilder) Build() (*Registry, error)
Build creates a new registry and applies all registration functions.
func (*RegistryBuilder) Register ¶
func (p *RegistryBuilder) Register(funcs ...func(*Registry) error)
Register adds registration functions to the builder.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core provides the essential primitives required for Scheme to function.
|
Package core provides the essential primitives required for Scheme to function. |
|
Package helpers provides shared utility functions for primitive implementations.
|
Package helpers provides shared utility functions for primitive implementations. |
|
Package testhelpers provides shared test infrastructure for Scheme primitive tests.
|
Package testhelpers provides shared test infrastructure for Scheme primitive tests. |