rill_lang/backend/mod.rs
1//! Compilation backends: turn IR into a runnable `RillProgram`.
2
3pub mod interp;
4
5use rill_core::math::Transcendental;
6
7use crate::error::CompileError;
8use crate::ir::Ir;
9use crate::program::RillProgram;
10
11/// A backend builds a runnable program from lowered IR.
12pub trait Backend {
13 /// Build a program for scalar type `T`.
14 fn build<T: Transcendental>(&self, ir: Ir) -> Result<RillProgram<T>, CompileError>;
15}
16
17/// The default safe interpreter backend.
18#[derive(Debug, Default, Clone, Copy)]
19pub struct InterpBackend;
20
21impl Backend for InterpBackend {
22 fn build<T: Transcendental>(&self, ir: Ir) -> Result<RillProgram<T>, CompileError> {
23 Ok(RillProgram::new(ir))
24 }
25}