org.erights.e.elang.scope
Class ScopeMap

java.lang.Object
  |
  +--org.erights.e.elang.scope.ScopeMap
Direct Known Subclasses:
ScopeMapBase, ScopeMapContour, ScopeMapLink

public abstract class ScopeMap
extends Object

Untamed: Static information about the runtime representation of a Scope.

A ScopeMap and an EvalContext together form a Scope. The ScopeMap maps from names to NounExprs which will retrieve the corresponding org.erights.e.elib.slot.Slot or value from a corresponding EvalContext. Each EvalContext can be seen as an instantiation of a ScopeMap.

A ScopeMap is built out of layered scopes, with the layers separated by ScopeMapContours. At the lowest layer is a ScopeMapBase that may contain many bindings; each additional binding is added in a ScopeMapLink. For example, if a, b, and c are extant in the outermost scope, and declarations are added like this:

     def d := ...
     {
         def e := ...
         def f := ...
         {
             def g := ...
         }
     }
 
then the resulting structure would look like this:
                         ____________________________________________
                        |                           _______________  |
                        |                          |               | |
     Base <- Link <- Contour <- Link <- Link <- Contour <- Link    | |
   a, b, c     d        |         e       f        |         g     | |
                        |                          |_______________| |
                        |____________________________________________|
 
ScopeMaps are DeepFrozen (though not currently DeepPassByCopy). They are therefore thread-safe, and can be shared between vats. This is necessary for OuterScope.diverge(java.lang.String) to be thread-safe.

Author:
E. Dean Tribble, some mods by Mark S. Miller, more docs by Ka-Ping Yee

Field Summary
static ScopeMap EMPTY
          Enabled: The empty ScopeMap
 
Constructor Summary
ScopeMap()
          Enabled:
 
Method Summary
(package private) abstract  void addNamesTo(FlexSet names)
          Adds all the names mapped by this ScopeMap to 'names'
abstract  void assertShadowable(String varName)
          Enabled: Throw an exception is the varName may not be shadowed because it is already defined in the current (i.e.
abstract  boolean contains(String varName)
          Enabled: Is 'varName' in scope?
abstract  NounExpr getNoun(String varName)
          Enabled: Gets the NounExpr which will retrieve the Slot/value of the variable named 'varName' from a corresponding EvalContext.
static ScopeMap make(ConstMap bindings)
          Enabled: @param bindings must be a mapping from names (Strings) to NounExprs.
 ConstSet namesSet()
          Enabled: Return the set of all names mapped by this ScopeMap.
 ScopeMap nested()
          Enabled: Makes a new ScopeMap just like this one, but with a new empty innermost contour added.
 ScopeMap with(String varName, NounExpr noun)
          Enabled: Returns a ScopeMap just like this one, but with a new varName => NounExpr mapping added to the innermost contour.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final ScopeMap EMPTY
Enabled: The empty ScopeMap

Constructor Detail

ScopeMap

public ScopeMap()
Enabled:

Method Detail

make

public static ScopeMap make(ConstMap bindings)
Enabled: @param bindings must be a mapping from names (Strings) to NounExprs.

Returns:
The ScopeMap representing exactly this mapping as a single contour

getNoun

public abstract NounExpr getNoun(String varName)
Enabled: Gets the NounExpr which will retrieve the Slot/value of the variable named 'varName' from a corresponding EvalContext.


contains

public abstract boolean contains(String varName)
Enabled: Is 'varName' in scope?


with

public ScopeMap with(String varName,
                     NounExpr noun)
Enabled: Returns a ScopeMap just like this one, but with a new varName => NounExpr mapping added to the innermost contour.

This does not create a new contour, so this operation is rejected if varName is already defined in the innermost contour.


namesSet

public ConstSet namesSet()
Enabled: Return the set of all names mapped by this ScopeMap.


addNamesTo

abstract void addNamesTo(FlexSet names)
Adds all the names mapped by this ScopeMap to 'names'


nested

public ScopeMap nested()
Enabled: Makes a new ScopeMap just like this one, but with a new empty innermost contour added.


assertShadowable

public abstract void assertShadowable(String varName)
Enabled: Throw an exception is the varName may not be shadowed because it is already defined in the current (i.e. innermost) contour.

If varName may not be shadowed because it is reserved, this is caught in org.erights.e.elang.evm.NounPattern rather than here.



comments?