Mid rewrite
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
//! This module lowers closures by making implicit environment captures explicit
|
||||
//!
|
||||
//! Replace:
|
||||
//! ```js
|
||||
//! let x = 0;
|
||||
//! let y = true;
|
||||
//!
|
||||
//! function fn() {
|
||||
//! f(x)
|
||||
//! f(y)
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! With:
|
||||
//! ```js
|
||||
//! let x = 0;
|
||||
//! let y = true;
|
||||
//!
|
||||
//! function fn() {
|
||||
//! f(fn.<var>.x);
|
||||
//! f(fn.<var>.y);
|
||||
//! }
|
||||
//!
|
||||
//! fn.<var>.x = x; // by-ref
|
||||
//! fn.<var>.y = y; // by-ref
|
||||
//! ```
|
||||
//!
|
||||
//! i.e. captured fields are turned into fields on the function
|
||||
//!
|
||||
//! A special `define_field_ref` instr is introduced by `c_parse.py` to define a field on an
|
||||
//! object specifically by-reference. This signals to `escape.rs` to promote those values to
|
||||
//! the heap regardless if its a primitive or an object. This is required because normally
|
||||
//! primitives are only passed by-value, but closure captures must always be by-reference
|
||||
//!
|
||||
//! In the emitted C, every underlying "plain" function is called as:
|
||||
//! `fn(this, fields, arg_0, arg_1, ... arg_n)`
|
||||
Reference in New Issue
Block a user