mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
LibJS: Implement async functions as generator functions in BC mode
This applies a simple transformation, and adds a simple wrapper that translates the generator interface to the async function interface.
This commit is contained in:
parent
c604e95993
commit
3b0bf05fa5
14 changed files with 192 additions and 43 deletions
|
@ -23,19 +23,19 @@ Generator::~Generator()
|
|||
{
|
||||
}
|
||||
|
||||
Executable Generator::generate(ASTNode const& node, bool is_in_generator_function)
|
||||
Executable Generator::generate(ASTNode const& node, FunctionKind enclosing_function_kind)
|
||||
{
|
||||
Generator generator;
|
||||
generator.switch_to_basic_block(generator.make_block());
|
||||
if (is_in_generator_function) {
|
||||
generator.enter_generator_context();
|
||||
generator.m_enclosing_function_kind = enclosing_function_kind;
|
||||
if (generator.is_in_generator_or_async_function()) {
|
||||
// Immediately yield with no value.
|
||||
auto& start_block = generator.make_block();
|
||||
generator.emit<Bytecode::Op::Yield>(Label { start_block });
|
||||
generator.switch_to_basic_block(start_block);
|
||||
}
|
||||
node.generate_bytecode(generator);
|
||||
if (is_in_generator_function) {
|
||||
if (generator.is_in_generator_or_async_function()) {
|
||||
// Terminate all unterminated blocks with yield return
|
||||
for (auto& block : generator.m_root_basic_blocks) {
|
||||
if (block.is_terminated())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue