Mid rewrite

This commit is contained in:
UditDey
2026-10-13 11:52:02 +00:00
parent 2f21347088
commit d0c2f291e9
24 changed files with 752 additions and 3527 deletions
+36
View File
@@ -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)`