Skip to content

Commit

Permalink
doc: remove redundant comments and doc-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Oct 18, 2023
1 parent c8eaf8c commit 546167e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
15 changes: 2 additions & 13 deletions triton-vm/src/op_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,33 @@ impl OpStack {
Self { stack }
}

/// Push an element onto the op-stack.
pub(crate) fn push(&mut self, element: BFieldElement) {
self.stack.push(element);
}

/// Push an extension field element onto the op-stack.
pub(crate) fn push_extension_field_element(&mut self, element: XFieldElement) {
for coefficient in element.coefficients.into_iter().rev() {
self.push(coefficient);
}
}

/// Pop an element from the op-stack.
pub(crate) fn pop(&mut self) -> Result<BFieldElement> {
self.stack.pop().ok_or_else(|| anyhow!(OpStackTooShallow))
}

/// Pop an extension field element from the op-stack.
pub(crate) fn pop_extension_field_element(&mut self) -> Result<XFieldElement> {
let coefficients = self.pop_multiple()?;
let element = XFieldElement::new(coefficients);
Ok(element)
}

/// Pop a u32 from the op-stack.
pub(crate) fn pop_u32(&mut self) -> Result<u32> {
let element = self.pop()?;
element
.try_into()
.map_err(|_| anyhow!(FailedU32Conversion(element)))
}

/// Pop multiple elements from the op-stack.
pub(crate) fn pop_multiple<const N: usize>(&mut self) -> Result<[BFieldElement; N]> {
let mut popped_elements = [BFieldElement::zero(); N];
for element in popped_elements.iter_mut() {
Expand All @@ -87,35 +81,30 @@ impl OpStack {
Ok(popped_elements)
}

/// Fetches the indicated stack element without modifying the stack.
pub(crate) fn peek_at(&self, stack_element: OpStackElement) -> BFieldElement {
let stack_element_index = usize::from(stack_element);
let top_of_stack_index = self.stack.len() - 1;
self.stack[top_of_stack_index - stack_element_index]
}

/// Fetches the top-most extension field element without modifying the stack.
pub(crate) fn peek_at_top_extension_field_element(&self) -> XFieldElement {
let coefficients = [self.peek_at(ST0), self.peek_at(ST1), self.peek_at(ST2)];
XFieldElement::new(coefficients)
}

/// Swaps the top of the stack with the indicated stack element.
pub(crate) fn swap_top_with(&mut self, stack_element: OpStackElement) {
let stack_element_index = usize::from(stack_element);
let top_of_stack_index = self.stack.len() - 1;
self.stack
.swap(top_of_stack_index, top_of_stack_index - stack_element_index);
}

/// `true` if and only if the op-stack contains fewer elements than the number of
/// op-stack registers, _i.e._, [`OpStackElement::COUNT`].
pub(crate) fn is_too_shallow(&self) -> bool {
self.stack.len() < OpStackElement::COUNT
}

/// The address of the next free address of the op-stack.
/// Equivalent to the current length of the op-stack.
/// The address of the next free address of the op-stack. Equivalent to the current length of
/// the op-stack.
pub(crate) fn op_stack_pointer(&self) -> BFieldElement {
(self.stack.len() as u64).into()
}
Expand Down
3 changes: 0 additions & 3 deletions triton-vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub const NUM_HELPER_VARIABLE_REGISTERS: usize = 7;

#[derive(Debug, Clone)]
pub struct VMState<'pgm> {
// Memory
/// The **program memory** stores the instructions (and their arguments) of the program
/// currently being executed by Triton VM. It is read-only.
pub program: &'pgm [Instruction],
Expand All @@ -66,7 +65,6 @@ pub struct VMState<'pgm> {
/// The **Jump-stack memory** stores the entire jump stack.
pub jump_stack: Vec<(BFieldElement, BFieldElement)>,

// Registers
/// Number of cycles the program has been running for
pub cycle_count: u32,

Expand All @@ -86,7 +84,6 @@ pub struct VMState<'pgm> {
/// exposed outside of the VM.
pub sponge_state: [BFieldElement; tip5::STATE_SIZE],

// Bookkeeping
/// Indicates whether the terminating instruction `halt` has been executed.
pub halting: bool,
}
Expand Down

0 comments on commit 546167e

Please sign in to comment.