Documentation ¶
Overview ¶
Package activations implements data structures that can be used when dealing with program scopes.
Index ¶
- type Activation
- type Activations
- func (a *Activations) Current() *Activation
- func (a *Activations) CurrentOrNew() *Activation
- func (a *Activations) Depth() int
- func (a *Activations) Find(key string) interface{}
- func (a *Activations) Pop()
- func (a *Activations) Push(activation *Activation)
- func (a *Activations) PushNewWithCurrent()
- func (a *Activations) PushNewWithParent(parent *Activation) *Activation
- func (a *Activations) Set(name string, value interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Activation ¶ added in v0.6.0
type Activation struct { Depth int Parent *Activation // contains filtered or unexported fields }
An Activation is a map of strings to arbitrary values. It can be used to represent an active scope in a program, i.e. it can be used as a symbol table during semantic analysis, or as an activation record during interpretation.
func NewActivation ¶ added in v0.6.0
func NewActivation(parent *Activation) *Activation
func (*Activation) Find ¶ added in v0.6.0
func (a *Activation) Find(name string) interface{}
Find returns the value for a given key in the activation. It returns nil if no value is found.
func (*Activation) ForEach ¶ added in v0.10.6
func (a *Activation) ForEach(cb func(string, interface{}) error) error
ForEach calls the given function for each entry (key-value pair) in the activation. It can be used to iterate over all entries of the activation.
func (*Activation) Set ¶ added in v0.12.6
func (a *Activation) Set(name string, value interface{})
Set sets the given key-value pair in the activation.
type Activations ¶
type Activations struct {
// contains filtered or unexported fields
}
Activations is a stack of activation records. Each entry represents a new ac.
The current / most nested activation record can be found at the top of the stack (see function `current`).
Each activation in the stack contains *all* active records – there is no need to traverse to parent records. This is implemented efficiently by using immutable maps that share data with their parents.
func (*Activations) Current ¶ added in v0.12.6
func (a *Activations) Current() *Activation
Current returns the current / most nested activation, which can be found at the top of the stack. It returns nil if there is no active activation.
func (*Activations) CurrentOrNew ¶
func (a *Activations) CurrentOrNew() *Activation
CurrentOrNew returns the current activation, or if it does not exists, a new activation
func (*Activations) Depth ¶
func (a *Activations) Depth() int
Depth returns the depth (size) of the activation stack.
func (*Activations) Find ¶
func (a *Activations) Find(key string) interface{}
Find returns the value for a given key in the current activation. It returns nil if no value is found or if there is no current activation.
func (*Activations) Pop ¶
func (a *Activations) Pop()
Pop pops the top-most (current) activation from the top of the activation stack.
func (*Activations) Push ¶
func (a *Activations) Push(activation *Activation)
Push pushes the given activation onto the top of the activation stack.
func (*Activations) PushNewWithCurrent ¶ added in v0.12.6
func (a *Activations) PushNewWithCurrent()
PushNewWithCurrent pushes a new empty activation to the top of the activation stack. The new activation has the current activation as its parent.
func (*Activations) PushNewWithParent ¶ added in v0.12.6
func (a *Activations) PushNewWithParent(parent *Activation) *Activation
PushNewWithParent pushes a new empty activation to the top of the activation stack. The new activation has the given parent as its parent.
func (*Activations) Set ¶
func (a *Activations) Set(name string, value interface{})
Set sets the key value pair int the current scope.