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 intRequest to on failure return error code.static final intRequest to on failure return error code; on failure return 0.static final intRequest to throw an exception on a match failure.intIndex of next argument.Fields inherited from class gnu.mapping.ArgListImpl
count -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidintvoidfinal voidcleanupFromContext(int saved) Cleanup-only part of getFromContext.getArgAsObject(int i) Index into arguments, not counting keywords.intObject[]getArgs()final ObjectgetFromContext(int saved) Routine to extract result and restore state after startFromContext.static CallContextGet or create a CallContext for the current thread.intgetMode()Get the next incoming argument.getNextArg(Object defaultValue) Get the next incoming argument.static CallContextGet but don't create a CallContext for the current thread.final Object[]final Object[]getRestArgsArray(int next) Get remaining arguments as an array.final LListfinal LListgetRestArgsList(int next) Get remaining arguments as a list.final ArgListVectorgetRestArgsVector(int next) Get remaining arguments are an ArgListVector.final Object[]final LListgetRestPlainList(int next) static short[]getSortedKeywords(String[] keywords, int nkeys) booleanhaveArg()voidlastArg()Note that we are done with the input arguments.voidmatchError(int code) intnextKeyword(String keyword) Return index of matching keyword argument.nextKeyword(String keyword, Object dfault) intnextKeywordAllowOthers(String keyword) nextKeywordAllowOthers(String keyword, Object dfault) intnextKeywordIndex(String keyword, boolean allowOthers) final LListfinal voidfinal voidvoidreset()voidrewind()voidrewind(int mode) voidfinal ObjectRun until no more continuations, returning final result.final voidrunUntilValue(Consumer out) Run until no more continuations, sending result to a COnsumer.static voidsetInstance(CallContext ctx) final voidsetNextProcedure(Procedure proc) final voidsetNextProcedure(Procedure proc, MethodHandle apply) voidsetupApply(Procedure proc) voidsetupApply(Procedure proc, Object arg0) voidsetupApply(Procedure proc, Object arg0, Object arg1) voidsetupApply(Procedure proc, Object arg0, Object arg1, Object arg2) voidvoidsetupApplyAll(Procedure proc, Object[] args) voidsetupApplyAll(Procedure proc, Object[] args, int fromIndex, int toIndex) voidfinal intSetup routine before calling a method that takes a CallContext.booleanvoidwriteValue(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, shiftArgsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:ArgListIndex 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:
getArgAsObjectin interfaceArgList- Overrides:
getArgAsObjectin 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:
dfaultif 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()
-