java.lang.Object
org.kink_lang.kink.internal.callstack.CallStack
A call stack.
-
Constructor Summary
ConstructorDescriptionCallStack
(int initCapa, int maxModerateSize, int trbSize) Constructs a call stack. -
Method Summary
Modifier and TypeMethodDescriptionabort
(KontTagCse kontTag) Performs abort operation on shift function.boolean
canAbort
(KontTagCse kontTag) Returns true when the elem stack contains at least one kontTag.boolean
canReplay
(CallStackSlice callSlice) Returns true if the call stack can replay the slice.boolean
Returns true if the call stack has moderate size and can push a non-trace elem.void
Removes theFakeCallTraceCse
on the top.long
Returns the lnum corresponding to the ResumeCse which was popped just before.Removes elems till the topmostResumeCse
, and returns the elem.void
Pushes a cse.void
pushTailTrace
(Trace trace) Pushes a trace of a tail-call.void
replay
(CallStackSlice slice) Replays the delimited continuation.traces()
Returns the traces; bottom to top.
-
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
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.edataStackUsage
- 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
Pushes a trace of a tail-call.- Parameters:
trace
- a trace of a tail-call.
-
popResumer
Removes elems till the topmostResumeCse
, and returns the elem.- Returns:
- the topmost
ResumeCse
. - Throws:
IllegalStateException
- if there is noResumeCse
.
-
popFakeCallTrace
public void popFakeCallTrace()Removes theFakeCallTraceCse
on the top.- Throws:
IllegalStateException
- if the top is notFakeCallTraceCse
.
-
canAbort
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
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 nokontTag
.
-
canReplay
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
Replays the delimited continuation.Precondition:
canReplay(CallStackSlice)
must return true.contFrames
must be a result ofabort(KontTagCse)
- Parameters:
slice
- the delimited continuation slice.
-
traces
Returns the traces; bottom to top.- Returns:
- the traces; bottom to top.
-