Rewrite with working async
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
//! - call{0, 1, 2, 3}
|
||||
//! - tail_call, tail_call_method
|
||||
//! - get_field2
|
||||
//! - get_array_el2
|
||||
//! - get_loc0_loc1
|
||||
//! - inc_loc, dec_loc, add_loc
|
||||
//! - set_proto
|
||||
@@ -20,15 +21,24 @@
|
||||
//! - put_var_ref{0, 1, 2, 3}, put_var_ref_check, put_var_ref_check_init
|
||||
//! - set_var_ref{0, 1, 2, 3}, set_var_ref
|
||||
//! - set_loc_uninitialized
|
||||
//! - close_loc
|
||||
//! - fclosure8
|
||||
//! - define_class
|
||||
//!
|
||||
//!
|
||||
//! And the following instructions take on a different meaning:
|
||||
//! The following instructions take on a different meaning:
|
||||
//! - call_constructor (see new.rs)
|
||||
//! - close_loc (see closure.rs)
|
||||
//!
|
||||
//! And the following instructions are added:
|
||||
//! - define_field_ref (see closure.rs)
|
||||
//! - close_field (see closure.rs)
|
||||
//!
|
||||
//! Async fns and generators become a constructor and a step closure first (see async.rs),
|
||||
//! so no instr of theirs is left: initial_yield, yield, await, return_async in them, and
|
||||
//! close_var_ref, which deasync makes and closure.rs lowers
|
||||
|
||||
mod args;
|
||||
mod r#async;
|
||||
mod class;
|
||||
mod closure;
|
||||
mod expand;
|
||||
@@ -40,7 +50,9 @@ use crate::{
|
||||
};
|
||||
|
||||
use args::try_replace_arg_access;
|
||||
use r#async::deasync;
|
||||
use class::declass;
|
||||
use closure::try_replace_closure;
|
||||
use expand::{replace_get_var, try_replace_expansion};
|
||||
use new::try_replace_new;
|
||||
|
||||
@@ -70,17 +82,28 @@ pub const THIS_ARG: u16 = 1;
|
||||
pub const FIRST_ARG: u16 = 2;
|
||||
|
||||
pub fn transform(
|
||||
flat_fns: Vec<FlatFn>,
|
||||
captures: &[Vec<ClosureVar>],
|
||||
mut flat_fns: Vec<FlatFn>,
|
||||
mut captures: Vec<Vec<ClosureVar>>,
|
||||
atoms: &[Atom],
|
||||
) -> Vec<FlatFn> {
|
||||
// Async fns and generators become state machines first: this adds fns, and changes the
|
||||
// captures that the other transforms read
|
||||
deasync(&mut flat_fns, &mut captures, atoms);
|
||||
|
||||
flat_fns
|
||||
.into_iter()
|
||||
.map(|f| transform_one(f, captures, atoms))
|
||||
.enumerate()
|
||||
.map(|(idx, f)| transform_one(f, &captures[idx], &captures, atoms))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn transform_one(mut f: FlatFn, captures: &[Vec<ClosureVar>], atoms: &[Atom]) -> FlatFn {
|
||||
/// `own` is the captures of `f`
|
||||
fn transform_one(
|
||||
mut f: FlatFn,
|
||||
own: &[ClosureVar],
|
||||
captures: &[Vec<ClosureVar>],
|
||||
atoms: &[Atom],
|
||||
) -> FlatFn {
|
||||
// Transform class declarations
|
||||
let code = declass(&f.code);
|
||||
|
||||
@@ -113,16 +136,19 @@ fn transform_one(mut f: FlatFn, captures: &[Vec<ClosureVar>], atoms: &[Atom]) ->
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: replace closures/bindings
|
||||
if try_replace_closure(instr, own, captures, &f.cpool, &mut out) {
|
||||
continue;
|
||||
}
|
||||
|
||||
out.push(instr.clone());
|
||||
}
|
||||
|
||||
FlatFn {
|
||||
name: f.name,
|
||||
kind: f.kind,
|
||||
arg_count: f.arg_count + FIRST_ARG as usize,
|
||||
local_count: f.local_count,
|
||||
local_count: next_local,
|
||||
cpool: f.cpool,
|
||||
code,
|
||||
code: out,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user