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.
-
#expr_stack ⇒ Array<LoxNode>
readonly
Stack of values needed in evaluating an expression.
-
#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.
33 34 35 36 37 |
# File 'lib/loxxy/back_end/environment.rb', line 33 def initialize(aParent = nil) @enclosing = aParent @defns = {} @expr_stack = [] 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 |
#expr_stack ⇒ Array<LoxNode> (readonly)
Returns stack of values needed in evaluating an expression.
29 30 31 |
# File 'lib/loxxy/back_end/environment.rb', line 29 def expr_stack @expr_stack 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.
42 43 44 45 46 47 |
# File 'lib/loxxy/back_end/environment.rb', line 42 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.
51 52 53 |
# File 'lib/loxxy/back_end/environment.rb', line 51 def inspect +"#<#{self.class}:#{object_id.to_s(16)}>" end |