registry

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyContext

type ApplyContext interface {
	Context() context.Context
	Environment() *environment.EnvironmentFrame
}

ApplyContext provides context during registry application.

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 NewExtension

func NewExtension(name string, fn func(*Registry) error) Extension

NewExtension creates an Extension from a name and function.

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) Name

func (p *ExtensionFunc) Name() string

Name returns the extension name.

type InitFunc

type InitFunc func(ApplyContext) error

InitFunc is called after primitives are registered.

type Phase

type Phase int

Phase indicates when a primitive is available.

const (
	// PhaseRuntime indicates the primitive is available at runtime.
	PhaseRuntime Phase = 1 << iota
	// PhaseExpand indicates the primitive is available during macro expansion.
	PhaseExpand
	// PhaseCompile indicates the primitive is a compile-time binding (no value).
	PhaseCompile
)

func (Phase) HasCompile

func (p Phase) HasCompile() bool

HasCompile returns true if the phase includes compile time.

func (Phase) HasExpand

func (p Phase) HasExpand() bool

HasExpand returns true if the phase includes expand time.

func (Phase) HasRuntime

func (p Phase) HasRuntime() bool

HasRuntime returns true if the phase includes runtime.

func (Phase) String

func (p Phase) String() string

String returns a string representation of the phase.

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
}

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 NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new empty registry.

func (*Registry) AddBinding

func (p *Registry) AddBinding(name string)

AddBinding registers a compile-time only binding (no runtime value).

func (*Registry) AddBindings

func (p *Registry) AddBindings(names []string)

AddBindings registers multiple compile-time only bindings.

func (*Registry) AddInitFunc

func (p *Registry) AddInitFunc(f InitFunc)

AddInitFunc registers an initialization function.

func (*Registry) AddMacroSource

func (p *Registry) AddMacroSource(source string)

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

Apply registers all primitives and runs init functions on an environment.

func (*Registry) BindingCount

func (p *Registry) BindingCount() int

BindingCount returns the number of compile-time bindings.

func (*Registry) Bindings

func (p *Registry) Bindings() []string

Bindings returns a copy of the compile-time bindings.

func (*Registry) Clone

func (p *Registry) Clone() *Registry

Clone creates a copy of the registry.

func (*Registry) InitFuncs

func (p *Registry) InitFuncs() []InitFunc

InitFuncs returns a copy of the initialization functions.

func (*Registry) MacroSources

func (p *Registry) MacroSources() []string

MacroSources returns copies of macro source strings.

func (*Registry) PrimitiveCount

func (p *Registry) PrimitiveCount() int

PrimitiveCount returns the number of registered primitives.

func (*Registry) Primitives

func (p *Registry) Primitives() []PrimitiveRegistration

Primitives returns a copy of the primitive registrations.

type RegistryBuilder

type RegistryBuilder []func(*Registry) error

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.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL