Class: Loxxy::BackEnd::Environment
- Inherits:
-
Object
- Object
- Loxxy::BackEnd::Environment
- Defined in:
- lib/loxxy/back_end/environment.rb
Overview
A environment is a name space that corresponds either to a specific delimited region in Loxxy source code or to an activation record of a relation or a relation definition. It contains a map of names to the objects they name (e.g. logical var)
Instance Attribute Summary collapse
-
#defns ⇒ Hash{String => Variable}
readonly
Mapping from user-defined name to related definition (say, a variable object).
-
#embedding ⇒ Boolean
True if this environment is part of a closure (contains an embedded function).
-
#enclosing ⇒ Environment, NilClass
The enclosing (parent) environment.
-
#predecessor ⇒ Environment, NilClass
The previous environment in the environment chain.
Instance Method Summary collapse
-
#initialize(aParent = nil) ⇒ Environment
constructor
Construct a environment instance.
-
#insert(anEntry) ⇒ BackEnd::Variable
Add a new variable to the environment.
-
#inspect ⇒ String
Returns a string with a human-readable representation of the object.
Constructor Details
#initialize(aParent = nil) ⇒ Environment
Construct a environment instance.
30 31 32 33 |
# File 'lib/loxxy/back_end/environment.rb', line 30 def initialize(aParent = nil) @enclosing = aParent @defns = {} end |
Instance Attribute Details
#defns ⇒ Hash{String => Variable} (readonly)
Mapping from user-defined name to related definition (say, a variable object)
26 27 28 |
# File 'lib/loxxy/back_end/environment.rb', line 26 def defns @defns end |
#embedding ⇒ Boolean
Returns true if this environment is part of a closure (contains an embedded function).
21 22 23 |
# File 'lib/loxxy/back_end/environment.rb', line 21 def @embedding end |
#enclosing ⇒ Environment, NilClass
The enclosing (parent) environment.
14 15 16 |
# File 'lib/loxxy/back_end/environment.rb', line 14 def enclosing @enclosing end |
#predecessor ⇒ Environment, NilClass
The previous environment in the environment chain.
18 19 20 |
# File 'lib/loxxy/back_end/environment.rb', line 18 def predecessor @predecessor end |
Instance Method Details
#insert(anEntry) ⇒ BackEnd::Variable
Add a new variable to the environment.
38 39 40 41 42 43 |
# File 'lib/loxxy/back_end/environment.rb', line 38 def insert(anEntry) e = validated_entry(anEntry) defns[e.name] = e e end |
#inspect ⇒ String
Returns a string with a human-readable representation of the object.
47 48 49 |
# File 'lib/loxxy/back_end/environment.rb', line 47 def inspect +"#<#{self.class}:#{object_id.to_s(16)}>" end |