orc.runtime
Class Token

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

public class Token
extends java.lang.Object
implements java.io.Serializable, 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
          The location of the token in the DAG; determines what the token will do next.
 
Method Summary
 void activate()
           
 Token bind(java.lang.Object f)
          Push a new future onto the environment stack
 void debug(java.lang.String s)
           
 void delay(int delay)
           
 void die()
          Kill this token.
 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(Group group, Region region)
          Fork a token with a specified group and region.
 OrcEngine getEngine()
           
 Env<java.lang.Object> getEnvironment()
           
 Group getGroup()
           
 Node getNode()
           
 Region getRegion()
           
 java.lang.Object getResult()
           
 SourceLocation getSourceLocation()
           
 TokenTracer getTracer()
           
 Transaction getTransaction()
           
 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 popLtimer()
           
 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 pushLtimer()
           
 void requireCapability(java.lang.String name, boolean ifNull)
           
 void resume()
           
 void resume(java.lang.Object object)
           
 Token setGroup(Group group)
           
 void setQuiescent()
           
 Token setRegion(Region region)
          Migrate the token from one region to another.
 Token setResult(java.lang.Object result)
           
 void setSourceLocation(SourceLocation location)
           
 Token setTransaction(Transaction trans)
           
 void unsetQuiescent()
           
 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
The location of the token in the DAG; determines what the token will do next.

Method Detail

die

public final void die()
Kill this token. Should only be called on non-quiescent tokens. Synchronized because tokens may be killed from site threads.


process

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


getNode

public final Node getNode()

getGroup

public final Group getGroup()

getEnvironment

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

getResult

public final java.lang.Object getResult()

getEngine

public final OrcEngine getEngine()

getRegion

public final Region getRegion()

getTransaction

public final Transaction getTransaction()

setResult

public final Token setResult(java.lang.Object result)

setGroup

public final Token setGroup(Group group)

setTransaction

public final Token setTransaction(Transaction trans)

setRegion

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


getTracer

public final TokenTracer getTracer()

move

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

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

enterClosure

public final 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 final Token leaveClosure()
Leave a closure by returning to the continuation set by #enterClosure(Node, Env, Node).


bind

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

Parameters:
f - future to push
Returns:
self

unwind

public final 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 final 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

debug

public final void debug(java.lang.String s)

activate

public final void activate()

resume

public final void resume(java.lang.Object object)

resume

public final void resume()

error

public final void error(TokenException problem)

print

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


publish

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


fork

public final Token fork()
                 throws TokenLimitReachedError
Fork a token.

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

fork

public final Token fork(Group 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 final void setSourceLocation(SourceLocation location)
Specified by:
setSourceLocation in interface Locatable

getSourceLocation

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

unsetQuiescent

public final void unsetQuiescent()

setQuiescent

public final void setQuiescent()

requireCapability

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

delay

public final void delay(int delay)

pushLtimer

public final void pushLtimer()

popLtimer

public final void popLtimer()
                     throws SiteException
Throws:
SiteException