use alloc::{sync::Arc, vec::Vec};
use core::future::Future;
use miden_core::{
Felt, Word,
advice::AdviceMap,
crypto::merkle::InnerNodeInfo,
events::{EventId, EventName},
mast::MastForest,
operations::DebugOptions,
precompile::PrecompileRequest,
};
use miden_debug_types::{Location, SourceFile, SourceSpan};
use crate::{DebugError, ProcessorState, TraceError};
pub(super) mod advice;
pub mod debug;
pub mod default;
pub mod handlers;
use handlers::{DebugHandler, EventError};
mod mast_forest_store;
pub use mast_forest_store::{MastForestStore, MemMastForestStore};
#[derive(Debug, PartialEq, Eq)]
pub enum AdviceMutation {
ExtendStack { values: Vec<Felt> },
ExtendMap { other: AdviceMap },
ExtendMerkleStore { infos: Vec<InnerNodeInfo> },
ExtendPrecompileRequests { data: Vec<PrecompileRequest> },
}
impl AdviceMutation {
pub fn extend_stack(iter: impl IntoIterator<Item = Felt>) -> Self {
Self::ExtendStack { values: Vec::from_iter(iter) }
}
pub fn extend_map(other: AdviceMap) -> Self {
Self::ExtendMap { other }
}
pub fn extend_merkle_store(infos: impl IntoIterator<Item = InnerNodeInfo>) -> Self {
Self::ExtendMerkleStore { infos: Vec::from_iter(infos) }
}
pub fn extend_precompile_requests(data: impl IntoIterator<Item = PrecompileRequest>) -> Self {
Self::ExtendPrecompileRequests { data: Vec::from_iter(data) }
}
}
pub trait Host {
fn get_label_and_source_file(
&self,
location: &Location,
) -> (SourceSpan, Option<Arc<SourceFile>>);
fn get_mast_forest(&self, node_digest: &Word) -> impl FutureMaybeSend<Option<Arc<MastForest>>>;
fn on_event(
&mut self,
process: &ProcessorState<'_>,
) -> impl FutureMaybeSend<Result<Vec<AdviceMutation>, EventError>>;
fn on_debug(
&mut self,
process: &ProcessorState,
options: &DebugOptions,
) -> Result<(), DebugError> {
let mut handler = debug::DefaultDebugHandler::default();
handler.on_debug(process, options)
}
fn on_trace(&mut self, process: &ProcessorState, trace_id: u32) -> Result<(), TraceError> {
let mut handler = debug::DefaultDebugHandler::default();
handler.on_trace(process, trace_id)
}
fn resolve_event(&self, _event_id: EventId) -> Option<&EventName> {
None
}
}
#[cfg(target_family = "wasm")]
pub trait FutureMaybeSend<O>: Future<Output = O> {}
#[cfg(target_family = "wasm")]
impl<T, O> FutureMaybeSend<O> for T where T: Future<Output = O> {}
#[cfg(not(target_family = "wasm"))]
pub trait FutureMaybeSend<O>: Future<Output = O> + Send {}
#[cfg(not(target_family = "wasm"))]
impl<T, O> FutureMaybeSend<O> for T where T: Future<Output = O> + Send {}