Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable lambda-lifting for the JavaScript target
Summary ======= Previously, inner closure procedures were not lifted into free-standing procedures during `transf`, but rather kept as is and mapped to nested JavaScript functions by `jsgen`. Besides requiring the JavaScript target to be special-cased in `transf` and `lambdalifting`, this also caused observable semantic issues: the destructors for captured variables were called when leaving the scope in which they were defined, not when the closure got destroyed. In order to bring the closure semantics in line with the other targets and as a prerequisite for full ORC support, lambda-lifting is now also enabled when using the JS target -- the code generator is adjusted to support the lifted procedures. The code generator changes are also a preparation for full closure iterator support. As a side-effect, closures now also work as expected when using the JS target and executing non-compile-time-only procedures that have inner closure procedures at compile-time. Details ======= - remove the dispatching based on the selected backend from `transf` and `lambdalifting` - remove all code related to the previous closure support from `jsgen` - implement support for lifted procedures in `jsgen` The hidden environment parameter of routines using the `.closure` calling convention is mapped to the this parameter at the JavaScript level. When a NimSkull closure object is created, a new function instance is created via `bind` and the provided environment bound to the `this` parameter. In addition, the both the function and environment are also assigned to the respective prc and env properties on the function object -- this allows for later retrieval. Compared to using an object, this approach has the benefit that closures can still be passed to an imported procedure that expects a JavaScript function object, without requiring any changes to the user code.
- Loading branch information
Showing
6 changed files
with
73 additions
and
64 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