-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate interpreter stack(s) a bit better
- Loading branch information
Showing
9 changed files
with
186 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod init_once; | |
pub mod thread; | ||
mod vector_clock; | ||
pub mod weak_memory; | ||
mod stack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::*; | ||
|
||
/// An encapsulated call stack, so encapsulated to enable efficient caching of metadata about the | ||
/// contained `Frame`. | ||
pub struct Stack<'mir, 'tcx> { | ||
frames: Vec<Frame<'mir, 'tcx, Provenance, FrameData<'tcx>>>, | ||
} | ||
|
||
impl<'mir, 'tcx> Stack<'mir, 'tcx> { | ||
pub fn new() -> Self { | ||
Stack { frames: Vec::new() } | ||
} | ||
|
||
/// Does this `Stack` contain any `Frame`s? | ||
pub fn is_empty(&self) -> bool { | ||
self.frames.is_empty() | ||
} | ||
|
||
/// Borrow the call frames of a `Stack`. | ||
pub fn frames(&self) -> &[Frame<'mir, 'tcx, Provenance, FrameData<'tcx>>] { | ||
&self.frames[..] | ||
} | ||
|
||
/// Mutably borrow the call frames of a `Stack`. | ||
pub fn frames_mut(&mut self) -> &mut [Frame<'mir, 'tcx, Provenance, FrameData<'tcx>>] { | ||
&mut self.frames[..] | ||
} | ||
|
||
/// Push a new `Frame` onto a `Stack`. | ||
pub fn push(&mut self, frame: Frame<'mir, 'tcx, Provenance, FrameData<'tcx>>) { | ||
self.frames.push(frame); | ||
} | ||
|
||
/// Try to pop a `Frame` from a `Stack`. | ||
pub fn pop(&mut self) -> Option<Frame<'mir, 'tcx, Provenance, FrameData<'tcx>>> { | ||
self.frames.pop() | ||
} | ||
} | ||
|
||
impl VisitTags for Stack<'_, '_> { | ||
fn visit_tags(&self, visit: &mut dyn FnMut(SbTag)) { | ||
let Stack { frames } = self; | ||
for frame in frames { | ||
frame.visit_tags(visit); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters