1use std::{sync::mpsc::Sender, fmt::Display, error::Error};
2
3use flatten::flatten;
4use kind_report::data::Diagnostic;
5use kind_tree::untyped;
6
7pub use compile::File;
8
9mod compile;
10mod diagnostic;
11mod flatten;
12mod linearize;
13mod subst;
14
15#[derive(Debug)]
16pub struct GenericCompilationToHVMError;
17
18impl Display for GenericCompilationToHVMError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 write!(f, "generic compilation to hvm error")
21 }
22}
23
24impl Error for GenericCompilationToHVMError { }
25
26pub fn compile_book(
27 book: untyped::Book,
28 sender: Sender<Box<dyn Diagnostic>>,
29 namespace: &str,
30) -> Result<compile::File, GenericCompilationToHVMError> {
31 let flattened = flatten(book);
34
35 let file = compile::compile_book(&flattened, sender, namespace)?;
36
37 let file = linearize::linearize_file(file);
38 Ok(file)
39}