Package gnu.mapping
Class CallContext
- java.lang.Object
-
- gnu.mapping.ArgListImpl
-
- gnu.mapping.CallContext
-
- All Implemented Interfaces:
ArgList,ArgListBuilder
public class CallContext extends ArgListImpl implements ArgList, ArgListBuilder
A procedure activation stack (when compiled with explicit stacks).
-
-
Field Summary
Fields Modifier and Type Field Description MethodHandleapplyMethodConsumerconsumerFunction results are written to this Consumer.Object[][]evalFramesCurrent stack of evaluation frames for interpreter.static intMATCH_CHECKRequest to on failure return error code.static intMATCH_CHECK_ONLYRequest to on failure return error code; on failure return 0.static intMATCH_THROW_ON_EXCEPTIONRequest to throw an exception on a match failure.intnextIndex of next argument.Procedureproc-
Fields inherited from class gnu.mapping.ArgListImpl
count
-
-
Constructor Summary
Constructors Constructor Description CallContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArg(Object arg)voidaddArg(Object arg0, Object arg1, Object arg2, Object arg3)intcheckDone()voidcheckKeywordsDone()voidcleanupFromContext(int saved)Cleanup-only part of getFromContext.ObjectgetArgAsObject(int i)Index into arguments, not counting keywords.intgetArgCount()Object[]getArgs()ObjectgetFromContext(int saved)Routine to extract result and restore state after startFromContext.static CallContextgetInstance()Get or create a CallContext for the current thread.intgetMode()ObjectgetNextArg()Get the next incoming argument.ObjectgetNextArg(Object defaultValue)Get the next incoming argument.static CallContextgetOnlyInstance()Get but don't create a CallContext for the current thread.Object[]getRestArgsArray()Object[]getRestArgsArray(int next)Get remaining arguments as an array.LListgetRestArgsList()LListgetRestArgsList(int next)Get remaining arguments as a list.ArgListVectorgetRestArgsVector()ArgListVectorgetRestArgsVector(int next)Get remaining arguments are an ArgListVector.Object[]getRestPlainArray()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.ObjectnextKeyword(String keyword, Object dfault)intnextKeywordAllowOthers(String keyword)ObjectnextKeywordAllowOthers(String keyword, Object dfault)intnextKeywordIndex(String keyword, boolean allowOthers)LListpeekRestArgsList()voidpopArgState()voidpushArgState()voidreset()voidrewind()voidrewind(int mode)voidrunUntilDone()ObjectrunUntilValue()Run until no more continuations, returning final result.voidrunUntilValue(Consumer out)Run until no more continuations, sending result to a COnsumer.static voidsetInstance(CallContext ctx)voidsetNextProcedure(Procedure proc)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)voidsetupApply(Procedure proc, Object arg0, Object arg1, Object arg2, Object arg3)voidsetupApplyAll(Procedure proc, Object[] args)voidsetupApplyAll(Procedure proc, Object[] args, int fromIndex, int toIndex)voidshiftArgs(Procedure proc, int toDrop)intstartFromContext()Setup routine before calling a method that takes a CallContext.booleanthrowOnException()voidwriteValue(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 Detail
-
applyMethod
public MethodHandle applyMethod
-
proc
public Procedure proc
-
consumer
public Consumer consumer
Function results are written to this Consumer. This may point to vstack - or some other Consumer.
-
next
public int next
Index of next argument. This is used by methods like getNextArg, used by callees.
-
MATCH_THROW_ON_EXCEPTION
public static final int MATCH_THROW_ON_EXCEPTION
Request to throw an exception on a match failure. This is instead of setting matchState to an error value.- See Also:
- Constant Field Values
-
MATCH_CHECK
public static final int MATCH_CHECK
Request 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:
- Constant Field Values
-
MATCH_CHECK_ONLY
public static final int MATCH_CHECK_ONLY
Request to on failure return error code; on failure return 0. Regardless, don't invoke body method.- See Also:
- Constant Field Values
-
evalFrames
public Object[][] evalFrames
Current stack of evaluation frames for interpreter.
-
-
Method Detail
-
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.
-
setNextProcedure
public final void setNextProcedure(Procedure proc, MethodHandle apply)
-
setNextProcedure
public final void setNextProcedure(Procedure proc)
-
getArgAsObject
public Object getArgAsObject(int i)
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
public void shiftArgs(Procedure proc, int toDrop)
-
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
public Object getNextArg()
Get the next incoming argument.
-
getNextArg
public Object getNextArg(Object defaultValue)
Get the next incoming argument. Return defaultValue if there are no more arguments.
-
getRestPlainArray
public final Object[] getRestPlainArray()
-
getRestArgsArray
public final Object[] getRestArgsArray()
-
getRestArgsArray
public final Object[] getRestArgsArray(int next)
Get remaining arguments as an array.
-
peekRestArgsList
public final LList peekRestArgsList()
-
getRestArgsVector
public final ArgListVector getRestArgsVector()
-
getRestArgsList
public final LList getRestArgsList()
-
getRestArgsList
public final LList getRestArgsList(int next)
Get remaining arguments as a list. Used for Scheme and Lisp rest args.
-
getRestPlainList
public final LList getRestPlainList(int next)
-
getRestArgsVector
public ArgListVector getRestArgsVector(int next)
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
public Object[] getArgs()
-
getSortedKeywords
public static short[] getSortedKeywords(String[] keywords, int nkeys)
-
nextKeyword
public int nextKeyword(String keyword)
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
public int nextKeywordAllowOthers(String keyword)
-
nextKeywordIndex
public int nextKeywordIndex(String keyword, boolean allowOthers)
-
setupApply
public void setupApply(Procedure proc)
-
setupApply
public void setupApply(Procedure proc, Object arg0, Object arg1, Object arg2, Object arg3)
-
addArg
public void addArg(Object arg)
-
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 Object getFromContext(int saved) throws Throwable
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
public final Object runUntilValue() throws Throwable
Run until no more continuations, returning final result. Assume that the current applyHandle is from proc.- Throws:
Throwable
-
runUntilValue
public final void runUntilValue(Consumer out) throws Throwable
Run until no more continuations, sending result to a COnsumer.- Throws:
Throwable
-
writeValue
public void writeValue(Object value)
Write values (of function result) to current consumer.
-
pushArgState
public final void pushArgState()
-
popArgState
public final void popArgState()
-
-