re-organize project

This commit is contained in:
2024-03-29 16:20:34 +07:00
parent 8f7685e8ea
commit 2689fd9d1b
10 changed files with 153 additions and 43 deletions

7
executor/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "executor"
version = "0.1.0"
edition = "2021"
[dependencies]
albireo = { path = "../albireo" }

22
executor/src/errors.rs Normal file
View File

@ -0,0 +1,22 @@
use std::fmt;
pub type Result<T> = std::result::Result<T, ExecutionError>;
#[derive(Debug)]
pub enum ExecutionError {
MainNotFound,
MainSignatureIncorrect,
}
impl std::error::Error for ExecutionError {}
impl fmt::Display for ExecutionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ExecutionError::MainNotFound =>
write!(f, "main function not found"),
ExecutionError::MainSignatureIncorrect =>
write!(f, "main function signature is incorrect, expecting Fn([], T) for any output type T"),
}
}
}

23
executor/src/lib.rs Normal file
View File

@ -0,0 +1,23 @@
pub mod errors;
use errors::{Result, ExecutionError};
use albireo::{Expression, Type, Identifier, Module, Declaration};
// TODO: accepting a module map not a module
pub fn run_program(module: Module) -> Result<()> {
let main = module.declaration.get(&Identifier { name: "main".into() })
.ok_or(ExecutionError::MainNotFound)?;
// expecting main to be function receiving no parameter
if let Declaration::Variable(_, Type::Function(input, _), _) = main {
if input.len() != 0 {
return Err(ExecutionError::MainSignatureIncorrect)
}
} else {
return Err(ExecutionError::MainSignatureIncorrect)
};
println!("main {:?}", main);
Ok(())
}