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 jthywiss
See Also:
Serialized Form

Method Summary
 void activate()
           
 Token bind(java.lang.Object f)
          Push a new future onto the environment stack
 void delay(int delay)
           
 void die()
          Kill this token.
 Token enterClosure(Closure closure, TokenContinuation publishContinuation)
          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()
           
 LogicalClock getLtimer()
          Used for Ltimer.time().
 Expression getNode()
           
 Region getRegion()
           
 java.lang.Object getResult()
           
 SourceLocation getSourceLocation()
           
 TokenTracer getTracer()
           
 void leave()
          Convenience method for node.leave(this);
 Token leaveClosure()
          Leave a closure by returning to the continuation set by enterClosure(Closure, TokenContinuation).
 java.lang.Object lookup(Argument var)
          Lookup a variable in the environment
 Token move(Expression right)
          Move to a node node
 void popHandler()
          pop an exception frame off the stack:
 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 pushHandler(Closure closure, TokenContinuation handlerReturn)
           
 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)
           
 void throwException(java.lang.Object exceptionValue)
           
 void throwJavaException(TokenException problem)
           
 void throwRuntimeException(TokenException problem)
           
 void unsetQuiescent()
           
 Token unwind()
          Pop one value off of the environment stack.
 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
 

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 Expression 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()

setResult

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

setGroup

public final Token setGroup(Group group)

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(Expression right)
Move to a node node

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

enterClosure

public final Token enterClosure(Closure closure,
                                TokenContinuation publishContinuation)
                         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(Closure, TokenContinuation).


popHandler

public void popHandler()
pop an exception frame off the stack:


throwException

public void throwException(java.lang.Object exceptionValue)
                    throws TokenLimitReachedError,
                           TokenException
Throws:
TokenLimitReachedError
TokenException

pushHandler

public void pushHandler(Closure closure,
                        TokenContinuation handlerReturn)

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()
Pop one value off of the environment stack. Used to leave binding scopes.

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(Argument var)
Lookup a variable in the environment

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

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)

throwRuntimeException

public void throwRuntimeException(TokenException problem)

throwJavaException

public void throwJavaException(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

getLtimer

public final LogicalClock getLtimer()
Used for Ltimer.time().


leave

public void leave()
Convenience method for node.leave(this);