java.lang.Object
org.kink_lang.kink.internal.callstack.CallStack

public class CallStack extends Object
A call stack.
  • Constructor Details

    • CallStack

      public CallStack(int initCapa, int maxModerateSize, int trbSize)
      Constructs a call stack.
      Parameters:
      initCapa - the initial capacity of the backing array.
      maxModerateSize - the maximum size which is considered moderate.
      trbSize - the max number of tail-call trace elems in a frame.
  • Method Details

    • isModerateSize

      public boolean isModerateSize()
      Returns true if the call stack has moderate size and can push a non-trace elem.
      Returns:
      true if the call stack has moderate size.
    • pushCse

      public void pushCse(Cse elem, int programCounter, int argCount, int dataStackUsage)
      Pushes a cse.

      Precondition: isModerateSize() must be true.

      Parameters:
      elem - an elem.
      programCounter - the program counter where the processing starts if it is resumed. The value is specific to implementation of ResumeCse.
      argCount - the number of args in the fram.e
      dataStackUsage - the size of datastack consumed by the frame.
      Throws:
      IllegalStateException - if the elem stack has no capacity for the elem.
    • poppedLnum

      public long poppedLnum()
      Returns the lnum corresponding to the ResumeCse which was popped just before.
      Returns:
      the lnum corresponding to the ResumeCse which was popped just before.
    • pushTailTrace

      public void pushTailTrace(Trace trace)
      Pushes a trace of a tail-call.
      Parameters:
      trace - a trace of a tail-call.
    • popResumer

      public ResumeCse popResumer()
      Removes elems till the topmost ResumeCse, and returns the elem.
      Returns:
      the topmost ResumeCse.
      Throws:
      IllegalStateException - if there is no ResumeCse.
    • popFakeCallTrace

      public void popFakeCallTrace()
      Removes the FakeCallTraceCse on the top.
      Throws:
      IllegalStateException - if the top is not FakeCallTraceCse.
    • canAbort

      public boolean canAbort(KontTagCse kontTag)
      Returns true when the elem stack contains at least one kontTag.
      Parameters:
      kontTag - the kont tag.
      Returns:
      true the call stack contains at least one kontTag.
    • abort

      public CallStackSlice abort(KontTagCse kontTag)
      Performs abort operation on shift function.

      This method returns the elems from the nearest kontTag to the current stack top. This method removes the elems after the ResetFrame.

      Precondition: canAbort(KontTagCse) must return true.

      Parameters:
      kontTag - the kont tag.
      Returns:
      the delimited continuation elems.
      Throws:
      IllegalArgumentException - if the call stack contains no kontTag.
    • canReplay

      public boolean canReplay(CallStackSlice callSlice)
      Returns true if the call stack can replay the slice.
      Parameters:
      callSlice - the delimited continuation slice.
      Returns:
      true if the call stack can replay the cont elems.
    • replay

      public void replay(CallStackSlice slice)
      Replays the delimited continuation.

      Precondition: canReplay(CallStackSlice) must return true. contFrames must be a result of abort(KontTagCse)

      Parameters:
      slice - the delimited continuation slice.
    • traces

      public List<Trace> traces()
      Returns the traces; bottom to top.
      Returns:
      the traces; bottom to top.