Package gnu.mapping
Class CallContext
java.lang.Object
gnu.mapping.ArgListImpl
gnu.mapping.CallContext
- All Implemented Interfaces:
ArgList
,ArgListBuilder
A procedure activation stack (when compiled with explicit stacks).
-
Field Summary
FieldsModifier and TypeFieldDescriptionFunction results are written to this Consumer.Object[][]
Current stack of evaluation frames for interpreter.static final int
Request to on failure return error code.static final int
Request to on failure return error code; on failure return 0.static final int
Request to throw an exception on a match failure.int
Index of next argument.Fields inherited from class gnu.mapping.ArgListImpl
count
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
int
void
final void
cleanupFromContext
(int saved) Cleanup-only part of getFromContext.getArgAsObject
(int i) Index into arguments, not counting keywords.int
Object[]
getArgs()
final Object
getFromContext
(int saved) Routine to extract result and restore state after startFromContext.static CallContext
Get or create a CallContext for the current thread.int
getMode()
Get the next incoming argument.getNextArg
(Object defaultValue) Get the next incoming argument.static CallContext
Get but don't create a CallContext for the current thread.final Object[]
final Object[]
getRestArgsArray
(int next) Get remaining arguments as an array.final LList
final LList
getRestArgsList
(int next) Get remaining arguments as a list.final ArgListVector
getRestArgsVector
(int next) Get remaining arguments are an ArgListVector.final Object[]
final LList
getRestPlainList
(int next) static short[]
getSortedKeywords
(String[] keywords, int nkeys) boolean
haveArg()
void
lastArg()
Note that we are done with the input arguments.void
matchError
(int code) int
nextKeyword
(String keyword) Return index of matching keyword argument.nextKeyword
(String keyword, Object dfault) int
nextKeywordAllowOthers
(String keyword) nextKeywordAllowOthers
(String keyword, Object dfault) int
nextKeywordIndex
(String keyword, boolean allowOthers) final LList
final void
final void
void
reset()
void
rewind()
void
rewind
(int mode) void
final Object
Run until no more continuations, returning final result.final void
runUntilValue
(Consumer out) Run until no more continuations, sending result to a COnsumer.static void
setInstance
(CallContext ctx) final void
setNextProcedure
(Procedure proc) final void
setNextProcedure
(Procedure proc, MethodHandle apply) void
setupApply
(Procedure proc) void
setupApply
(Procedure proc, Object arg0) void
setupApply
(Procedure proc, Object arg0, Object arg1) void
setupApply
(Procedure proc, Object arg0, Object arg1, Object arg2) void
void
setupApplyAll
(Procedure proc, Object[] args) void
setupApplyAll
(Procedure proc, Object[] args, int fromIndex, int toIndex) void
final int
Setup routine before calling a method that takes a CallContext.boolean
void
writeValue
(Object value) Write values (of function result) to current consumer.Methods inherited from class gnu.mapping.ArgListImpl
add, add, addAll, addAll, addArgList, addKey, addSequence, asArgList, asFreshArgList, clear, findKeyword, findKeyword, firstKeyword, getKeyword, numArguments, numKeywords, popLast, printArgs, setArgs, setArgs, setArgs, setArgs, setArgs, setArgsAll, setArgsAll, setKeys, shiftArgs
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gnu.mapping.ArgList
findKeyword, firstKeyword, getKeyword, numArguments, numKeywords
-
Field Details
-
applyMethod
-
proc
-
consumer
Function results are written to this Consumer. This may point to vstack - or some other Consumer. -
next
public int nextIndex of next argument. This is used by methods like getNextArg, used by callees. -
MATCH_THROW_ON_EXCEPTION
public static final int MATCH_THROW_ON_EXCEPTIONRequest to throw an exception on a match failure. This is instead of setting matchState to an error value.- See Also:
-
MATCH_CHECK
public static final int MATCH_CHECKRequest to on failure return error code. Error is indicated by check routine returning this CallContext. Otherwise, execute actual function and return result (or null).- See Also:
-
MATCH_CHECK_ONLY
public static final int MATCH_CHECK_ONLYRequest to on failure return error code; on failure return 0. Regardless, don't invoke body method.- See Also:
-
evalFrames
Current stack of evaluation frames for interpreter.
-
-
Constructor Details
-
CallContext
public CallContext()
-
-
Method Details
-
setInstance
-
getOnlyInstance
Get but don't create a CallContext for the current thread. -
getInstance
Get or create a CallContext for the current thread. -
setNextProcedure
-
setNextProcedure
-
getArgAsObject
Description copied from interface:ArgList
Index into arguments, not counting keywords. I.e. for [a b k1: c k2: d e] the index 0 returns a, 2 returns c, 3 returns d, 4 returns e.- Specified by:
getArgAsObject
in interfaceArgList
- Overrides:
getArgAsObject
in classArgListImpl
-
rewind
public void rewind(int mode) -
rewind
public void rewind() -
reset
public void reset() -
shiftArgs
-
getMode
public int getMode() -
matchError
public void matchError(int code) -
throwOnException
public boolean throwOnException() -
haveArg
public boolean haveArg() -
checkKeywordsDone
public void checkKeywordsDone() -
checkDone
public int checkDone() -
getArgCount
public int getArgCount() -
getNextArg
Get the next incoming argument. -
getNextArg
Get the next incoming argument. Return defaultValue if there are no more arguments. -
getRestPlainArray
-
getRestArgsArray
-
getRestArgsArray
Get remaining arguments as an array. -
peekRestArgsList
-
getRestArgsVector
-
getRestArgsList
-
getRestArgsList
Get remaining arguments as a list. Used for Scheme and Lisp rest args. -
getRestPlainList
-
getRestArgsVector
Get remaining arguments are an ArgListVector.- Parameters:
next
- The number of arguments that should be skipped. Assume either no keywords have been processed, or they all have.
-
lastArg
public void lastArg()Note that we are done with the input arguments. Throw WrongArguments if there are unprocessed arguments. -
getArgs
-
getSortedKeywords
-
nextKeyword
Return index of matching keyword argument. Must be called with keywords in increasing lexicographic order.- Returns:
dfault
if no matching keyword argument, or the corresponding keyword value.
-
nextKeywordAllowOthers
-
nextKeywordIndex
-
nextKeyword
-
nextKeywordAllowOthers
-
setupApply
-
setupApply
-
setupApply
-
setupApply
-
setupApply
-
setupApplyAll
-
setupApplyAll
-
addArg
-
addArg
-
runUntilDone
- Throws:
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
Routine to extract result and restore state after startFromContext.- Throws:
Throwable
-
cleanupFromContext
public final void cleanupFromContext(int saved) 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.) -
runUntilValue
Run until no more continuations, returning final result. Assume that the current applyHandle is from proc.- Throws:
Throwable
-
runUntilValue
Run until no more continuations, sending result to a COnsumer.- Throws:
Throwable
-
writeValue
Write values (of function result) to current consumer. -
pushArgState
public final void pushArgState() -
popArgState
public final void popArgState()
-