Skip to content

Commit 5d3df10

Browse files
committed
context: add run context
1 parent 17774fb commit 5d3df10

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

crates/leanVm/src/context/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod run_context;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::memory::address::MemoryAddress;
2+
3+
#[derive(Debug)]
4+
pub struct RunContext {
5+
/// The address in memory of the current instruction to be executed.
6+
pub(crate) pc: MemoryAddress,
7+
/// Points to the beginning of the stack frame of the current function.
8+
///
9+
/// The value of `fp` stays the same fopr all the instructions in the same invocation of a function.
10+
pub(crate) fp: MemoryAddress,
11+
}
12+
13+
impl RunContext {
14+
#[must_use]
15+
pub const fn new(pc: MemoryAddress, fp: MemoryAddress) -> Self {
16+
Self { pc, fp }
17+
}
18+
19+
#[must_use]
20+
pub const fn pc(&self) -> &MemoryAddress {
21+
&self.pc
22+
}
23+
24+
#[must_use]
25+
pub const fn fp(&self) -> &MemoryAddress {
26+
&self.fp
27+
}
28+
}

crates/leanVm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod context;
12
pub mod memory;

0 commit comments

Comments
 (0)