-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With the addition of the constant evaluator to the `proc` module, it is now concerned with constructing expressions. Any code that constructs expressions will generally also need to deal with `Emit` statements, which are handled by the `Emitter` type. However, `Emitter` is private to the `front` module. This patch moves it to `proc` and makes it accessible to both the constant evaluator and the front ends.
- Loading branch information
Showing
8 changed files
with
63 additions
and
60 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
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,40 @@ | ||
use crate::arena::Arena; | ||
|
||
/// Helper class to emit expressions | ||
#[allow(dead_code)] | ||
#[derive(Default, Debug)] | ||
pub struct Emitter { | ||
start_len: Option<usize>, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl Emitter { | ||
pub fn start(&mut self, arena: &Arena<crate::Expression>) { | ||
if self.start_len.is_some() { | ||
unreachable!("Emitting has already started!"); | ||
} | ||
self.start_len = Some(arena.len()); | ||
} | ||
pub const fn is_running(&self) -> bool { | ||
self.start_len.is_some() | ||
} | ||
#[must_use] | ||
pub fn finish( | ||
&mut self, | ||
arena: &Arena<crate::Expression>, | ||
) -> Option<(crate::Statement, crate::span::Span)> { | ||
let start_len = self.start_len.take().unwrap(); | ||
if start_len != arena.len() { | ||
#[allow(unused_mut)] | ||
let mut span = crate::span::Span::default(); | ||
let range = arena.range_from(start_len); | ||
#[cfg(feature = "span")] | ||
for handle in range.clone() { | ||
span.subsume(arena.get_span(handle)) | ||
} | ||
Some((crate::Statement::Emit(range), span)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
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