orc.runtime
Class Token

java.lang.Object
  extended by orc.runtime.Token
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Token>, Locatable, Located

public final class Token
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<Token>, Locatable

Representation of an active thread of execution. Tokens move over the node graph as they are executed. They contain an environment, and may belong to a group. They also preserve the call chain and contain a value to be passed to the next token.

Author:
wcook, dkitchin, quark
See Also:
Serialized Form

Field Summary
 Node node
           
 
Method Summary
 void activate()
           
 Token bind(java.lang.Object f)
          Push a new future onto the environment stack
 int compareTo(Token t)
           
 void debug(java.lang.String s)
           
 void die()
           
 Token enterClosure(Closure closure, Node next)
          Enter a closure by moving to a new node and environment, and setting the continuation for leaveClosure().
 void error(TokenException problem)
           
 Token fork()
          Fork a token.
 Token fork(GroupCell group, Region region)
          Fork a token with a specified group and region.
 OrcEngine getEngine()
           
 Env<java.lang.Object> getEnvironment()
           
 GroupCell getGroup()
           
 Node getNode()
           
 Region getRegion()
           
 java.lang.Object getResult()
           
 SourceLocation getSourceLocation()
           
 TokenTracer getTracer()
           
 Token leaveClosure()
          Leave a closure by returning to the continuation set by #enterClosure(Node, Env, Node).
 java.lang.Object lookup(Arg var)
          Lookup a variable in the environment
 Token move(Node node)
          Move to a node node
 void print(java.lang.String string, boolean newline)
          Print something (for use by the print and println sites).
 void process()
          If a token is alive, calls the node to perform the next action.
 void publish()
          Publish a value to the top level.
 void requireCapability(java.lang.String name, boolean ifNull)
           
 void resume()
           
 void resume(java.lang.Object object)
           
 Token setGroup(GroupCell group)
           
 void setPending()
           
 Token setRegion(Region region)
          Migrate the token from one region to another.
 Token setResult(java.lang.Object result)
           
 void setSourceLocation(SourceLocation location)
           
 void unsetPending()
           
 Token unwind(int width)
          Pop values off of the environment stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

public Node node
Method Detail

die

public void die()

process

public void process()
If a token is alive, calls the node to perform the next action.


getNode

public Node getNode()

getGroup

public GroupCell getGroup()

getEnvironment

public Env<java.lang.Object> getEnvironment()

getResult

public java.lang.Object getResult()

getEngine

public OrcEngine getEngine()

getRegion

public Region getRegion()

setResult

public Token setResult(java.lang.Object result)

setGroup

public Token setGroup(GroupCell group)

setRegion

public Token setRegion(Region region)
Migrate the token from one region to another.


getTracer

public TokenTracer getTracer()

move

public Token move(Node node)
Move to a node node

Parameters:
node - the node to move to
Returns:
returns self

enterClosure

public Token enterClosure(Closure closure,
                          Node next)
                   throws StackLimitReachedError
Enter a closure by moving to a new node and environment, and setting the continuation for leaveClosure().

Throws:
StackLimitReachedError

leaveClosure

public Token leaveClosure()
Leave a closure by returning to the continuation set by #enterClosure(Node, Env, Node).


bind

public Token bind(java.lang.Object f)
Push a new future onto the environment stack

Parameters:
f - future to push
Returns:
self

unwind

public Token unwind(int width)
Pop values off of the environment stack. Used to leave binding scopes.

Parameters:
width - number of bindings to leave
Returns:
self

lookup

public java.lang.Object lookup(Arg var)
                        throws SiteResolutionException
Lookup a variable in the environment

Parameters:
var - variable name
Returns:
value, or an error if the variable is undefined
Throws:
SiteResolutionException

compareTo

public int compareTo(Token t)
Specified by:
compareTo in interface java.lang.Comparable<Token>

debug

public void debug(java.lang.String s)

activate

public void activate()

resume

public void resume(java.lang.Object object)

resume

public void resume()

error

public void error(TokenException problem)

print

public void print(java.lang.String string,
                  boolean newline)
Print something (for use by the print and println sites).


publish

public void publish()
Publish a value to the top level.


fork

public Token fork()
           throws TokenLimitReachedError
Fork a token.

Throws:
TokenLimitReachedError
See Also:
fork(GroupCell, Region)

fork

public Token fork(GroupCell group,
                  Region region)
           throws TokenLimitReachedError
Fork a token with a specified group and region. By convention, the original token continues on the left while the new token evaluates the right (this order is arbitrary, but right-branching ensures fewer tokens are created with the common left-associative asymmetric combinators).

Throws:
TokenLimitReachedError

setSourceLocation

public void setSourceLocation(SourceLocation location)
Specified by:
setSourceLocation in interface Locatable

getSourceLocation

public SourceLocation getSourceLocation()
Specified by:
getSourceLocation in interface Located

setPending

public void setPending()

unsetPending

public void unsetPending()

requireCapability

public void requireCapability(java.lang.String name,
                              boolean ifNull)
                       throws CapabilityException
Throws:
CapabilityException