feat: rename to aiken and add e2e tests for uplc

This commit is contained in:
rvcas
2022-06-11 23:22:24 -04:00
parent 1ef116fcda
commit 984c253f31
17 changed files with 9915 additions and 330 deletions

View File

@@ -0,0 +1,57 @@
use std::collections::HashMap;
use crate::ast::{Name, Program, Term, Unique};
pub struct Interner {
identifiers: HashMap<String, Unique>,
current: Unique,
}
impl Interner {
pub fn new() -> Self {
Interner {
identifiers: HashMap::new(),
current: Unique::new(0),
}
}
pub fn program(&mut self, program: &mut Program<Name>) {
self.term(&mut program.term);
}
pub fn term(&mut self, term: &mut Term<Name>) {
match term {
Term::Var(name) => name.unique = self.intern(&name.text),
Term::Delay(term) => self.term(term),
Term::Lambda {
parameter_name,
body,
} => {
parameter_name.unique = self.intern(&parameter_name.text);
self.term(body);
}
Term::Apply { function, argument } => {
self.term(function);
self.term(argument);
}
Term::Constant(_) => (),
Term::Force(term) => self.term(term),
Term::Error => (),
Term::Builtin(_) => (),
}
}
fn intern(&mut self, text: &str) -> Unique {
if let Some(u) = self.identifiers.get(text) {
*u
} else {
let unique = self.current;
self.identifiers.insert(text.to_string(), unique);
self.current.increment();
unique
}
}
}