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 Details

    • 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:
    • 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:
    • 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:
    • evalFrames

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

    • CallContext

      public CallContext()
  • Method Details

    • 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: 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 interface ArgList
      Overrides:
      getArgAsObject in class ArgListImpl
    • 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:
      dfault if no matching keyword argument, or the corresponding keyword value.
    • nextKeywordAllowOthers

      public int nextKeywordAllowOthers(String keyword)
    • nextKeywordIndex

      public int nextKeywordIndex(String keyword, boolean allowOthers)
    • nextKeyword

      public Object nextKeyword(String keyword, Object dfault)
    • nextKeywordAllowOthers

      public Object nextKeywordAllowOthers(String keyword, Object dfault)
    • setupApply

      public void setupApply(Procedure proc)
    • setupApply

      public void setupApply(Procedure proc, Object arg0)
    • setupApply

      public void setupApply(Procedure proc, Object arg0, Object arg1)
    • setupApply

      public void setupApply(Procedure proc, Object arg0, Object arg1, Object arg2)
    • setupApply

      public void setupApply(Procedure proc, Object arg0, Object arg1, Object arg2, Object arg3)
    • setupApplyAll

      public void setupApplyAll(Procedure proc, Object[] args)
    • setupApplyAll

      public void setupApplyAll(Procedure proc, Object[] args, int fromIndex, int toIndex)
    • addArg

      public void addArg(Object arg)
    • addArg

      public void addArg(Object arg0, Object arg1, Object arg2, Object arg3)
    • runUntilDone

      public void runUntilDone() throws Throwable
      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

      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()