Skip to content

Commit

Permalink
chore: add section separators and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Jul 7, 2024
1 parent fe8b7a7 commit 5869525
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
7 changes: 5 additions & 2 deletions core/src/mast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub trait MerkleTreeNode {
fn to_display<'a>(&'a self, mast_forest: &'a MastForest) -> impl fmt::Display + 'a;
}

// MAST NODE ID
// ================================================================================================

/// An opaque handle to a [`MastNode`] in some [`MastForest`]. It is the responsibility of the user
/// to use a given [`MastNodeId`] with the corresponding [`MastForest`].
///
Expand Down Expand Up @@ -72,7 +75,7 @@ impl Deserializable for MastNodeId {
}

// MAST FOREST
// ===============================================================================================
// ================================================================================================

/// Represents one or more procedures, represented as a collection of [`MastNode`]s.
///
Expand Down Expand Up @@ -132,7 +135,7 @@ impl MastForest {
/// Returns the [`MastNode`] associated with the provided [`MastNodeId`] if valid, or else
/// `None`.
///
/// This is the faillible version of indexing (e.g. `mast_forest[node_id]`).
/// This is the failable version of indexing (e.g. `mast_forest[node_id]`).
#[inline(always)]
pub fn get_node_by_id(&self, node_id: MastNodeId) -> Option<&MastNode> {
let idx = node_id.0 as usize;
Expand Down
10 changes: 8 additions & 2 deletions core/src/mast/serialization/basic_block_data_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::{

use super::{decorator::EncodedDecoratorVariant, DataOffset, StringIndex, StringRef};

// BASIC BLOCK DATA BUILDER
// ================================================================================================

/// Builds the `data` section of a serialized [`crate::mast::MastForest`].
#[derive(Debug, Default)]
pub struct BasicBlockDataBuilder {
Expand Down Expand Up @@ -62,8 +65,8 @@ impl BasicBlockDataBuilder {

// For operations that have extra data, encode it in `data`.
match operation {
Operation::Assert(value) | Operation::MpVerify(value) => {
self.data.extend_from_slice(&value.to_le_bytes())
Operation::Assert(err_code) | Operation::MpVerify(err_code) => {
self.data.extend_from_slice(&err_code.to_le_bytes())
}
Operation::U32assert2(value) | Operation::Push(value) => {
self.data.extend_from_slice(&value.as_int().to_le_bytes())
Expand Down Expand Up @@ -240,6 +243,9 @@ impl BasicBlockDataBuilder {
}
}

// STRING TABLE BUILDER
// ================================================================================================

#[derive(Debug, Default)]
struct StringTableBuilder {
table: Vec<StringRef>,
Expand Down
4 changes: 2 additions & 2 deletions core/src/mast/serialization/basic_block_data_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl<'a> BasicBlockDataDecoder<'a> {
// operation.
let op_code = first_byte;

let operation = if op_code == Operation::Assert(0_u32).op_code()
|| op_code == Operation::MpVerify(0_u32).op_code()
let operation = if op_code == Operation::Assert(0).op_code()
|| op_code == Operation::MpVerify(0).op_code()
{
let value_le_bytes: [u8; 4] = self.data_reader.read_array()?;
let value = u32::from_le_bytes(value_le_bytes);
Expand Down
8 changes: 4 additions & 4 deletions core/src/mast/serialization/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::mast::{MastForest, MastNode, MastNodeId, MerkleTreeNode};
use super::{basic_block_data_decoder::BasicBlockDataDecoder, DataOffset};

// MAST NODE INFO
// ===============================================================================================
// ================================================================================================

/// Represents a serialized [`MastNode`], with some data inlined in its [`MastNodeType`].
///
Expand All @@ -15,7 +15,7 @@ use super::{basic_block_data_decoder::BasicBlockDataDecoder, DataOffset};
/// field. For all other variants of [`MastNode`], the `offset` field is guaranteed to be 0.
///
/// The serialized representation of [`MastNodeInfo`] is guaranteed to be fixed width, so that the
/// nodes stored in the `nodes` table of the serialzied [`MastForest`] can be accessed quickly by
/// nodes stored in the `nodes` table of the serialized [`MastForest`] can be accessed quickly by
/// index.
#[derive(Debug)]
pub struct MastNodeInfo {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Deserializable for MastNodeInfo {
}

// MAST NODE TYPE
// ===============================================================================================
// ================================================================================================

const JOIN: u8 = 0;
const SPLIT: u8 = 1;
Expand Down Expand Up @@ -393,7 +393,7 @@ impl MastNodeType {
}

// TESTS
// ===============================================================================================
// ================================================================================================

#[cfg(test)]
mod tests {
Expand Down
8 changes: 4 additions & 4 deletions core/src/mast/serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use basic_block_data_decoder::BasicBlockDataDecoder;
mod tests;

// TYPE ALIASES
// ===============================================================================================
// ================================================================================================

/// Specifies an offset into the `data` section of an encoded [`MastForest`].
type DataOffset = u32;
Expand All @@ -27,7 +27,7 @@ type DataOffset = u32;
type StringIndex = usize;

// CONSTANTS
// ===============================================================================================
// ================================================================================================

/// Magic string for detecting that a file is binary-encoded MAST.
const MAGIC: &[u8; 5] = b"MAST\0";
Expand All @@ -40,7 +40,7 @@ const MAGIC: &[u8; 5] = b"MAST\0";
const VERSION: [u8; 3] = [0, 0, 0];

// STRING REF
// ===============================================================================================
// ================================================================================================

/// An entry in the `strings` table of an encoded [`MastForest`].
///
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Deserializable for StringRef {
}

// MAST FOREST SERIALIZATION/DESERIALIZATION
// ===============================================================================================
// ================================================================================================

impl Serializable for MastForest {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/decorators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum Decorator {
Debug(DebugOptions),
/// Emits an event to the host.
Event(u32),
/// Emmits a trace to the host.
/// Emits a trace to the host.
Trace(u32),
}

Expand Down

0 comments on commit 5869525

Please sign in to comment.