-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closureiters: use case-statement-based dispatcher
Summary ======= Use a case statement for the dispatcher generated by the `closureiters` transformation, removing the need for both dedicated code generator support and the `nkState` node kind. This is a significant step towards closure iterator support the JavaScript and VM backend. While neither officially supported nor documented, it was previously possible to emit `nkGotoState` and `nkState` nodes from a macro, which could be used for unsafe unstructured control-flow. With the removal of the `nkState` node kind and `nkGotoState` being disallowed in AST reaching semantic analysis, the aforementioned is no longer possible. Details ======= The AST generated by the `closureiters` transformation always looked as follows: ```nim while true: block :stateLoop: # the block's body is wrapped in a try-except, if # necessary goto env.:state # goto the label corresponding to the run-time value # of `:state` # declarations body ``` where `body` defines the code blocks associated with each state value, like so: ```nim state 0: ... env.:state = 1 break :stateLoop state 1: ... state 2: ... ... # more labels (if used) follow ``` The control-flow described by the `goto` (`nkGotoState`) followed by the labels (`nkState`) is equally representable by the use of a case statement, which is what is now done after this commit. To summarize the change: - don't support `nkGotoState` nodes in AST reaching sem - adjust `closureiters` to generate a case statement for the dispatcher and to not depend on `nkState` - remove C code-generator support for `nkGotoState` and `nkState` - remove the `nkState` node kind Nodes with the `nkGotoState` kind now only exists *during* the transformation, but never before or after.
- Loading branch information
Showing
12 changed files
with
52 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters