Browse Source

Generate `Opcode` impl using macro (#2391)

This reduces a lot of the repetition from the `Opcode` functions and makes it easier to add a new Op.
pull/2396/head
José Julián Espina 2 years ago
parent
commit
18824baba8
  1. 172
      boa_engine/src/vm/mod.rs
  2. 2885
      boa_engine/src/vm/opcode/mod.rs

172
boa_engine/src/vm/mod.rs

@ -15,9 +15,6 @@ mod call_frame;
mod code_block; mod code_block;
mod opcode; mod opcode;
#[allow(clippy::wildcard_imports)]
use opcode::*;
pub use {call_frame::CallFrame, code_block::CodeBlock, opcode::Opcode}; pub use {call_frame::CallFrame, code_block::CodeBlock, opcode::Opcode};
pub(crate) use { pub(crate) use {
@ -126,174 +123,7 @@ impl Context {
let _timer = Profiler::global().start_event(opcode.as_instruction_str(), "vm"); let _timer = Profiler::global().start_event(opcode.as_instruction_str(), "vm");
let result = match opcode { let result = opcode.execute(self)?;
Opcode::Nop => Nop::execute(self)?,
Opcode::Pop => Pop::execute(self)?,
Opcode::PopIfThrown => PopIfThrown::execute(self)?,
Opcode::Dup => Dup::execute(self)?,
Opcode::Swap => Swap::execute(self)?,
Opcode::RotateLeft => RotateLeft::execute(self)?,
Opcode::RotateRight => RotateRight::execute(self)?,
Opcode::PushUndefined => PushUndefined::execute(self)?,
Opcode::PushNull => PushNull::execute(self)?,
Opcode::PushTrue => PushTrue::execute(self)?,
Opcode::PushFalse => PushFalse::execute(self)?,
Opcode::PushZero => PushZero::execute(self)?,
Opcode::PushOne => PushOne::execute(self)?,
Opcode::PushInt8 => PushInt8::execute(self)?,
Opcode::PushInt16 => PushInt16::execute(self)?,
Opcode::PushInt32 => PushInt32::execute(self)?,
Opcode::PushRational => PushRational::execute(self)?,
Opcode::PushNaN => PushNaN::execute(self)?,
Opcode::PushPositiveInfinity => PushPositiveInfinity::execute(self)?,
Opcode::PushNegativeInfinity => PushNegativeInfinity::execute(self)?,
Opcode::PushLiteral => PushLiteral::execute(self)?,
Opcode::PushEmptyObject => PushEmptyObject::execute(self)?,
Opcode::PushClassPrototype => PushClassPrototype::execute(self)?,
Opcode::SetClassPrototype => SetClassPrototype::execute(self)?,
Opcode::SetHomeObject => SetHomeObject::execute(self)?,
Opcode::PushNewArray => PushNewArray::execute(self)?,
Opcode::PushValueToArray => PushValueToArray::execute(self)?,
Opcode::PushElisionToArray => PushElisionToArray::execute(self)?,
Opcode::PushIteratorToArray => PushIteratorToArray::execute(self)?,
Opcode::Add => Add::execute(self)?,
Opcode::Sub => Sub::execute(self)?,
Opcode::Mul => Mul::execute(self)?,
Opcode::Div => Div::execute(self)?,
Opcode::Pow => Pow::execute(self)?,
Opcode::Mod => Mod::execute(self)?,
Opcode::BitAnd => BitAnd::execute(self)?,
Opcode::BitOr => BitOr::execute(self)?,
Opcode::BitXor => BitXor::execute(self)?,
Opcode::ShiftLeft => ShiftLeft::execute(self)?,
Opcode::ShiftRight => ShiftRight::execute(self)?,
Opcode::UnsignedShiftRight => UnsignedShiftRight::execute(self)?,
Opcode::Eq => Eq::execute(self)?,
Opcode::NotEq => NotEq::execute(self)?,
Opcode::StrictEq => StrictEq::execute(self)?,
Opcode::StrictNotEq => StrictNotEq::execute(self)?,
Opcode::GreaterThan => GreaterThan::execute(self)?,
Opcode::GreaterThanOrEq => GreaterThanOrEq::execute(self)?,
Opcode::LessThan => LessThan::execute(self)?,
Opcode::LessThanOrEq => LessThanOrEq::execute(self)?,
Opcode::In => In::execute(self)?,
Opcode::InstanceOf => InstanceOf::execute(self)?,
Opcode::Void => Void::execute(self)?,
Opcode::TypeOf => TypeOf::execute(self)?,
Opcode::Pos => Pos::execute(self)?,
Opcode::Neg => Neg::execute(self)?,
Opcode::Inc => Inc::execute(self)?,
Opcode::IncPost => IncPost::execute(self)?,
Opcode::Dec => Dec::execute(self)?,
Opcode::DecPost => DecPost::execute(self)?,
Opcode::LogicalNot => LogicalNot::execute(self)?,
Opcode::BitNot => BitNot::execute(self)?,
Opcode::DefVar => DefVar::execute(self)?,
Opcode::DefInitVar => DefInitVar::execute(self)?,
Opcode::DefLet => DefLet::execute(self)?,
Opcode::DefInitLet => DefInitLet::execute(self)?,
Opcode::DefInitConst => DefInitConst::execute(self)?,
Opcode::DefInitArg => DefInitArg::execute(self)?,
Opcode::GetName => GetName::execute(self)?,
Opcode::GetNameOrUndefined => GetNameOrUndefined::execute(self)?,
Opcode::SetName => SetName::execute(self)?,
Opcode::Jump => Jump::execute(self)?,
Opcode::JumpIfFalse => JumpIfFalse::execute(self)?,
Opcode::JumpIfNotUndefined => JumpIfNotUndefined::execute(self)?,
Opcode::JumpIfNullOrUndefined => JumpIfNullOrUndefined::execute(self)?,
Opcode::LogicalAnd => LogicalAnd::execute(self)?,
Opcode::LogicalOr => LogicalOr::execute(self)?,
Opcode::Coalesce => Coalesce::execute(self)?,
Opcode::ToBoolean => ToBoolean::execute(self)?,
Opcode::GetPropertyByName => GetPropertyByName::execute(self)?,
Opcode::GetPropertyByValue => GetPropertyByValue::execute(self)?,
Opcode::GetPropertyByValuePush => GetPropertyByValuePush::execute(self)?,
Opcode::SetPropertyByName => SetPropertyByName::execute(self)?,
Opcode::DefineOwnPropertyByName => DefineOwnPropertyByName::execute(self)?,
Opcode::DefineClassMethodByName => DefineClassMethodByName::execute(self)?,
Opcode::SetPropertyByValue => SetPropertyByValue::execute(self)?,
Opcode::DefineOwnPropertyByValue => DefineOwnPropertyByValue::execute(self)?,
Opcode::DefineClassMethodByValue => DefineClassMethodByValue::execute(self)?,
Opcode::SetPropertyGetterByName => SetPropertyGetterByName::execute(self)?,
Opcode::DefineClassGetterByName => DefineClassGetterByName::execute(self)?,
Opcode::SetPropertyGetterByValue => SetPropertyGetterByValue::execute(self)?,
Opcode::DefineClassGetterByValue => DefineClassGetterByValue::execute(self)?,
Opcode::SetPropertySetterByName => SetPropertySetterByName::execute(self)?,
Opcode::DefineClassSetterByName => DefineClassSetterByName::execute(self)?,
Opcode::SetPropertySetterByValue => SetPropertySetterByValue::execute(self)?,
Opcode::DefineClassSetterByValue => DefineClassSetterByValue::execute(self)?,
Opcode::AssignPrivateField => AssignPrivateField::execute(self)?,
Opcode::SetPrivateField => SetPrivateField::execute(self)?,
Opcode::SetPrivateMethod => SetPrivateMethod::execute(self)?,
Opcode::SetPrivateSetter => SetPrivateSetter::execute(self)?,
Opcode::SetPrivateGetter => SetPrivateGetter::execute(self)?,
Opcode::GetPrivateField => GetPrivateField::execute(self)?,
Opcode::PushClassField => PushClassField::execute(self)?,
Opcode::PushClassFieldPrivate => PushClassFieldPrivate::execute(self)?,
Opcode::PushClassPrivateGetter => PushClassPrivateGetter::execute(self)?,
Opcode::PushClassPrivateSetter => PushClassPrivateSetter::execute(self)?,
Opcode::PushClassPrivateMethod => PushClassPrivateMethod::execute(self)?,
Opcode::DeletePropertyByName => DeletePropertyByName::execute(self)?,
Opcode::DeletePropertyByValue => DeletePropertyByValue::execute(self)?,
Opcode::CopyDataProperties => CopyDataProperties::execute(self)?,
Opcode::ToPropertyKey => ToPropertyKey::execute(self)?,
Opcode::Throw => Throw::execute(self)?,
Opcode::TryStart => TryStart::execute(self)?,
Opcode::TryEnd => TryEnd::execute(self)?,
Opcode::CatchEnd => CatchEnd::execute(self)?,
Opcode::CatchStart => CatchStart::execute(self)?,
Opcode::CatchEnd2 => CatchEnd2::execute(self)?,
Opcode::FinallyStart => FinallyStart::execute(self)?,
Opcode::FinallyEnd => FinallyEnd::execute(self)?,
Opcode::FinallySetJump => FinallySetJump::execute(self)?,
Opcode::This => This::execute(self)?,
Opcode::Super => Super::execute(self)?,
Opcode::SuperCall => SuperCall::execute(self)?,
Opcode::SuperCallSpread => SuperCallSpread::execute(self)?,
Opcode::SuperCallDerived => SuperCallDerived::execute(self)?,
Opcode::Case => Case::execute(self)?,
Opcode::Default => Default::execute(self)?,
Opcode::GetArrowFunction => GetArrowFunction::execute(self)?,
Opcode::GetFunction => GetFunction::execute(self)?,
Opcode::GetFunctionAsync => GetFunctionAsync::execute(self)?,
Opcode::GetGenerator => GetGenerator::execute(self)?,
Opcode::GetGeneratorAsync => GetGeneratorAsync::execute(self)?,
Opcode::CallEval => CallEval::execute(self)?,
Opcode::CallEvalSpread => CallEvalSpread::execute(self)?,
Opcode::Call => Call::execute(self)?,
Opcode::CallSpread => CallSpread::execute(self)?,
Opcode::New => New::execute(self)?,
Opcode::NewSpread => NewSpread::execute(self)?,
Opcode::Return => Return::execute(self)?,
Opcode::PushDeclarativeEnvironment => PushDeclarativeEnvironment::execute(self)?,
Opcode::PushFunctionEnvironment => PushFunctionEnvironment::execute(self)?,
Opcode::PopEnvironment => PopEnvironment::execute(self)?,
Opcode::LoopStart => LoopStart::execute(self)?,
Opcode::LoopContinue => LoopContinue::execute(self)?,
Opcode::LoopEnd => LoopEnd::execute(self)?,
Opcode::ForInLoopInitIterator => ForInLoopInitIterator::execute(self)?,
Opcode::InitIterator => InitIterator::execute(self)?,
Opcode::InitIteratorAsync => InitIteratorAsync::execute(self)?,
Opcode::IteratorNext => IteratorNext::execute(self)?,
Opcode::IteratorClose => IteratorClose::execute(self)?,
Opcode::IteratorToArray => IteratorToArray::execute(self)?,
Opcode::ForInLoopNext => ForInLoopNext::execute(self)?,
Opcode::ForAwaitOfLoopIterate => ForAwaitOfLoopIterate::execute(self)?,
Opcode::ForAwaitOfLoopNext => ForAwaitOfLoopNext::execute(self)?,
Opcode::ConcatToString => ConcatToString::execute(self)?,
Opcode::RequireObjectCoercible => RequireObjectCoercible::execute(self)?,
Opcode::ValueNotNullOrUndefined => ValueNotNullOrUndefined::execute(self)?,
Opcode::RestParameterInit => RestParameterInit::execute(self)?,
Opcode::RestParameterPop => RestParameterPop::execute(self)?,
Opcode::PopOnReturnAdd => PopOnReturnAdd::execute(self)?,
Opcode::PopOnReturnSub => PopOnReturnSub::execute(self)?,
Opcode::Yield => Yield::execute(self)?,
Opcode::GeneratorNext => GeneratorNext::execute(self)?,
Opcode::AsyncGeneratorNext => AsyncGeneratorNext::execute(self)?,
Opcode::GeneratorNextDelegate => GeneratorNextDelegate::execute(self)?,
Opcode::Await => Await::execute(self)?,
Opcode::PushNewTarget => PushNewTarget::execute(self)?,
};
Ok(result) Ok(result)
} }

2885
boa_engine/src/vm/opcode/mod.rs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save