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 a1af47c commit 29974b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
4 changes: 0 additions & 4 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
2 changes: 1 addition & 1 deletion 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
41 changes: 19 additions & 22 deletions boa_engine/src/vm/opcode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,15 @@ where

/// Represents a varying operand kind.
#[derive(Default, Debug, Clone, Copy)]
#[allow(missing_docs)]
pub enum VaryingOperandKind {
pub(crate) enum VaryingOperandKind {
#[default]
Short,
Half,
Wide,
}

#[derive(Debug, Clone, Copy)]
#[allow(missing_docs)]
pub struct VaryingOperand {
pub(crate) struct VaryingOperand {
kind: VaryingOperandKind,
value: u32,
}
Expand All @@ -147,35 +145,34 @@ impl PartialEq for VaryingOperand {
}
}

#[allow(missing_docs)]
impl VaryingOperand {
#[must_use]
pub fn short(value: u8) -> Self {
pub(crate) fn short(value: u8) -> Self {
Self {
kind: VaryingOperandKind::Short,
value: u32::from(value),
}
}
#[must_use]
pub fn half(value: u16) -> Self {
pub(crate) fn half(value: u16) -> Self {
Self {
kind: VaryingOperandKind::Half,
value: u32::from(value),
}
}
#[must_use]
pub const fn wide(value: u32) -> Self {
pub(crate) const fn wide(value: u32) -> Self {
Self {
kind: VaryingOperandKind::Wide,
value,
}
}
#[must_use]
pub const fn value(self) -> u32 {
pub(crate) const fn value(self) -> u32 {
self.value
}
#[must_use]
pub const fn kind(self) -> VaryingOperandKind {
pub(crate) const fn kind(self) -> VaryingOperandKind {
self.kind
}
}
Expand Down Expand Up @@ -378,7 +375,7 @@ macro_rules! generate_opcodes {
/// The opcodes of the vm.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Opcode {
pub(crate) enum Opcode {
$(
$(#[$inner $($args)*])*
$Variant
Expand Down Expand Up @@ -409,7 +406,7 @@ macro_rules! generate_opcodes {

/// Name of this opcode.
#[must_use]
pub const fn as_str(self) -> &'static str {
pub(crate) const fn as_str(self) -> &'static str {
Self::NAMES[self as usize]
}

Expand All @@ -421,7 +418,7 @@ macro_rules! generate_opcodes {

/// Name of the profiler event for this opcode.
#[must_use]
pub const fn as_instruction_str(self) -> &'static str {
pub(crate) const fn as_instruction_str(self) -> &'static str {
Self::INSTRUCTIONS[self as usize]
}

Expand All @@ -443,13 +440,12 @@ macro_rules! generate_opcodes {
// be a part of `Instruction`.
#[derive(Debug, Clone, PartialEq)]
#[repr(u8)]
pub enum Instruction {
pub(crate) enum Instruction {
$(
$(#[$inner $($args)*])*
$Variant $({
$(
$(#[$fieldinner $($fieldargs)*])*
#[allow(missing_docs)]
$FieldName : $FieldType
),*
})?
Expand All @@ -459,7 +455,8 @@ macro_rules! generate_opcodes {
impl Instruction {
/// Convert [`Instruction`] to compact bytecode.
#[inline]
pub fn to_bytecode(&self, bytes: &mut Vec<u8>) {
#[allow(dead_code)]
pub(crate) fn to_bytecode(&self, bytes: &mut Vec<u8>) {
match self {
$(
Self::$Variant $({
Expand All @@ -481,7 +478,7 @@ macro_rules! generate_opcodes {
/// If the provided bytecode is not valid.
#[inline]
#[must_use]
pub fn from_bytecode(bytes: &[u8], pc: &mut usize, varying_kind: VaryingOperandKind) -> Self {
pub(crate) fn from_bytecode(bytes: &[u8], pc: &mut usize, varying_kind: VaryingOperandKind) -> Self {
let opcode = bytes[*pc].into();
*pc += 1;
match opcode {
Expand All @@ -508,7 +505,7 @@ macro_rules! generate_opcodes {
/// Get the [`Opcode`] of the [`Instruction`].
#[inline]
#[must_use]
pub const fn opcode(&self) -> Opcode {
pub(crate) const fn opcode(&self) -> Opcode {

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

View workflow job for this annotation

GitHub Actions / Coverage

method `opcode` is never used

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

View workflow job for this annotation

GitHub Actions / Coverage

method `opcode` is never used
match self {
$(
Self::$Variant $({ $( $FieldName: _ ),* })? => Opcode::$Variant
Expand Down Expand Up @@ -2184,7 +2181,7 @@ pub(crate) enum BindingOpcode {

/// Iterator over the instructions in the compact bytecode.
#[derive(Debug, Clone)]
pub struct InstructionIterator<'bytecode> {
pub(crate) struct InstructionIterator<'bytecode> {
bytes: &'bytecode [u8],
pc: usize,
}
Expand All @@ -2193,20 +2190,20 @@ impl<'bytecode> InstructionIterator<'bytecode> {
/// Create a new [`InstructionIterator`] from bytecode array.
#[inline]
#[must_use]
pub const fn new(bytes: &'bytecode [u8]) -> Self {
pub(crate) const fn new(bytes: &'bytecode [u8]) -> Self {

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

View workflow job for this annotation

GitHub Actions / Coverage

associated items `new`, `with_pc`, and `pc` are never used

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

View workflow job for this annotation

GitHub Actions / Coverage

associated items `new`, `with_pc`, and `pc` are never used
Self { bytes, pc: 0 }
}

/// Create a new [`InstructionIterator`] from bytecode array at pc.
#[inline]
#[must_use]
pub const fn with_pc(bytes: &'bytecode [u8], pc: usize) -> Self {
pub(crate) const fn with_pc(bytes: &'bytecode [u8], pc: usize) -> Self {
Self { bytes, pc }
}

/// Return the current program counter.
#[must_use]
pub const fn pc(&self) -> usize {
pub(crate) const fn pc(&self) -> usize {
self.pc
}
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Operation for Half {
/// `Wide` implements the Opcode Operation for `Opcode::Wide`
///
/// Operation:
/// - [`Opcode`] prefix operand modifier, makes all varying operands of an instruction [`u16`] sized.
/// - [`Opcode`] prefix operand modifier, makes all varying operands of an instruction [`u32`] sized.
#[derive(Debug, Clone, Copy)]
pub(crate) struct Wide;

Expand Down

0 comments on commit 29974b7

Please sign in to comment.