Documentation
¶
Overview ¶
Package env provides namespace and binding management for the Ale runtime. It implements lexical scoping, symbol resolution, and environment chaining that supports nested scopes, closures, and public/private visibility. This is the foundation for global storage and lookup throughout the Ale interpreter.
Index ¶
- Constants
- func BindPrivate(ns Namespace, n data.Local, v ale.Value) error
- func BindPublic(ns Namespace, n data.Local, v ale.Value) error
- func MustResolveValue(ns Namespace, s data.Symbol) ale.Value
- func ResolveSymbol(ns Namespace, s data.Symbol) (*Entry, Namespace, error)
- func ResolveValue(ns Namespace, s data.Symbol) (ale.Value, error)
- func RootSymbol(name data.Local) data.Symbol
- type Binder
- type Entries
- type Entry
- type Environment
- func (e *Environment) Domains() data.Locals
- func (e *Environment) GetAnonymous() Namespace
- func (e *Environment) GetQualified(n data.Local) (Namespace, error)
- func (e *Environment) GetRoot() Namespace
- func (e *Environment) NewQualified(n data.Local) (Namespace, error)
- func (e *Environment) Snapshot() *Environment
- type Namespace
Constants ¶
const ( // ErrNameAlreadyBound is raised when an attempt is made to bind a // Namespace entry that has already been bound ErrNameAlreadyBound = "name is already bound in namespace: %s" // ErrNameNotBound is raised when an attempt is made to retrieve a value // from a Namespace that hasn't been bound ErrNameNotBound = "name is not bound in namespace: %s" )
const ( ErrNamespaceNotFound = "namespace not found: %s" ErrNamespaceExists = "namespace already exists: %s" )
const ( // ErrNameAlreadyDeclared is raised when an attempt to declare a name is // performed that has already been declared with different privacy ErrNameAlreadyDeclared = "name already declared in namespace: %s" // ErrNameNotDeclared is raised when an attempt to forcefully resolve an // undeclared name in the Namespace fails ErrNameNotDeclared = "name not declared in namespace: %s" )
Variables ¶
This section is empty.
Functions ¶
func MustResolveValue ¶
MustResolveValue attempts to resolve a value or explodes violently
func ResolveSymbol ¶
ResolveSymbol attempts to resolve a symbol. If it's a qualified symbol, it will be retrieved directly from the identified namespace. Otherwise, it will be searched in the current namespace
func ResolveValue ¶
ResolveValue attempts to resolve a symbol to a bound value
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry represents a namespace entry
type Environment ¶
Environment maintains a mapping of domain names to namespaces
func NewEnvironment ¶
func NewEnvironment() *Environment
NewEnvironment creates a new synchronous namespace map
func (*Environment) Domains ¶
func (e *Environment) Domains() data.Locals
func (*Environment) GetAnonymous ¶
func (e *Environment) GetAnonymous() Namespace
GetAnonymous returns an anonymous (non-resolvable) namespace
func (*Environment) GetQualified ¶
func (e *Environment) GetQualified(n data.Local) (Namespace, error)
GetQualified returns the namespace for the specified domain.
func (*Environment) GetRoot ¶
func (e *Environment) GetRoot() Namespace
GetRoot returns the root namespace, where built-ins go
func (*Environment) NewQualified ¶ added in v0.3.0
func (e *Environment) NewQualified(n data.Local) (Namespace, error)
NewQualified creates a new namespace for the specified domain if it doesn't already exist.
func (*Environment) Snapshot ¶
func (e *Environment) Snapshot() *Environment
type Namespace ¶
type Namespace interface {
// Environment returns the environment associated with this namespace
Environment() *Environment
// Domain returns the domain name of this namespace
Domain() data.Local
// Declared returns all declared symbols in this namespace
Declared() data.Locals
// Public declares a public symbol in this namespace
Public(data.Local) (*Entry, error)
// Private declares a private symbol in this namespace
Private(data.Local) (*Entry, error)
// Resolve attempts to resolve a symbol in this namespace or its parents
Resolve(data.Local) (*Entry, Namespace, error)
// Snapshot creates a snapshot of this namespace for another environment
Snapshot(*Environment) Namespace
// Import atomically adds entries from another namespace to this one
Import(Entries) error
}
Namespace represents a namespace
func MustGetQualified ¶ added in v0.3.0
func MustGetQualified(e *Environment, n data.Local) Namespace
MustGetQualified attempts to retrieve a namespace for the specified domain. If the namespace does not exist, it will attempt to create it. If creation fails, it will panic.