From 989edd42c7cff46b91a9d193bc5550d910df6a04 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 12 Jan 2023 05:06:14 +0000 Subject: [PATCH] `Break` Opcode and `ByteCompiler` changes (#2523) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi all! 😄 This Pull Request addresses #2424. There are also a few changes made to the `ByteCompiler`, the majority of which are involving `JumpControlInfo`. It changes the following: - Adds `Break` Opcode - Shifts `compile_stmt` into the `statement` module. - Moves `JumpControlInfo` to it's own module. --- boa_engine/src/bytecompiler/jump_control.rs | 389 ++++++++++++++++++ boa_engine/src/bytecompiler/mod.rs | 259 +----------- .../src/bytecompiler/statement/block.rs | 39 ++ .../src/bytecompiler/statement/break.rs | 70 ++++ .../src/bytecompiler/statement/continue.rs | 35 +- boa_engine/src/bytecompiler/statement/if.rs | 25 ++ .../src/bytecompiler/statement/labelled.rs | 69 ++++ boa_engine/src/bytecompiler/statement/loop.rs | 21 +- boa_engine/src/bytecompiler/statement/mod.rs | 257 +++--------- .../src/bytecompiler/statement/switch.rs | 54 +++ boa_engine/src/bytecompiler/statement/try.rs | 4 +- boa_engine/src/tests.rs | 103 +++++ boa_engine/src/vm/code_block.rs | 3 +- boa_engine/src/vm/flowgraph/mod.rs | 16 + boa_engine/src/vm/opcode/jump/break.rs | 44 ++ boa_engine/src/vm/opcode/jump/mod.rs | 3 + boa_engine/src/vm/opcode/mod.rs | 3 + 17 files changed, 897 insertions(+), 497 deletions(-) create mode 100644 boa_engine/src/bytecompiler/jump_control.rs create mode 100644 boa_engine/src/bytecompiler/statement/block.rs create mode 100644 boa_engine/src/bytecompiler/statement/break.rs create mode 100644 boa_engine/src/bytecompiler/statement/if.rs create mode 100644 boa_engine/src/bytecompiler/statement/labelled.rs create mode 100644 boa_engine/src/bytecompiler/statement/switch.rs create mode 100644 boa_engine/src/vm/opcode/jump/break.rs diff --git a/boa_engine/src/bytecompiler/jump_control.rs b/boa_engine/src/bytecompiler/jump_control.rs new file mode 100644 index 0000000000..7dc30b38bc --- /dev/null +++ b/boa_engine/src/bytecompiler/jump_control.rs @@ -0,0 +1,389 @@ +//! `JumpControlInfo` tracks relevant jump information used during compilation. +//! +//! Primarily, jump control tracks information related to the compilation of [iteration +//! statements][iteration spec], [switch statements][switch spec], [try statements][try spec], +//! and [labelled statements][labelled spec]. +//! +//! [iteration spec]: https://tc39.es/ecma262/#sec-iteration-statements +//! [switch spec]: https://tc39.es/ecma262/#sec-switch-statement +//! [try spec]: https://tc39.es/ecma262/#sec-try-statement +//! [labelled spec]: https://tc39.es/ecma262/#sec-labelled-statements + +use crate::{ + bytecompiler::{ByteCompiler, Label}, + vm::Opcode, +}; +use bitflags::bitflags; +use boa_interner::Sym; +use std::mem::size_of; + +/// Boa's `ByteCompiler` jump information tracking struct. +#[derive(Debug, Clone)] +pub(crate) struct JumpControlInfo { + label: Option, + start_address: u32, + decl_envs: u32, + flags: JumpControlInfoFlags, + breaks: Vec