use std::fmt;
use zksync_vm2_interface::ShouldStop;
use crate::{addressing_modes::Arguments, vm::VirtualMachine};
pub struct Instruction<T, W> {
pub(crate) handler: Handler<T, W>,
pub(crate) arguments: Arguments,
}
impl<T, W> fmt::Debug for Instruction<T, W> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("Instruction")
.field("arguments", &self.arguments)
.finish_non_exhaustive()
}
}
pub(crate) type Handler<T, W> = fn(&mut VirtualMachine<T, W>, &mut W, &mut T) -> ExecutionStatus;
#[derive(Debug)]
pub(crate) enum ExecutionStatus {
Running,
Stopped(ExecutionEnd),
}
impl ExecutionStatus {
#[must_use]
#[inline(always)]
pub(crate) fn merge_tracer(self, should_stop: ShouldStop) -> Self {
match (&self, should_stop) {
(Self::Running, ShouldStop::Stop) => Self::Stopped(ExecutionEnd::StoppedByTracer),
_ => self,
}
}
}
impl From<ShouldStop> for ExecutionStatus {
fn from(should_stop: ShouldStop) -> Self {
match should_stop {
ShouldStop::Stop => Self::Stopped(ExecutionEnd::StoppedByTracer),
ShouldStop::Continue => Self::Running,
}
}
}
#[derive(Debug, PartialEq)]
pub enum ExecutionEnd {
ProgramFinished(Vec<u8>),
Reverted(Vec<u8>),
Panicked,
SuspendedOnHook(u32),
StoppedByTracer,
}