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

Nested Class Summary
protected static class Token.Continuation
          Return pointer for a function call.
 
Field Summary
protected  boolean alive
           
protected  Token.Continuation continuation
           
protected  OrcEngine engine
           
protected  Env<java.lang.Object> env
           
protected  GroupCell group
           
protected  SourceLocation location
          The location of the token in the source code.
protected  Node node
           
protected  Region region
           
protected  java.lang.Object result
           
protected  TokenTracer tracer
           
 
Constructor Summary
  Token(Node node, Env<java.lang.Object> env, GroupCell group, Region region, OrcEngine engine, TokenTracer tracer)
           
protected Token(Node node, Env<java.lang.Object> env, Token.Continuation continuation, GroupCell group, Region region, java.lang.Object result, OrcEngine engine, TokenTracer tracer)
          Copy constructor
 
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(Node node, Env<java.lang.Object> env, Node next)
          Enter a closure by moving to a new node and environment, and setting the continuation for leaveClosure().
 void error(TokenException problem)
           
 void finalize()
           
 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 setEnv(Env<java.lang.Object> e)
           
 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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

protected Node node

env

protected Env<java.lang.Object> env

group

protected GroupCell group

region

protected Region region

engine

protected OrcEngine engine

location

protected SourceLocation location
The location of the token in the source code. This is set whenever the token begins processing a new node. Why not just use the location of the current node? Because e.g. during a site call this.node actually points to the next node, not the current one, so the source location would be incorrect.


tracer

protected TokenTracer tracer

continuation

protected Token.Continuation continuation

result

protected java.lang.Object result

alive

protected boolean alive
Constructor Detail

Token

protected Token(Node node,
                Env<java.lang.Object> env,
                Token.Continuation continuation,
                GroupCell group,
                Region region,
                java.lang.Object result,
                OrcEngine engine,
                TokenTracer tracer)
Copy constructor


Token

public Token(Node node,
             Env<java.lang.Object> env,
             GroupCell group,
             Region region,
             OrcEngine engine,
             TokenTracer tracer)
Method Detail

die

public void die()

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

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

setEnv

public Token setEnv(Env<java.lang.Object> e)

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(Node node,
                          Env<java.lang.Object> env,
                          Node next)
Enter a closure by moving to a new node and environment, and setting the continuation for leaveClosure().


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

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

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()
Fork a token.

See Also:
fork(GroupCell, Region)

fork

public Token fork(GroupCell group,
                  Region region)
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).


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