1pub mod codegen;
2pub mod containers;
3pub mod context;
4pub mod demod;
5pub mod grammar;
6pub mod typed_ast;
7pub mod typesys;
8
9use std::path::Path;
10
11use demod::Demodularizer;
12use typesys::Type;
13
14pub fn compile(melo_code: &str, module_path: &Path) -> context::CtxResult<(String, Type)> {
16 let mut root_path = module_path
17 .canonicalize()
18 .unwrap_or_else(|_| module_path.to_owned());
19 if root_path.is_file() {
20 root_path.pop();
21 }
22 let fname = module_path.file_name();
23
24 let mut demod = Demodularizer::new_at_fs(&root_path, &root_path.join("melo-libs"));
25 let modid = if let Some(f) = fname {
26 context::ProjectRoot(root_path.clone()).module_from_root(f.as_ref())
27 } else {
28 context::ProjectRoot(root_path.clone()).module_from_root(Path::new("."))
29 };
30 demod.module_override(modid, melo_code.to_string());
31
32 let raw = demod.demod(modid, &root_path)?;
33 let prgrm = typesys::typecheck_program(raw)?;
34 let t = prgrm.body.itype.clone();
35 Ok((codegen::codegen_program(prgrm), t))
36}