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(java.lang.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.- 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 in user code.
- Since:
- 24.2
-
-
Method Details
-
continueWith
Resumes the continuation.- 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(java.lang.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.Languages can invoke this call target directly via
continueWith(java.lang.Object). However, they may instead choose to access and call this call target directly (e.g., to register it in an inline cache).The call target takes two parameters: the materialized interpreter
frameand anObjectvalue 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
Returns the value yielded by the yield operation.- Since:
- 24.2
-
getBytecodeLocation
Returns the location at which the continuation was created.This location can have a different
BytecodeNodefrom thesource root nodeif the source bytecode wasupdated(explicitly or implicitly).- Since:
- 24.2
-
toString
Returns a string representation of aContinuationResult.
-