truthlinked_axiom_compiler/
lib.rs1pub mod ast;
9pub mod lexer;
10pub mod lower;
11pub mod manifest;
12pub mod parser;
13pub mod typeck;
14
15use std::path::Path;
16
17#[derive(Debug, thiserror::Error)]
18pub enum CompileError {
19 #[error("lex error: {0}")]
20 Lex(#[from] lexer::LexError),
21 #[error("parse error: {0}")]
22 Parse(#[from] parser::ParseError),
23 #[error("type error: {0}")]
24 Type(#[from] typeck::TypeError),
25 #[error("io error: {0}")]
26 Io(#[from] std::io::Error),
27}
28
29pub struct CompileOutput {
30 pub bytecode: Vec<u8>,
31 pub manifest: manifest::Manifest,
32}
33
34pub fn compile(src: &str) -> Result<CompileOutput, CompileError> {
35 let tokens = lexer::lex(src)?;
36 let ast = parser::parse(tokens)?;
37 typeck::check(&ast)?;
38 let ir = lower::lower(&ast);
39 let alloc = truthlinked_axiom_sdk::regalloc::allocate(&ir);
40 let bytecode = truthlinked_axiom_sdk::codegen::emit(&ir, &alloc);
41 let manifest = manifest::generate(&ast);
42 Ok(CompileOutput { bytecode, manifest })
43}
44
45pub fn compile_file(path: &Path) -> Result<CompileOutput, CompileError> {
46 let src = std::fs::read_to_string(path)?;
47 compile(&src)
48}