Documentation
¶
Overview ¶
Package runtime provides the runtime environment initialization for the Scheme interpreter.
This package is responsible for:
- Creating and initializing the top-level environment with all R7RS primitives
- Loading bootstrap macros (and, or, let, let*, letrec, cond, when, unless)
Architecture ¶
The runtime creates a three-phase environment hierarchy:
TopLevel (Runtime) -> Expand -> Compile
Primitives are registered via the registry pattern from registry/core and extensions/*.
Package bootstrap initializes the top-level Scheme environment.
The package creates and bootstraps complete runtime environments using the registry pattern:
env, err := bootstrap.NewNamespaceFrame(ctx)
Initialization ¶
NewNamespaceFrame performs these steps:
- Creates a registry with core primitives
- Adds all extensions (io, files, math, eval, exceptions, threads, etc.)
- Creates a new Namespace with per-instance symbol interning
- Applies all primitives to the environment
- Registers syntax compilers and primitive expanders
- Loads bootstrap macros
Library Environments ¶
NewLibraryEnvironmentFrame creates environments for R7RS libraries that share symbol interning with the caller but isolate bindings:
libEnv, err := bootstrap.NewLibraryEnvironmentFrame(ctx, callerEnv)
This ensures (eq? 'foo (string->symbol "foo")) returns #t across library boundaries per R7RS 6.5.
Index ¶
- Variables
- func NewLibraryEnvironmentFrame(ctx context.Context, callerEnv *environment.EnvironmentFrame, _ []string) (*environment.EnvironmentFrame, error)
- func NewNamespaceFrame(ctx context.Context) (*environment.EnvironmentFrame, error)
- func NewProfileEnvironment(ctx context.Context, callerNS *environment.Namespace, ...) (*environment.Namespace, error)
- func NewTopLevelWithRegistry(ctx context.Context) (*environment.EnvironmentFrame, *registry.Registry, error)
- func ProfileExtensions(name string) ([]registry.Extension, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownProfile = werr.NewStaticError("unknown profile")
ErrUnknownProfile is returned by ProfileExtensions when given a name outside the known set (tiny, console, console-with-load, small, kitchen-sink).
Functions ¶
func NewLibraryEnvironmentFrame ¶
func NewLibraryEnvironmentFrame(ctx context.Context, callerEnv *environment.EnvironmentFrame, _ []string) (*environment.EnvironmentFrame, error)
NewLibraryEnvironmentFrame creates a new environment for a library that shares the Namespace with the caller. This ensures symbol identity is preserved across library boundaries per R7RS §6.5: (eq? 'foo (string->symbol "foo")) must be #t.
The library gets its own:
- GlobalEnvironmentFrame for bindings (isolates library definitions)
- PhaseRegistry for expand/compile phases
But shares with caller:
- Namespace (symbol and syntax interning)
- LibraryRegistry (for nested imports)
func NewNamespaceFrame ¶
func NewNamespaceFrame(ctx context.Context) (*environment.EnvironmentFrame, error)
NewNamespaceFrame creates and initializes a complete Scheme runtime environment.
This function:
- Creates a registry with core primitives
- Adds all extensions (io, files, math, introspection, eval, threads, gointerop, all, system)
- Creates a new Namespace with per-instance symbol interning
- Applies the registry to register all primitives
- Registers primitive compilers in the compile environment
- Loads bootstrap macros (and, or, let, let*, letrec, cond, when, unless, parameterize)
The resulting environment is ready for parsing, expanding, compiling, and executing Scheme programs.
func NewProfileEnvironment ¶
func NewProfileEnvironment(ctx context.Context, callerNS *environment.Namespace, exts []registry.Extension) (*environment.Namespace, error)
NewProfileEnvironment creates a new *environment.Namespace initialized with the given extension set. It shares symbol interning with callerNS but has its own bindings so the caller's top-level definitions do not leak in. Intended for Scheme-level (environment '(wile <profile>)) construction.
func NewTopLevelWithRegistry ¶
func NewTopLevelWithRegistry(ctx context.Context) (*environment.EnvironmentFrame, *registry.Registry, error)
NewTopLevelWithRegistry creates a top-level environment and returns both the environment frame and the primitive registry for doc introspection.
Top-level immutability is deliberately NOT enabled here. This is the policy-free bootstrap building block (sealed base + mutable runtime, fully populated); the immutable-top-level default is a PRODUCT policy applied by the public Engine (pkg/wile NewEngine via SetImmutableTopLevel). Callers using this internal constructor directly (test helpers, internal tooling) therefore get a mutable top level, which is the right default for redefine-heavy test code. Embedders use the public Engine and get the immutable default.
func ProfileExtensions ¶
ProfileExtensions returns the extension set for a named profile. It is the single source of truth for profile→extensions mapping; callers in the public wile package (profile.go Profile.extensions) and in extensions/eval (tryWileProfile, for Scheme-level (environment '(wile <name>))) both dispatch through here.
Valid names: "tiny", "console", "console-with-load", "small", "kitchen-sink". An unknown name returns ErrUnknownProfile wrapped with the offending string.
Types ¶
This section is empty.