skeleton for codegen
This commit is contained in:
@@ -470,20 +470,48 @@ impl<'a> TermFunctionsBuilder<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize(self) -> (HashMap<TermId, TrieNode>, HashMap<TermId, TrieNode>) {
|
||||
let functions_by_input = self
|
||||
.builders_by_input
|
||||
.into_iter()
|
||||
.map(|(term, builder)| (term, builder.trie))
|
||||
.collect::<HashMap<_, _>>();
|
||||
let functions_by_output = self
|
||||
.builders_by_output
|
||||
.into_iter()
|
||||
.map(|(term, builder)| (term, builder.trie))
|
||||
.collect::<HashMap<_, _>>();
|
||||
(functions_by_input, functions_by_output)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Automata {
|
||||
pub automata_by_input: HashMap<TermId, ()>,
|
||||
pub automata_by_output: HashMap<TermId, ()>,
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Codegen<'a> {
|
||||
typeenv: &'a TypeEnv,
|
||||
termenv: &'a TermEnv,
|
||||
functions_by_input: HashMap<TermId, TrieNode>,
|
||||
functions_by_output: HashMap<TermId, TrieNode>,
|
||||
}
|
||||
|
||||
impl Automata {
|
||||
pub fn compile(typeenv: &TypeEnv, termenv: &TermEnv) -> Result<Automata, Error> {
|
||||
impl<'a> Codegen<'a> {
|
||||
pub fn compile(typeenv: &'a TypeEnv, termenv: &'a TermEnv) -> Result<Codegen<'a>, Error> {
|
||||
let mut builder = TermFunctionsBuilder::new(typeenv, termenv);
|
||||
builder.build();
|
||||
log::trace!("builder: {:?}", builder);
|
||||
// TODO
|
||||
Ok(Automata::default())
|
||||
let (functions_by_input, functions_by_output) = builder.finalize();
|
||||
Ok(Codegen {
|
||||
typeenv,
|
||||
termenv,
|
||||
functions_by_input,
|
||||
functions_by_output,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn generate_rust(&self) -> Result<String, Error> {
|
||||
use std::fmt::Write;
|
||||
let mut code = String::new();
|
||||
writeln!(&mut code, "// GENERATED BY ISLE. DO NOT EDIT!")?;
|
||||
Ok(code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user