orc.env
Class Env<T>

java.lang.Object
  extended by orc.env.Env<T>
All Implemented Interfaces:
java.io.Serializable

public class Env<T>
extends java.lang.Object
implements java.io.Serializable

Generic indexed environment, used primarily at runtime. Env is also content addressable, so it can be used for the deBruijn index conversion in the compiler.

Author:
dkitchin
See Also:
Serialized Form

Nested Class Summary
protected static class Env.ENode<T>
          Individual entries in the environment.
 
Constructor Summary
  Env()
           
protected Env(Env.ENode<T> node)
           
 
Method Summary
 Env<T> add(T item)
           
 Env<T> addAll(java.util.List<T> items)
           
 java.util.List<T> items()
          Return a list of items in the order they were added.
 T lookup(int index)
          Lookup a variable in the environment Currently uses a linear search.
 int search(T target)
          Content addressable mode.
 java.lang.String toString()
           
 Env<T> unwind(int width)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Env

protected Env(Env.ENode<T> node)

Env

public Env()
Method Detail

add

public Env<T> add(T item)

items

public java.util.List<T> items()
Return a list of items in the order they were added.


addAll

public Env<T> addAll(java.util.List<T> items)

lookup

public T lookup(int index)
Lookup a variable in the environment Currently uses a linear search.

Parameters:
index - Stack depth (a deBruijn index)
Returns:
The bound item

search

public int search(T target)
Content addressable mode. Used in compilation to determine the deBruijn indices from an environment populated by Var objects. Assuming no error is raised, search and lookup are inverses: search(lookup(i)) = i lookup(search(o)) = o

Parameters:
target - The item
Returns:
The index of the target item

unwind

public Env<T> unwind(int width)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object