gnu.mapping

Class CallContext

Known Direct 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.
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
Object
value1
Used for passing parameters.
Object
value2
Object
value3
Object
value4
Object[]
values
ValueStack
vstack
Default place for function results.
int
where
Encoding of where the arguments are.

Method Summary

void
cleanupFromContext(int oldIndex)
Cleanup-only part of getFromContext.
Object[]
getArgs()
Environment
getEnvironment()
Environment
getEnvironmentRaw()
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.
Object
getNextArg()
Get the next incoming argument.
Object
getNextArg(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.
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()
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(Object value)
Write values (of function result) to current consumer.

Field Details

ARG_IN_IVALUE1

public static final int ARG_IN_IVALUE1
Field Value:
5

ARG_IN_IVALUE2

public static final int ARG_IN_IVALUE2
Field Value:
6

ARG_IN_VALUE1

public static final int ARG_IN_VALUE1
Field Value:
1

ARG_IN_VALUE2

public static final int ARG_IN_VALUE2
Field Value:
2

ARG_IN_VALUE3

public static final int ARG_IN_VALUE3
Field Value:
3

ARG_IN_VALUE4

public static final int ARG_IN_VALUE4
Field Value:
4

ARG_IN_VALUES_ARRAY

public static final int ARG_IN_VALUES_ARRAY
Field Value:
0

consumer

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

count

public int count
Number of actual arguments.

evalFrames

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

ivalue1

public int ivalue1

ivalue2

public int ivalue2

pc

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

proc

public Procedure proc

value1

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

value2

public Object value2

value3

public Object value3

value4

public Object value4

values

public Object[] values

vstack

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

where

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

Method Details

cleanupFromContext

public final void cleanupFromContext(int oldIndex)
            throws 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.)

getArgs

public Object[] getArgs()

getEnvironment

public final Environment getEnvironment()

getEnvironmentRaw

public final Environment getEnvironmentRaw()

getFromContext

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

getInstance

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

getNextArg

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

getNextArg

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

getNextIntArg

public int getNextIntArg()

getNextIntArg

public int getNextIntArg(int defaultValue)

getOnlyInstance

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

getRestArgsArray

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

popFluid

public final void popFluid()

pushFluid

public final void pushFluid(Location loc)

runUntilDone

public void runUntilDone()
            throws Throwable

runUntilValue

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

runUntilValue

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

setEnvironmentRaw

public final void setEnvironmentRaw(Environment env)

setInstance

public static void setInstance(CallContext ctx)

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.

writeValue

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