gnu.mapping
Class CallContext

java.lang.Object
  extended by gnu.mapping.CallContext
Direct Known Subclasses:
ServletCallContext

public class CallContext
extends java.lang.Object

A procedure activation stack (when compiled with explicit stacks).


Field Summary
static int ARG_IN_IVALUE1
           
static int ARG_IN_IVALUE2
           
static int ARG_IN_VALUE1
           
static int ARG_IN_VALUE2
           
static int ARG_IN_VALUE3
           
static int ARG_IN_VALUE4
           
static int ARG_IN_VALUES_ARRAY
           
 Consumer consumer
          Function results are written to this Consumer.
 int count
          Number of actual arguments.
 java.lang.Object[][] evalFrames
          Current stack of evaluation frames for interpreter.
 int ivalue1
           
 int ivalue2
           
 int next
          Index of next argument.
 int pc
          The program location in the current procedure.
 Procedure proc
           
 java.lang.Object value1
          Used for passing parameters.
 java.lang.Object value2
           
 java.lang.Object value3
           
 java.lang.Object value4
           
 java.lang.Object[] values
           
 ValueStack vstack
          Default place for function results.
 int where
          Encoding of where the arguments are.
 
Constructor Summary
CallContext()
           
 
Method Summary
 void cleanupFromContext(int oldIndex)
          Cleanup-only part of getFromContext.
 java.lang.Object[] getArgs()
           
 Environment getEnvironment()
           
 Environment getEnvironmentRaw()
           
 java.lang.Object getFromContext(int oldIndex)
          Routine to extract result and restore state after startFromContext.
static CallContext getInstance()
          Get or create a CallContext for the current thread.
 java.lang.Object getNextArg()
          Get the next incoming argument.
 java.lang.Object getNextArg(java.lang.Object defaultValue)
          Get the next incoming argument.
 int getNextIntArg()
           
 int getNextIntArg(int defaultValue)
           
static CallContext getOnlyInstance()
          Get but don't create a CallContext for the current thread.
 java.lang.Object[] getRestArgsArray(int next)
          Get remaining arguments as an array.
 LList getRestArgsList(int next)
          Get remaining arguments as a list.
 void lastArg()
          Note that we are done with the input arguments.
 void popFluid()
           
 void pushFluid(Location loc)
           
 void runUntilDone()
           
 java.lang.Object runUntilValue()
          Run until no more continuations, returning final result.
 void runUntilValue(Consumer out)
          Run until no more continuations, sending result to a COnsumer.
 void setEnvironmentRaw(Environment env)
           
static void setInstance(CallContext ctx)
           
 int startFromContext()
          Setup routine before calling a method that takes a CallContext.
 void writeValue(java.lang.Object value)
          Write values (of function result) to current consumer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proc

public Procedure proc

pc

public int pc
The program location in the current procedure. This a selector that only has meaning to the proc's Procedure.


vstack

public ValueStack vstack
Default place for function results. In the future, function arguments will also use vstack.


consumer

public Consumer consumer
Function results are written to this Consumer. This may point to vstack - or some other Consumer.


value1

public java.lang.Object value1
Used for passing parameters. (Will be replaced by vstack.)


value2

public java.lang.Object value2

value3

public java.lang.Object value3

value4

public java.lang.Object value4

values

public java.lang.Object[] values

ivalue1

public int ivalue1

ivalue2

public int ivalue2

count

public int count
Number of actual arguments.


next

public int next
Index of next argument. This is used by methods like getNextArg, used by callees.


where

public int where
Encoding of where the arguments are. Each argument uses 4 bits. Arguments beyond 8 are implicitly ARG_IN_VALUES_ARRAY.


ARG_IN_VALUES_ARRAY

public static final int ARG_IN_VALUES_ARRAY
See Also:
Constant Field Values

ARG_IN_VALUE1

public static final int ARG_IN_VALUE1
See Also:
Constant Field Values

ARG_IN_VALUE2

public static final int ARG_IN_VALUE2
See Also:
Constant Field Values

ARG_IN_VALUE3

public static final int ARG_IN_VALUE3
See Also:
Constant Field Values

ARG_IN_VALUE4

public static final int ARG_IN_VALUE4
See Also:
Constant Field Values

ARG_IN_IVALUE1

public static final int ARG_IN_IVALUE1
See Also:
Constant Field Values

ARG_IN_IVALUE2

public static final int ARG_IN_IVALUE2
See Also:
Constant Field Values

evalFrames

public java.lang.Object[][] evalFrames
Current stack of evaluation frames for interpreter.

Constructor Detail

CallContext

public CallContext()
Method Detail

getEnvironmentRaw

public final Environment getEnvironmentRaw()

setEnvironmentRaw

public final void setEnvironmentRaw(Environment env)

getEnvironment

public final Environment getEnvironment()

setInstance

public static void setInstance(CallContext ctx)

getOnlyInstance

public static CallContext getOnlyInstance()
Get but don't create a CallContext for the current thread.


getInstance

public static CallContext getInstance()
Get or create a CallContext for the current thread.


getNextArg

public java.lang.Object getNextArg()
Get the next incoming argument. Throw WrongArguments if there are no more arguments. FIXME: This and following methods don't really fit until the current match/apply-based API, at least as currently implemented. We probably need to pass in (or make this a method of) the Procedure.


getNextIntArg

public int getNextIntArg()

getNextArg

public java.lang.Object getNextArg(java.lang.Object defaultValue)
Get the next incoming argument. Return defaultValue if there are no more arguments.


getNextIntArg

public int getNextIntArg(int defaultValue)

getRestArgsArray

public final java.lang.Object[] getRestArgsArray(int next)
Get remaining arguments as an array.


getRestArgsList

public final LList getRestArgsList(int next)
Get remaining arguments as a list. Used for Scheme and Lisp rest args.


lastArg

public void lastArg()
Note that we are done with the input arguments. Throw WrongArguments if there are unprocessed arguments.


getArgs

public java.lang.Object[] getArgs()

runUntilDone

public void runUntilDone()
                  throws java.lang.Throwable
Throws:
java.lang.Throwable

startFromContext

public final int startFromContext()
Setup routine before calling a method that takes a CallContext. The compiler emits a call to this before a call to a method that takes a CallContext, when it wants the function result as an Object. It pushes the CallContest state so it can uses the vstack for a temporary, After the method, getFromContext extract the method's result from the vstack and restores the state.


getFromContext

public final java.lang.Object getFromContext(int oldIndex)
                                      throws java.lang.Throwable
Routine to extract result and restore state after startFromContext.

Throws:
java.lang.Throwable

cleanupFromContext

public final void cleanupFromContext(int oldIndex)
                              throws java.lang.Throwable
Cleanup-only part of getFromContext. This can be in an exception handler as an alternative to getFromContext, which is called in the non-exception case. (Alternatively, the compiler could call cleanupFromContext from a finally clause but that is less efficient, partly because the JVM stack must be empty before a finally subroutine.)

Throws:
java.lang.Throwable

runUntilValue

public final java.lang.Object runUntilValue()
                                     throws java.lang.Throwable
Run until no more continuations, returning final result.

Throws:
java.lang.Throwable

runUntilValue

public final void runUntilValue(Consumer out)
                         throws java.lang.Throwable
Run until no more continuations, sending result to a COnsumer.

Throws:
java.lang.Throwable

writeValue

public void writeValue(java.lang.Object value)
Write values (of function result) to current consumer.


pushFluid

public final void pushFluid(Location loc)

popFluid

public final void popFluid()