miden_core/stack/mod.rs
1use super::{
2 Felt,
3 errors::{InputError, OutputError},
4};
5use crate::utils::{ByteWriter, Serializable};
6
7mod inputs;
8pub use inputs::StackInputs;
9
10mod outputs;
11pub use outputs::StackOutputs;
12
13#[cfg(test)]
14mod tests;
15
16// CONSTANTS
17// ================================================================================================
18
19/// Represents:
20/// - Number of elements that can be initialized at the start of execution and remain populated at
21/// the end of execution.
22/// - Number of elements that can be accessed directly via instructions.
23/// - Number of elements that remain visible to the callee when the context is switched via `call`
24/// or `syscall` instructions.
25/// - Number of elements below which the depth of the stack never drops.
26pub const MIN_STACK_DEPTH: usize = 16;
27
28// HELPER FUNCTIONS
29// ================================================================================================
30
31/// Get the number of non-zero stack elements.
32fn get_num_stack_values(values: &[Felt; MIN_STACK_DEPTH]) -> u8 {
33 let mut num_trailing_zeros = 0;
34 for v in values.iter().rev() {
35 if v.as_int() == 0 {
36 num_trailing_zeros += 1;
37 } else {
38 break;
39 }
40 }
41 (MIN_STACK_DEPTH - num_trailing_zeros) as u8
42}