re-organize project
This commit is contained in:
7
executor/Cargo.toml
Normal file
7
executor/Cargo.toml
Normal 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
22
executor/src/errors.rs
Normal 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
23
executor/src/lib.rs
Normal 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(())
|
||||
}
|
Reference in New Issue
Block a user