Skip to content

Commit

Permalink
Transfer control fixup: Make 'code evaluation state' less vague
Browse files Browse the repository at this point in the history
Formerly, we would say:
    Set the code evaluation state of _genContext_
    such that the next time there is a transfer of control
    to that execution context,
    _closure_ will be called with no arguments.

I.e., we don't say what to set it *to*,
just what the eventual effect of the setting should be.
This isn't how the spec usually talks.

Instead, simply set the code evaluation state to _closure_,
and define "transfer of control" to handle that appropriately.
  • Loading branch information
jmdyck committed Jan 14, 2023
1 parent a60dcd7 commit 94b2244
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -11683,7 +11683,7 @@ <h1>Execution Contexts</h1>
<p>To express the semantics of generators, this document uses steps of the form “<dfn id="transfer-control" variants="transfers control,transfer of control">Transfer control</dfn> from _aContext_ to _bContext_, passing _completion_”, where _aContext_ and _bContext_ are execution contexts and _completion_ is a Completion Record. This means:</p>
<ul>
<li>Execution of the current algorithm (the one with the “Transfer control” step) is suspended, and a representation of that suspended execution is saved in the code evaluation state of _aContext_.</li>
<li>The code evaluation state of _bContext_ is typically a representation of an execution that was suspended in another “Transfer control” step; that execution is resumed, and _completion_ is provided as “the Completion Record passed when control was transferred back to _bContext_”. Alternatively, _bContext_'s code evaluation state is set up to call an Abstract Closure; in that case, the Abstract Closure starts to execute and _completion_ is ignored.</li>
<li>The code evaluation state of _bContext_ is typically a representation of an execution that was suspended in another “Transfer control” step; that execution is resumed, and _completion_ is provided as “the Completion Record passed when control was transferred back to _bContext_”. Alternatively, _bContext_'s code evaluation state is an Abstract Closure; in that case, the Abstract Closure is called with no arguments, and _completion_ is ignored.</li>
</ul>
<p>The suspended execution associated with _aContext_ will stay suspended until some step transfers control back to _aContext_, which might never happen.</p>
<emu-note>This is analogous to the concept of coroutines in programming languages.</emu-note>
Expand Down Expand Up @@ -45255,7 +45255,8 @@ <h1>
1. Let _callerContext_ be the running execution context.
1. Transfer control from _genContext_ to _callerContext_, passing _finalCompletion_.
1. NOTE: The above step never completes, because control is never transferred back to _genContext_.
1. Set the code evaluation state of _genContext_ such that the next time there is a transfer of control to that execution context, _closure_ will be called with no arguments.
1. Set _genContext_'s code evaluation state to _closure_.
1. NOTE: The next time there is a transfer of control to _genContext_, _closure_ will be called with no arguments.
1. Set _generator_.[[GeneratorContext]] to _genContext_.
1. Set _generator_.[[GeneratorState]] to ~suspendedStart~.
1. Return ~unused~.
Expand Down Expand Up @@ -45613,7 +45614,8 @@ <h1>
1. Let _callerContext_ be the running execution context.
1. Transfer control from _genContext_ to _callerContext_, passing NormalCompletion(*undefined*).
1. NOTE: The above step never completes, because control is never transferred back to _genContext_.
1. Set the code evaluation state of _genContext_ such that the next time there is a transfer of control to that execution context, _closure_ will be called with no arguments.
1. Set _genContext_'s code evaluation state to _closure_.
1. NOTE: The next time there is a transfer of control to _genContext_, _closure_ will be called with no arguments.
1. Set _generator_.[[AsyncGeneratorContext]] to _genContext_.
1. Set _generator_.[[AsyncGeneratorState]] to ~suspendedStart~.
1. Set _generator_.[[AsyncGeneratorQueue]] to a new empty List.
Expand Down Expand Up @@ -46009,7 +46011,8 @@ <h1>
1. Let _callerContext_ be the running execution context.
1. [id="step-asyncblockstart-return-undefined"] Transfer control from _asyncContext_ to _callerContext_, passing NormalCompletion(~unused~).
1. NOTE: The above step never completes, because control is never transferred back to _asyncContext_.
1. Set the code evaluation state of _asyncContext_ such that the next time there is a transfer of control to that execution context, _closure_ will be called with no arguments.
1. Set _asyncContext_'s code evaluation state to _closure_.
1. NOTE: The next time there is a transfer of control to _asyncContext_, _closure_ will be called with no arguments.
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
1. Transfer control from _runningContext_ to _asyncContext_, passing NormalCompletion(~unused~).
1. NOTE: The above step completes only if/when control is transferred back to _runningContext_.
Expand Down

0 comments on commit 94b2244

Please sign in to comment.