org.erights.e.elang.scope
Class Scope

java.lang.Object
  |
  +--org.erights.e.elang.scope.Scope
All Implemented Interfaces:
Iteratable
Direct Known Subclasses:
InnerScope, OuterScope

public abstract class Scope
extends Object
implements Iteratable

Untamed: A ConstMap (sort of) from names (strings) to Slots. Scopes inherit from each other in a tree, so they can be used to model nesting lexical environments. The associations in the most leafward part of a Scope are called "locals".

Author:
E. Dean Tribble, Mark S. Miller

Field Summary
(package private)  ScopeMap myScopeMap
           
 
Constructor Summary
(package private) Scope(ScopeMap map)
           
 
Method Summary
 ConstMap asMap()
          Enabled:
 void bindFinal(String name, Object theValue)
          Enabled: The default implementation here just works in terms of bindOuter().
 UnQuote bindings()
          Enabled: universalFlag defaults to true
 UnQuote bindings(boolean showSafeFlag)
          Enabled: Returns a string showing the bindings in this scope in a pleasant, human readable format.
abstract  void bindOuter(String name, Slot slot)
          Enabled: A normal Scope returns a Scope just like this one, except for a new local binding 'name' to 'slot'.
 void cleanup()
          Enabled: Handle any messes left behind after a top-level exception.
abstract  Scope diverge(String fqnPrefix)
          Enabled: A new Scope object just like this one, except that it's extensible, but not otherwise mutable, and extension (which are only to the innermost contour) do not affect the inner scope.
 Object get(String name)
          Enabled: Gets the value of the slot associated with name.
 Object get(String name, Object instead)
          Enabled:
abstract  String getOptFQNPrefix()
          Enabled: What prefix should be used to turn relative behavior names into fully qualified names?
 ScopeMap getScopeMap()
          Enabled:
abstract  Slot getSlot(String name)
          Enabled:
static Scope in(ENode node, EvalContext ctx)
          Enabled:
 void iterate(AssocFunc func)
          Enabled:
private  ConstMap locals()
           
 boolean maps(String name)
          Enabled:
abstract  EvalContext newContext(int numLocals)
          Enabled:
private  void printBindingsOn(boolean showSafeFlag, TextWriter out)
           
 void put(String name, Object newValue)
          Enabled: The default put() is defined in the obvious fashion in terms of getSlot().setValue(newValue).
abstract  NounExpr reserveOuterNoun(String name)
          Enabled:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myScopeMap

ScopeMap myScopeMap
Constructor Detail

Scope

Scope(ScopeMap map)
Method Detail

in

public static Scope in(ENode node,
                       EvalContext ctx)
Enabled:


getOptFQNPrefix

public abstract String getOptFQNPrefix()
Enabled: What prefix should be used to turn relative behavior names into fully qualified names?


newContext

public abstract EvalContext newContext(int numLocals)
Enabled:


maps

public boolean maps(String name)
Enabled:

Parameters:
name -
Returns:

getSlot

public abstract Slot getSlot(String name)
Enabled:


get

public Object get(String name)
Enabled: Gets the value of the slot associated with name. Just a convenience implemented out of getSlot()


get

public Object get(String name,
                  Object instead)
Enabled:

Parameters:
name -
instead -
Returns:

put

public void put(String name,
                Object newValue)
Enabled: The default put() is defined in the obvious fashion in terms of getSlot().setValue(newValue).


getScopeMap

public ScopeMap getScopeMap()
Enabled:


reserveOuterNoun

public abstract NounExpr reserveOuterNoun(String name)
Enabled:


asMap

public ConstMap asMap()
Enabled:


iterate

public void iterate(AssocFunc func)
Enabled:

Specified by:
iterate in interface Iteratable
Parameters:
func -

bindFinal

public void bindFinal(String name,
                      Object theValue)
               throws AlreadyDefinedException
Enabled: The default implementation here just works in terms of bindOuter().

An interactive top-level Scope (a MutableScope) adds a 'name' => 'slot' binding to itself if necessary.

AlreadyDefinedException

bindings

public UnQuote bindings()
                 throws IOException
Enabled: universalFlag defaults to true

IOException

bindings

public UnQuote bindings(boolean showSafeFlag)
                 throws IOException
Enabled: Returns a string showing the bindings in this scope in a pleasant, human readable format.

Parameters:
showSafeFlag - If set, then unshadowable names from the safe scope will be shown as well.
IOException

printBindingsOn

private void printBindingsOn(boolean showSafeFlag,
                             TextWriter out)
                      throws IOException
IOException

bindOuter

public abstract void bindOuter(String name,
                               Slot slot)
                        throws AlreadyDefinedException
Enabled: A normal Scope returns a Scope just like this one, except for a new local binding 'name' to 'slot'.

If this scope already has a local for 'name', bindOuter() normally throws AlreadyDefinedException. But an interactive top-level Scope (a MutableScope) adds a 'name' => 'slot' binding to itself if necessary. If there already is a local named 'name', bindOuter() replaces it.

AlreadyDefinedException

diverge

public abstract Scope diverge(String fqnPrefix)
Enabled: A new Scope object just like this one, except that it's extensible, but not otherwise mutable, and extension (which are only to the innermost contour) do not affect the inner scope.

Unlike the old sprout(), diverge()ing a Scope does not add a new contour, but rather copies the existing innermost contour.


locals

private ConstMap locals()

cleanup

public void cleanup()
Enabled: Handle any messes left behind after a top-level exception.



comments?