Skip to content

Commit

Permalink
refactor: add Library, Program with advice map constructors,
Browse files Browse the repository at this point in the history
`AdviceMap` from iterator constructor.
  • Loading branch information
greenhat committed Nov 19, 2024
1 parent 813b340 commit 5ec902e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion assembly/src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use vm_core::{
debuginfo::Span,
mast::{MastForest, MastNodeId},
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
Kernel,
AdviceMap, Kernel,
};

use crate::ast::{Ident, ProcedureName, QualifiedProcedureName};
Expand Down Expand Up @@ -88,6 +88,15 @@ impl Library {

Ok(Self { digest, exports, mast_forest })
}

pub fn with_advice_map(self, advice_map: AdviceMap) -> Self {
let mut mast_forest = (*self.mast_forest).clone();
mast_forest.advice_map_mut().extend(advice_map);
Self {
mast_forest: Arc::new(mast_forest),
..self
}
}
}

// ------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions core/src/advice/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ impl From<BTreeMap<RpoDigest, Vec<Felt>>> for AdviceMap {
}
}

impl FromIterator<(RpoDigest, Vec<Felt>)> for AdviceMap {
fn from_iter<T: IntoIterator<Item = (RpoDigest, Vec<Felt>)>>(iter: T) -> Self {
Self(iter.into_iter().collect())
}
}

impl IntoIterator for AdviceMap {
type Item = (RpoDigest, Vec<Felt>);
type IntoIter = IntoIter<RpoDigest, Vec<Felt>>;
Expand Down
10 changes: 10 additions & 0 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::Kernel;
use crate::{
mast::{MastForest, MastNode, MastNodeId},
utils::ToElements,
AdviceMap,
};

// PROGRAM
Expand Down Expand Up @@ -53,6 +54,15 @@ impl Program {

Self { mast_forest, entrypoint, kernel }
}

pub fn with_advice_map(self, advice_map: AdviceMap) -> Self {
let mut mast_forest = (*self.mast_forest).clone();
mast_forest.advice_map_mut().extend(advice_map);
Self {
mast_forest: Arc::new(mast_forest),
..self
}
}
}

// ------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 5ec902e

Please sign in to comment.