1pub mod lexer;
21pub mod ast;
22pub mod parser;
23pub mod types;
24pub mod effects;
25pub mod codegen;
26pub mod runtime;
27pub mod stdlib;
28pub mod error;
29pub mod span;
30pub mod comptime;
31pub mod diagnostics;
32pub mod packager;
33pub mod lsp;
34pub mod monomorphize;
35
36
37pub use lexer::Lexer;
38pub use parser::Parser;
39pub use ast::*;
40pub use types::*;
41pub use effects::*;
42pub use error::KoreError;
43pub use span::Span;
44
45pub fn compile(source: &str, target: CompileTarget) -> Result<Vec<u8>, KoreError> {
47 let tokens = Lexer::new(source).tokenize()?;
49
50 let mut ast = Parser::new(&tokens).parse()?;
52
53 comptime::eval_program(&mut ast)?;
56
57 let mut typed_ast = types::check(&ast)?;
59
60 if matches!(target, CompileTarget::Llvm | CompileTarget::Wasm | CompileTarget::SpirV | CompileTarget::Interpret) {
62 let mono_prog = monomorphize::monomorphize(&typed_ast)?;
63 typed_ast.items = mono_prog.items;
68 }
69
70 match target {
72 CompileTarget::Wasm => codegen::wasm::generate(&typed_ast),
73 #[cfg(feature = "llvm")]
74 CompileTarget::Llvm => codegen::llvm::generate(&typed_ast),
75 #[cfg(not(feature = "llvm"))]
76 CompileTarget::Llvm => Err(KoreError::codegen("LLVM backend not compiled. Rebuild with --features llvm", Span::new(0, 0))),
77 CompileTarget::SpirV => codegen::spirv::generate(&typed_ast),
78 CompileTarget::Interpret => {
79 runtime::interpret(&typed_ast)?;
80 Ok(vec![])
81 }
82 CompileTarget::Test => {
83 runtime::run_tests(&typed_ast)?;
84 Ok(vec![])
85 }
86 }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq)]
90pub enum CompileTarget {
91 Wasm,
92 Llvm,
93 SpirV,
94 Interpret,
95 Test,
96}
97
98pub const VERSION: &str = "0.1.0";
100pub const LANGUAGE_NAME: &str = "KORE";
101