Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Sep 29, 2023
1 parent e0425eb commit 58e3a7d
Show file tree
Hide file tree
Showing 32 changed files with 189 additions and 189 deletions.
22 changes: 11 additions & 11 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,23 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
}

pub(crate) fn emit(&mut self, opcode: Opcode, operands: &[Operand]) {
let mut varying_kind = VaryingOperandKind::Short;
let mut varying_kind = VaryingOperandKind::U8;
for operand in operands {
if let Operand::Varying(operand) = *operand {
if u8::try_from(operand).is_ok() {
} else if u16::try_from(operand).is_ok() {
varying_kind = VaryingOperandKind::Half;
varying_kind = VaryingOperandKind::U16;
} else {
varying_kind = VaryingOperandKind::Wide;
varying_kind = VaryingOperandKind::U32;
break;
}
}
}

match varying_kind {
VaryingOperandKind::Short => {}
VaryingOperandKind::Half => self.emit_opcode(Opcode::Half),
VaryingOperandKind::Wide => self.emit_opcode(Opcode::Wide),
VaryingOperandKind::U8 => {}
VaryingOperandKind::U16 => self.emit_opcode(Opcode::ModifierU16),
VaryingOperandKind::U32 => self.emit_opcode(Opcode::ModifierU32),
}
self.emit_opcode(opcode);
for operand in operands {
Expand All @@ -497,11 +497,11 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
self.emit_opcode(opcode);
self.emit_u8(operand);
} else if let Ok(operand) = u16::try_from(operand) {
self.emit_opcode(Opcode::Half);
self.emit_opcode(Opcode::ModifierU16);
self.emit_opcode(opcode);
self.emit_u16(operand);
} else {
self.emit_opcode(Opcode::Wide);
self.emit_opcode(Opcode::ModifierU32);
self.emit_opcode(opcode);
self.emit_u32(operand);
}
Expand All @@ -519,9 +519,9 @@ impl<'ctx, 'host> ByteCompiler<'ctx, 'host> {
Operand::I64(v) => self.emit_i64(v),
Operand::U64(v) => self.emit_u64(v),
Operand::Varying(v) => match varying_kind {
VaryingOperandKind::Short => self.emit_u8(v as u8),
VaryingOperandKind::Half => self.emit_u16(v as u16),
VaryingOperandKind::Wide => self.emit_u32(v),
VaryingOperandKind::U8 => self.emit_u8(v as u8),
VaryingOperandKind::U16 => self.emit_u16(v as u16),
VaryingOperandKind::U32 => self.emit_u32(v),
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ impl CodeBlock {
| Instruction::SetReturnValue
| Instruction::Nop => String::new(),

Instruction::Half
| Instruction::Wide
Instruction::ModifierU16
| Instruction::ModifierU32
| Instruction::Reserved1
| Instruction::Reserved2
| Instruction::Reserved3
Expand Down Expand Up @@ -676,9 +676,9 @@ impl ToInternedString for CodeBlock {
};

let varying_operand_kind = match varying_operand_kind {
super::VaryingOperandKind::Short => "",
super::VaryingOperandKind::Half => ".Half",
super::VaryingOperandKind::Wide => ".Wide",
super::VaryingOperandKind::U8 => "",
super::VaryingOperandKind::U16 => ".U16",
super::VaryingOperandKind::U32 => ".U32",
};

f.push_str(&format!(
Expand Down
8 changes: 2 additions & 6 deletions boa_engine/src/vm/flowgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use super::{Instruction, InstructionIterator};

impl CodeBlock {
/// Output the [`CodeBlock`] VM instructions into a [`Graph`].
///
/// # Panics
///
/// TODO:
#[allow(clippy::match_same_arms)]
pub fn to_graph(&self, interner: &Interner, graph: &mut SubGraph) {
// Have to remove any invalid graph chars like `<` or `>`.
Expand Down Expand Up @@ -469,8 +465,8 @@ impl CodeBlock {
Instruction::Return => {
graph.add_node(previous_pc, NodeShape::Diamond, label.into(), Color::Red);
}
Instruction::Half
| Instruction::Wide
Instruction::ModifierU16
| Instruction::ModifierU32
| Instruction::Reserved1
| Instruction::Reserved2
| Instruction::Reserved3
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ mod runtime_limits;
#[cfg(feature = "flowgraph")]
pub mod flowgraph;

pub(crate) use opcode::{Instruction, InstructionIterator, Opcode, VaryingOperandKind};

Check warning on line 35 in boa_engine/src/vm/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `InstructionIterator`, `Instruction`

Check warning on line 35 in boa_engine/src/vm/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `InstructionIterator`, `Instruction`

Check warning on line 35 in boa_engine/src/vm/mod.rs

View workflow job for this annotation

GitHub Actions / Coverage

unused imports: `InstructionIterator`, `Instruction`
pub use runtime_limits::RuntimeLimits;
pub use {
call_frame::{CallFrame, GeneratorResumeKind},
code_block::CodeBlock,
opcode::{Instruction, InstructionIterator, Opcode, VaryingOperand, VaryingOperandKind},
};

pub(crate) use {
Expand Down Expand Up @@ -283,9 +283,9 @@ impl Context<'_> {
};

let varying_operand_kind = match varying_operand_kind {
VaryingOperandKind::Short => "",
VaryingOperandKind::Half => ".Half",
VaryingOperandKind::Wide => ".Wide",
VaryingOperandKind::U8 => "",
VaryingOperandKind::U16 => ".U16",
VaryingOperandKind::U32 => ".U32",
};

println!(
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/binary_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ impl Operation for InPrivate {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/opcode/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ impl Operation for CallEval {
Self::operation(context, argument_count as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let argument_count = context.vm.read::<u16>() as usize;
Self::operation(context, argument_count)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let argument_count = context.vm.read::<u32>();
Self::operation(context, argument_count as usize)
}
Expand Down Expand Up @@ -221,12 +221,12 @@ impl Operation for Call {
Self::operation(context, argument_count as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let argument_count = context.vm.read::<u16>() as usize;
Self::operation(context, argument_count)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let argument_count = context.vm.read::<u32>();
Self::operation(context, argument_count as usize)
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/concat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ impl Operation for ConcatToString {
Self::operation(context, value_count)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let value_count = context.vm.read::<u16>() as usize;
Self::operation(context, value_count)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let value_count = context.vm.read::<u32>() as usize;
Self::operation(context, value_count)
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/control_flow/throw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ impl Operation for ThrowNewTypeError {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/copy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ impl Operation for CopyDataProperties {
Self::operation(context, excluded_key_count, excluded_key_count_computed)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let excluded_key_count = context.vm.read::<u16>() as usize;
let excluded_key_count_computed = context.vm.read::<u16>() as usize;
Self::operation(context, excluded_key_count, excluded_key_count_computed)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let excluded_key_count = context.vm.read::<u32>() as usize;
let excluded_key_count_computed = context.vm.read::<u32>() as usize;
Self::operation(context, excluded_key_count, excluded_key_count_computed)
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/opcode/define/class/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ impl Operation for DefineClassStaticGetterByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down Expand Up @@ -129,12 +129,12 @@ impl Operation for DefineClassGetterByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/opcode/define/class/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ impl Operation for DefineClassStaticMethodByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down Expand Up @@ -121,12 +121,12 @@ impl Operation for DefineClassMethodByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/opcode/define/class/setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl Operation for DefineClassStaticSetterByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down Expand Up @@ -132,12 +132,12 @@ impl Operation for DefineClassSetterByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
12 changes: 6 additions & 6 deletions boa_engine/src/vm/opcode/define/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl Operation for DefVar {
Self::operation(context, index as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Self::operation(context, index as usize)
}
Expand Down Expand Up @@ -88,12 +88,12 @@ impl Operation for DefInitVar {
Self::operation(context, index as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Self::operation(context, index as usize)
}
Expand Down Expand Up @@ -130,12 +130,12 @@ impl Operation for PutLexicalValue {
Self::operation(context, index as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Self::operation(context, index as usize)
}
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/define/own_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl Operation for DefineOwnPropertyByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down
8 changes: 4 additions & 4 deletions boa_engine/src/vm/opcode/delete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ impl Operation for DeletePropertyByName {
Self::operation(context, index)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>() as usize;
Self::operation(context, index)
}
Expand Down Expand Up @@ -103,12 +103,12 @@ impl Operation for DeleteName {
Self::operation(context, index as usize)
}

fn half_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u16_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u16>() as usize;
Self::operation(context, index)
}

fn wide_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
fn u32_execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Self::operation(context, index as usize)
}
Expand Down
Loading

0 comments on commit 58e3a7d

Please sign in to comment.