class Kaze::Environment

Overview

Environment where variable bindings are to be stored.

Defined in:

environment.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(enclosing : Environment | Nil = nil) #

Initialize an environment instance. The enclosing environment is nil if no argument is provided, indicating that that environment is global.


[View source]

Instance Method Detail

def ancestor(distance : Int32) : Environment #

Returns the ancestor environment at a particular distance of scopes away.


[View source]
def assign(name : Token, value : VG) #

Assigns a value to an existing variable. If the enclosing environment exists, it assigns the variable present there. Raises an exception if the requested variable doesn't exist.


[View source]
def assign_at(distance : Int32, name : Token, value : VG) #

Does the same thing as Environment#assign, except from a specific ancestor environment.


[View source]
def define(name : String, value : VG) #

Defines a new variable binding. If the variable name is _, no definition is done.


[View source]
def enclosing : Kaze::Environment? #

The environment enclosing a new instance.


[View source]
def enclosing=(enclosing : Nil | Kaze::Environment) #

The environment enclosing a new instance.


[View source]
def get(name : Token) : VG #

Returns the value of the variable matching name's lexeme. If an enclosing environment exists, it fetches the variable from there. Raises an exception if the requested variable has a value of nil, or if it doesn't exist.


[View source]
def get_at(distance : Int32, name : String) #

Does the same thing as Environment#get, except from a specific ancestor environment.


[View source]
def values : Hash(String, Bool | Float64 | Kaze::Callable | Kaze::Instance | String | Nil) #

The values in the environment.


[View source]
def values=(values : Hash(String, Bool | Float64 | Kaze::Callable | Kaze::Instance | String | Nil)) #

The values in the environment.


[View source]