doughlang: symbol interning and AST reparameterization

- intern: Add interners from cl-intern

- ast:
- Break AST into ternimals (AstTypes) and nonterminals (Expr, Pat, Bind, Make, Use)
- Make AST generic over terminals (except operators, for now)
This commit is contained in:
2026-01-06 04:57:15 -05:00
parent e4c008bd4b
commit 2be73d2660
17 changed files with 952 additions and 592 deletions

View File

@@ -90,50 +90,50 @@ impl Weight {
}
}
impl<'a> Visit<'a> for Weight {
impl<'a, A: AstTypes> Visit<'a, A> for Weight {
type Error = Infallible;
fn visit_expr<A: Annotation>(&mut self, item: &'a Expr<A>) -> Result<(), Self::Error> {
fn visit_expr(&mut self, item: &'a Expr<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_ident(&mut self, item: &'a str) -> Result<(), Self::Error> {
fn visit_symbol(&mut self, item: &'a A::Symbol) -> Result<(), Self::Error> {
self.size += size_of_val(item);
Ok(())
}
fn visit_path(&mut self, item: &'a A::Path) -> Result<(), Self::Error> {
self.size += size_of_val(item);
Ok(())
}
fn visit_literal(&mut self, item: &'a A::Literal) -> Result<(), Self::Error> {
self.size += size_of_val(item);
Ok(())
}
fn visit_use(&mut self, item: &'a Use<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_path(&mut self, item: &'a Path) -> Result<(), Self::Error> {
self.size += size_of_val(item) + size_of_val(item.parts.as_slice());
item.children(self)
}
fn visit_literal(&mut self, item: &'a Literal) -> Result<(), Self::Error> {
fn visit_pat(&mut self, item: &'a Pat<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_use(&mut self, item: &'a Use) -> Result<(), Self::Error> {
fn visit_bind(&mut self, item: &'a Bind<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_pat<A: Annotation>(&mut self, item: &'a Pat<A>) -> Result<(), Self::Error> {
fn visit_make(&mut self, item: &'a Make<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_bind<A: Annotation>(&mut self, item: &'a Bind<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_make<A: Annotation>(&mut self, item: &'a Make<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}
fn visit_makearm<A: Annotation>(&mut self, item: &'a MakeArm<A>) -> Result<(), Self::Error> {
fn visit_makearm(&mut self, item: &'a MakeArm<A>) -> Result<(), Self::Error> {
self.size += size_of_val(item);
item.children(self)
}