Skip to content

Commit

Permalink
feature: introduce Host::advice_provider* to access host's advice p…
Browse files Browse the repository at this point in the history
…rovider
  • Loading branch information
greenhat committed Nov 18, 2024
1 parent bcc722b commit 65a3060
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions miden/tests/integration/operations/decorators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ impl Default for TestHost<MemAdviceProvider> {
}

impl<A: AdviceProvider> Host for TestHost<A> {
type AdviceProvider = A;

fn advice_provider(&self) -> &Self::AdviceProvider {
&self.adv_provider
}

fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider {
&mut self.adv_provider
}

fn get_advice<S: ProcessState>(
&mut self,
process: &S,
Expand Down
28 changes: 28 additions & 0 deletions processor/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ pub use mast_forest_store::{MastForestStore, MemMastForestStore};
/// state of the VM ([ProcessState]), which it can use to extract the data required to fulfill the
/// request.
pub trait Host {
type AdviceProvider: AdviceProvider;

// REQUIRED METHODS
// --------------------------------------------------------------------------------------------

/// Returns a reference to the advice provider.
fn advice_provider(&self) -> &Self::AdviceProvider;

/// Returns a mutable reference to the advice provider.
fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider;

/// Returns the requested advice, specified by [AdviceExtractor], from the host to the VM.
fn get_advice<P: ProcessState>(
&mut self,
Expand Down Expand Up @@ -180,6 +188,16 @@ impl<H> Host for &mut H
where
H: Host,
{
type AdviceProvider = H::AdviceProvider;

fn advice_provider(&self) -> &Self::AdviceProvider {
H::advice_provider(self)
}

fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider {
H::advice_provider_mut(self)
}

fn get_advice<S: ProcessState>(
&mut self,
process: &S,
Expand Down Expand Up @@ -339,6 +357,16 @@ impl<A> Host for DefaultHost<A>
where
A: AdviceProvider,
{
type AdviceProvider = A;

fn advice_provider(&self) -> &Self::AdviceProvider {
&self.adv_provider
}

fn advice_provider_mut(&mut self) -> &mut Self::AdviceProvider {
&mut self.adv_provider
}

fn get_advice<P: ProcessState>(
&mut self,
process: &P,
Expand Down

0 comments on commit 65a3060

Please sign in to comment.