Class ContinuationResult
- All Implemented Interfaces:
TruffleObject
RootNode
, the
interpreter state, and a yielded result. A ContinuationResult
is returned when the
interpreter yields. It can later be resumed to continue execution. It can be resumed only once.
Below illustrates an example usage of ContinuationResult
.
// Assume yieldingRootNode implements the following pseudocode: // // fun f(x): // y = yield (x + 1) // return x + y // MyBytecodeRootNode yieldingRootNode = ...; // The result is a ContinuationResult ContinuationResult yielded = (ContinuationResult) yieldingRootNode.getCallTarget().call(42); assert yielded.getResult() == 43; // Resume the continuation using continueWith. Pass 58 as the value for yield. Integer returned = (Integer) yielded.continueWith(58); assert returned == 100;For performance reasons, a language may wish to define an inline cache over continuations. In such a case, they should not call
continueWith(Object)
, but instead cache and call the
root node
or call target
directly. This is necessary because continuation results are dynamic values, not partial
evaluation constants. Be careful to conform to the calling
convention
when calling the continuation root node directly.- Since:
- 24.2
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionContinuationResult
(ContinuationRootNode rootNode, MaterializedFrame frame, Object result) Creates a continuation. -
Method Summary
Modifier and TypeMethodDescriptioncontinueWith
(Object value) Resumes the continuation.Returns the location at which the continuation was created.Returns the call target for thecontinuation root node
.Returns the root node that resumes execution.getFrame()
Returns the state of the interpreter at the point that it was suspended.Returns the value yielded by the yield operation.toString()
Returns a string representation of aContinuationResult
.
-
Constructor Details
-
ContinuationResult
Creates a continuation.The generated interpreter will use this constructor. Continuations should not be created directly by user code.
- Since:
- 24.2
-
-
Method Details
-
continueWith
Resumes the continuation.This method should generally not be used on compiled code paths. Each yield produces a unique
ContinuationResult
, so the receiver object cannot be easilycached
, which means partial evaluation will be unable to resolve the call target. Instead, it is recommended to cache thecontinuation call target
and call it directly.- Parameters:
value
- the value produced by the yield operation in the resumed execution.- Since:
- 24.2
-
getContinuationRootNode
Returns the root node that resumes execution.Note that the continuation root node has a specific calling convention. See
getContinuationCallTarget()
for more details, or invoke the root node directly usingcontinueWith(Object)
.- Since:
- 24.2
- See Also:
-
getContinuationCallTarget
Returns the call target for thecontinuation root node
. The call target can be invoked to resume the continuation. It is recommended to register this call target in an inline cache and call it directly.The call target takes two parameters: the materialized interpreter
frame
and anObject
value to resume execution with. The value becomes the value produced by the yield operation in the resumed execution.- Since:
- 24.2
-
getFrame
Returns the state of the interpreter at the point that it was suspended.- Since:
- 24.2
-
getResult
-
getBytecodeLocation
Returns the location at which the continuation was created.This location can have a different
BytecodeNode
from thesource root node
if the source bytecode wasupdated
(explicitly or implicitly).- Since:
- 24.2
-
toString
Returns a string representation of aContinuationResult
.
-