Dead end with macros

This commit is contained in:
2023-03-05 19:55:38 +00:00
parent ca23edabe4
commit b9d47c3181
30 changed files with 1518 additions and 332 deletions

View File

@@ -54,10 +54,10 @@ macro_rules! xloop {
(for $p:pat in $it:expr; $body:stmt) => {
xloop!(for $p in $it; $body; ())
};
(for $p:pat in $it:expr; $body:stmt; $exit:stmt) => {
(for $p:pat in $iit:expr; $body:stmt; $exit:stmt) => {
{
let mut __xloop__ = $it.into_iter();
xloop!(let Some($p) = __xloop__.next(); $body; $exit)
let mut i = $iit.into_iter();
xloop!(let Some($p) = i.next(); $body; $exit)
}
};
(let $p:pat = $e:expr; $body:stmt) => {

View File

@@ -1,5 +1,8 @@
mod cache;
pub mod translate;
mod replace_first;
// mod visitor;
pub use replace_first::replace_first;
pub use cache::Cache;
mod substack;
pub use substack::Stackframe;

View File

@@ -0,0 +1,14 @@
use std::iter;
pub fn replace_first<'a, T, F>(slice: &'a [T], mut f: F) -> Option<impl Iterator<Item = T> + 'a>
where T: Clone, F: FnMut(&T) -> Option<T> {
for i in 0..slice.len() {
if let Some(new) = f(&slice[i]) {
let subbed_iter = slice[0..i].iter().cloned()
.chain(iter::once(new))
.chain(slice[i+1..].iter().cloned());
return Some(subbed_iter)
}
}
None
}

18
src/utils/visitor.rs Normal file
View File

@@ -0,0 +1,18 @@
pub trait Visit<T> {
type Return;
fn visit(&self, target: T) -> Return;
}
pub trait ImpureVisit<T> {
type Shard;
type Return;
fn impure_visit(&self, target: T) -> (Shard, Return);
fn merge(&mut self, s: Shard);
}
pub struct OverlayVisitor<VBase, VOver>(VBase, VOver);
impl<VBase, VOver, T, R> Visitor<T> for OverlayVisitor<VBase, VOver>
where VBase: Visitor<T, Return = Option<R>>, VOver: Visitor<T, Return = Option<R>> {
}