Skip to content

Commit

Permalink
Change type of COST constant to u8
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Jun 19, 2023
1 parent bdc742e commit f5912de
Show file tree
Hide file tree
Showing 68 changed files with 187 additions and 185 deletions.
5 changes: 3 additions & 2 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ impl Context<'_> {

let completion = loop {
let completion = self.run_next_instruction(|opcode, context| {
total_cost = total_cost.checked_add(opcode.cost()).unwrap_or(usize::MAX);
total_cost += opcode.cost();
total_cost = total_cost
.checked_add(usize::from(opcode.cost()))
.unwrap_or(usize::MAX);
opcode.execute(context)
});
if let ControlFlow::Break(completion) = completion {
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/await_stm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) struct Await;
impl Operation for Await {
const NAME: &'static str = "Await";
const INSTRUCTION: &'static str = "INST - Await";
const COST: usize = 5;
const COST: u8 = 5;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let value = context.vm.pop();
Expand Down
6 changes: 3 additions & 3 deletions boa_engine/src/vm/opcode/binary_ops/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct LogicalAnd;
impl Operation for LogicalAnd {
const NAME: &'static str = "LogicalAnd";
const INSTRUCTION: &'static str = "INST - LogicalAnd";
const COST: usize = 1;
const COST: u8 = 1;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let exit = context.vm.read::<u32>();
Expand All @@ -36,7 +36,7 @@ pub(crate) struct LogicalOr;
impl Operation for LogicalOr {
const NAME: &'static str = "LogicalOr";
const INSTRUCTION: &'static str = "INST - LogicalOr";
const COST: usize = 1;
const COST: u8 = 1;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let exit = context.vm.read::<u32>();
Expand All @@ -59,7 +59,7 @@ pub(crate) struct Coalesce;
impl Operation for Coalesce {
const NAME: &'static str = "Coalesce";
const INSTRUCTION: &'static str = "INST - Coalesce";
const COST: usize = 1;
const COST: u8 = 1;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let exit = context.vm.read::<u32>();
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/binary_ops/macro_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ macro_rules! implement_bin_ops {
impl Operation for $name {
const NAME: &'static str = stringify!($name);
const INSTRUCTION: &'static str = stringify!("INST - " + $name);
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let rhs = context.vm.pop();
Expand Down
12 changes: 6 additions & 6 deletions boa_engine/src/vm/opcode/binary_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) struct NotEq;
impl Operation for NotEq {
const NAME: &'static str = "NotEq";
const INSTRUCTION: &'static str = "INST - NotEq";
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let rhs = context.vm.pop();
Expand All @@ -41,7 +41,7 @@ pub(crate) struct StrictEq;
impl Operation for StrictEq {
const NAME: &'static str = "StrictEq";
const INSTRUCTION: &'static str = "INST - StrictEq";
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let rhs = context.vm.pop();
Expand All @@ -61,7 +61,7 @@ pub(crate) struct StrictNotEq;
impl Operation for StrictNotEq {
const NAME: &'static str = "StrictNotEq";
const INSTRUCTION: &'static str = "INST - StrictNotEq";
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let rhs = context.vm.pop();
Expand All @@ -81,7 +81,7 @@ pub(crate) struct In;
impl Operation for In {
const NAME: &'static str = "In";
const INSTRUCTION: &'static str = "INST - In";
const COST: usize = 3;
const COST: u8 = 3;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let rhs = context.vm.pop();
Expand Down Expand Up @@ -112,7 +112,7 @@ pub(crate) struct InPrivate;
impl Operation for InPrivate {
const NAME: &'static str = "InPrivate";
const INSTRUCTION: &'static str = "INST - InPrivate";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down Expand Up @@ -153,7 +153,7 @@ pub(crate) struct InstanceOf;
impl Operation for InstanceOf {
const NAME: &'static str = "InstanceOf";
const INSTRUCTION: &'static str = "INST - InstanceOf";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let target = context.vm.pop();
Expand Down
10 changes: 5 additions & 5 deletions boa_engine/src/vm/opcode/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Operation for CallEval {
const INSTRUCTION: &'static str = "INST - CallEval";
// TODO: Calls will require a big refactor in order to track
// the cost of the call.
const COST: usize = 15;
const COST: u8 = 15;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
if context.vm.runtime_limits.recursion_limit() <= context.vm.frames.len() {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Operation for CallEvalSpread {
const INSTRUCTION: &'static str = "INST - CallEvalSpread";
// TODO: Calls will require a big refactor in order to track
// the cost of the call.
const COST: usize = 15;
const COST: u8 = 15;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
if context.vm.runtime_limits.recursion_limit() <= context.vm.frames.len() {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Operation for Call {
const INSTRUCTION: &'static str = "INST - Call";
// TODO: Calls will require a big refactor in order to track
// the cost of the call.
const COST: usize = 15;
const COST: u8 = 15;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
if context.vm.runtime_limits.recursion_limit() <= context.vm.frames.len() {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Operation for CallSpread {
const INSTRUCTION: &'static str = "INST - CallSpread";
// TODO: Calls will require a big refactor in order to track
// the cost of the call.
const COST: usize = 15;
const COST: u8 = 15;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
if context.vm.runtime_limits.recursion_limit() <= context.vm.frames.len() {
Expand Down Expand Up @@ -277,7 +277,7 @@ impl Operation for ImportCall {
const INSTRUCTION: &'static str = "INST - ImportCall";
// TODO: Calls will require a big refactor in order to track
// the cost of the call.
const COST: usize = 15;
const COST: u8 = 15;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
// Import Calls
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/concat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct ConcatToString;
impl Operation for ConcatToString {
const NAME: &'static str = "ConcatToString";
const INSTRUCTION: &'static str = "INST - ConcatToString";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let value_count = context.vm.read::<u32>();
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/control_flow/break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Break;
impl Operation for Break {
const NAME: &'static str = "Break";
const INSTRUCTION: &'static str = "INST - Break";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let jump_address = context.vm.read::<u32>();
Expand Down Expand Up @@ -72,7 +72,7 @@ pub(crate) struct BreakLabel;
impl Operation for BreakLabel {
const NAME: &'static str = "BreakLabel";
const INSTRUCTION: &'static str = "INST - BreakLabel";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let jump_address = context.vm.read::<u32>();
Expand Down
6 changes: 3 additions & 3 deletions boa_engine/src/vm/opcode/control_flow/catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct CatchStart;
impl Operation for CatchStart {
const NAME: &'static str = "CatchStart";
const INSTRUCTION: &'static str = "INST - CatchStart";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let start = context.vm.frame().pc - 1;
Expand All @@ -40,7 +40,7 @@ pub(crate) struct CatchEnd;
impl Operation for CatchEnd {
const NAME: &'static str = "CatchEnd";
const INSTRUCTION: &'static str = "INST - CatchEnd";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let mut envs_to_pop = 0_usize;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) struct CatchEnd2;
impl Operation for CatchEnd2 {
const NAME: &'static str = "CatchEnd2";
const INSTRUCTION: &'static str = "INST - CatchEnd2";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
if let Some(catch_entry) = context
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/control_flow/continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct Continue;
impl Operation for Continue {
const NAME: &'static str = "Continue";
const INSTRUCTION: &'static str = "INST - Continue";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let jump_address = context.vm.read::<u32>();
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/control_flow/finally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct FinallyStart;
impl Operation for FinallyStart {
const NAME: &'static str = "FinallyStart";
const INSTRUCTION: &'static str = "INST - FinallyStart";
const COST: usize = 1;
const COST: u8 = 1;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let exit = context.vm.read::<u32>();
Expand All @@ -40,7 +40,7 @@ pub(crate) struct FinallyEnd;
impl Operation for FinallyEnd {
const NAME: &'static str = "FinallyEnd";
const INSTRUCTION: &'static str = "INST - FinallyEnd";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let finally_candidates = context
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/control_flow/labelled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct LabelledStart;
impl Operation for LabelledStart {
const NAME: &'static str = "LabelledStart";
const INSTRUCTION: &'static str = "INST - LabelledStart";
const COST: usize = 1;
const COST: u8 = 1;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let start = context.vm.frame().pc - 1;
Expand All @@ -37,7 +37,7 @@ pub(crate) struct LabelledEnd;
impl Operation for LabelledEnd {
const NAME: &'static str = "LabelledEnd";
const INSTRUCTION: &'static str = "INST - LabelledEnd";
const COST: usize = 3;
const COST: u8 = 3;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let mut envs_to_pop = 0_usize;
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/control_flow/return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct Return;
impl Operation for Return {
const NAME: &'static str = "Return";
const INSTRUCTION: &'static str = "INST - Return";
const COST: usize = 4;
const COST: u8 = 4;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let current_address = context.vm.frame().pc;
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 @@ -17,7 +17,7 @@ pub(crate) struct Throw;
impl Operation for Throw {
const NAME: &'static str = "Throw";
const INSTRUCTION: &'static str = "INST - Throw";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let error = if let Some(err) = context.vm.err.take() {
Expand Down Expand Up @@ -196,7 +196,7 @@ pub(crate) struct ThrowNewTypeError;
impl Operation for ThrowNewTypeError {
const NAME: &'static str = "ThrowNewTypeError";
const INSTRUCTION: &'static str = "INST - ThrowNewTypeError";
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/vm/opcode/control_flow/try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct TryStart;
impl Operation for TryStart {
const NAME: &'static str = "TryStart";
const INSTRUCTION: &'static str = "INST - TryStart";
const COST: usize = 2;
const COST: u8 = 2;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let catch = context.vm.read::<u32>();
Expand Down Expand Up @@ -48,7 +48,7 @@ pub(crate) struct TryEnd;
impl Operation for TryEnd {
const NAME: &'static str = "TryEnd";
const INSTRUCTION: &'static str = "INST - TryEnd";
const COST: usize = 3;
const COST: u8 = 3;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let mut envs_to_pop = 0_usize;
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/vm/opcode/copy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) struct CopyDataProperties;
impl Operation for CopyDataProperties {
const NAME: &'static str = "CopyDataProperties";
const INSTRUCTION: &'static str = "INST - CopyDataProperties";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let excluded_key_count = context.vm.read::<u32>();
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 @@ -16,7 +16,7 @@ pub(crate) struct DefineClassStaticGetterByName;
impl Operation for DefineClassStaticGetterByName {
const NAME: &'static str = "DefineClassStaticGetterByName";
const INSTRUCTION: &'static str = "INST - DefineClassStaticGetterByName";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) struct DefineClassGetterByName;
impl Operation for DefineClassGetterByName {
const NAME: &'static str = "DefineClassGetterByName";
const INSTRUCTION: &'static str = "INST - DefineClassGetterByName";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down Expand Up @@ -124,7 +124,7 @@ pub(crate) struct DefineClassStaticGetterByValue;
impl Operation for DefineClassStaticGetterByValue {
const NAME: &'static str = "DefineClassStaticGetterByValue";
const INSTRUCTION: &'static str = "INST - DefineClassStaticGetterByValue";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let function = context.vm.pop();
Expand Down Expand Up @@ -175,7 +175,7 @@ pub(crate) struct DefineClassGetterByValue;
impl Operation for DefineClassGetterByValue {
const NAME: &'static str = "DefineClassGetterByValue";
const INSTRUCTION: &'static str = "INST - DefineClassGetterByValue";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let function = context.vm.pop();
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 @@ -16,7 +16,7 @@ pub(crate) struct DefineClassStaticMethodByName;
impl Operation for DefineClassStaticMethodByName {
const NAME: &'static str = "DefineClassStaticMethodByName";
const INSTRUCTION: &'static str = "INST - DefineClassStaticMethodByName";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down Expand Up @@ -63,7 +63,7 @@ pub(crate) struct DefineClassMethodByName;
impl Operation for DefineClassMethodByName {
const NAME: &'static str = "DefineClassMethodByName";
const INSTRUCTION: &'static str = "INST - DefineClassMethodByName";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let index = context.vm.read::<u32>();
Expand Down Expand Up @@ -116,7 +116,7 @@ pub(crate) struct DefineClassStaticMethodByValue;
impl Operation for DefineClassStaticMethodByValue {
const NAME: &'static str = "DefineClassStaticMethodByValue";
const INSTRUCTION: &'static str = "INST - DefineClassStaticMethodByValue";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let function = context.vm.pop();
Expand Down Expand Up @@ -163,7 +163,7 @@ pub(crate) struct DefineClassMethodByValue;
impl Operation for DefineClassMethodByValue {
const NAME: &'static str = "DefineClassMethodByValue";
const INSTRUCTION: &'static str = "INST - DefineClassMethodByValue";
const COST: usize = 6;
const COST: u8 = 6;

fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> {
let function = context.vm.pop();
Expand Down
Loading

0 comments on commit f5912de

Please sign in to comment.