Add a lot of new stuff to the compile mod
* compile::sym is now compile::name * add basic block structure * add visitor pattern * some other minor things (e.g. syn::ast::prelude) Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
29
src/compile/visit.rs
Normal file
29
src/compile/visit.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::syn::ast::{Stmt, Expr};
|
||||
|
||||
pub trait Visit {
|
||||
type Out;
|
||||
fn visit<A: Accept<Self>>(&mut self, acceptor: &A) -> Self::Out
|
||||
where Self: Sized
|
||||
{
|
||||
acceptor.accept(self)
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, stmt: &Stmt) -> Self::Out;
|
||||
fn visit_expr(&mut self, expr: &Expr) -> Self::Out;
|
||||
}
|
||||
|
||||
pub trait Accept<V: Visit> {
|
||||
fn accept(&self, visitor: &mut V) -> V::Out;
|
||||
}
|
||||
|
||||
impl<V: Visit> Accept<V> for Stmt {
|
||||
fn accept(&self, visitor: &mut V) -> V::Out {
|
||||
visitor.visit_stmt(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Visit> Accept<V> for Expr {
|
||||
fn accept(&self, visitor: &mut V) -> V::Out {
|
||||
visitor.visit_expr(self)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user