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.



30
31
32
33
# File 'lib/loxxy/back_end/environment.rb', line 30

def initialize(aParent = nil)
  @enclosing = aParent
  @defns = {}
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

#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:



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

#inspectString

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

Returns:

  • (String)


47
48
49
# File 'lib/loxxy/back_end/environment.rb', line 47

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