orc.runtime.values
Class Closure

java.lang.Object
  extended by orc.runtime.values.Value
      extended by orc.runtime.values.Closure
All Implemented Interfaces:
Callable, Future

public class Closure
extends Value
implements Callable

Represents a standard closure: a function defined in an environment. Note that a closure is not necessarily a resolved value, since it may contain unbound variables, and therefore cannot be used in arg position until all such variables become bound.

Author:
wcook, dkitchin

Constructor Summary
Closure(int arity, Node body, Env env)
           
 
Method Summary
<E> E
accept(Visitor<E> visitor)
           
 void createCall(Token callToken, java.util.List<Future> args, Node nextNode)
          To create a call to a closure, a new token is created using the environment in which the closure was defined.
 void setEnvironment(Env env)
           
 
Methods inherited from class orc.runtime.values.Value
forceArg, forceCall, head, isCons, isNil, isNone, isSome, signal, tail, untag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Closure

public Closure(int arity,
               Node body,
               Env env)
Method Detail

createCall

public void createCall(Token callToken,
                       java.util.List<Future> args,
                       Node nextNode)
                throws ArityMismatchException
To create a call to a closure, a new token is created using the environment in which the closure was defined. This environment is then extended to bind the formals to the actual arguments. The caller of the new token is normally a token point to right after the call. However, for tail-calls the existing caller is reused, rather than creating a new intermediate stack frame.

Specified by:
createCall in interface Callable
Parameters:
callToken - token for which the call is being made: points to the call node
args - argument list
nextNode - next node after the call node, to which the result should be sent
Throws:
ArityMismatchException

setEnvironment

public void setEnvironment(Env env)

accept

public <E> E accept(Visitor<E> visitor)
Specified by:
accept in class Value