Class: Loxxy::BackEnd::Environment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(aParent = nil) ⇒ Environment

Construct a environment instance.

Parameters:

  • aParent (Environment, NilClass) (defaults to: nil)

    Parent environment to this one.



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

#defnsHash{String => Variable} (readonly)

Mapping from user-defined name to related definition (say, a variable object)

Returns:

  • (Hash{String => Variable})

    Pairs of the kind



26
27
28
# File 'lib/loxxy/back_end/environment.rb', line 26

def defns
  @defns
end

#embeddingBoolean

Returns true if this environment is part of a closure (contains an embedded function).

Returns:

  • (Boolean)

    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
  @embedding
end

#enclosingEnvironment, NilClass

The enclosing (parent) environment.

Returns:



14
15
16
# File 'lib/loxxy/back_end/environment.rb', line 14

def enclosing
  @enclosing
end

#expr_stackArray<LoxNode> (readonly)

Returns stack of values needed in evaluating an expression.

Returns:

  • (Array<LoxNode>)

    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

#predecessorEnvironment, NilClass

The previous environment in the environment chain.

Returns:



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.

Parameters:

Returns:



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

#inspectString

Returns a string with a human-readable representation of the object.

Returns:

  • (String)


51
52
53
# File 'lib/loxxy/back_end/environment.rb', line 51

def inspect
  +"#<#{self.class}:#{object_id.to_s(16)}>"
end