repo: rename executor -> eval

This commit is contained in:
multisn8 2024-01-20 21:36:40 +01:00
parent 23fadce867
commit c4207af8da
Signed by: multisamplednight
GPG key ID: 6D525AA147CBDAE2
8 changed files with 3 additions and 3 deletions

14
crates/eval/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "eval"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { workspace = true, features = [ "derive" ] }
image = "0.24"
ir = { path = "../ir" }
[lints]
workspace = true

View file

@ -0,0 +1 @@
pub(crate) struct CpuExecutor;

View file

@ -0,0 +1,44 @@
pub mod read {
use image::{io::Reader as ImageReader, DynamicImage};
use ir::instruction::read::{Read, SourceType};
pub fn read(Read { source, .. }: Read) -> DynamicImage {
// TODO: actual error handling
let img = ImageReader::open(match source {
SourceType::File(path) => path,
})
.expect("something went wrong :(((");
img.decode().expect("couldn't decode image")
}
}
pub mod write {
use image::{DynamicImage, ImageFormat};
use ir::instruction::write::{TargetFormat, TargetType, Write};
pub fn write(Write { target, format }: Write, input_data: &DynamicImage) {
input_data
.save_with_format(
match target {
TargetType::File(path) => path,
},
match format {
TargetFormat::Jpeg => ImageFormat::Jpeg,
TargetFormat::Png => ImageFormat::Png,
},
)
.expect("couldn't save file — come back later and handle me properly please uwu");
}
}
pub mod filters {
pub mod invert {
use image::DynamicImage;
pub fn invert(mut input_data: DynamicImage) -> DynamicImage {
input_data.invert();
input_data
}
}
}

View file

@ -0,0 +1,37 @@
use ir::instruction::{Filter, Kind};
use crate::value::Dynamic;
mod instructions;
pub struct Executor;
impl crate::Executor for Executor {
fn execute(instruction: Kind, input: Option<Dynamic>) -> Option<Dynamic> {
match instruction {
Kind::Read(read_instruction) => {
Some(Dynamic::Image(instructions::read::read(read_instruction)))
}
Kind::Write(write_instruction) => {
instructions::write::write(
write_instruction,
match input {
Some(Dynamic::Image(ref img)) => img,
_ => panic!("awawwawwa"),
},
);
None
}
Kind::Math(_) => todo!(),
Kind::Blend(_) => todo!(),
Kind::Noise(_) => todo!(),
Kind::Filter(filter_instruction) => match filter_instruction {
Filter::Invert => Some(Dynamic::Image(instructions::filters::invert::invert(
match input {
Some(Dynamic::Image(img)) => img,
_ => panic!("invalid value type for invert"),
},
))),
},
}
}
}

34
crates/eval/src/lib.rs Normal file
View file

@ -0,0 +1,34 @@
use ir::instruction::Kind;
use value::Dynamic;
mod debug;
mod value;
/// The available executors
/// unused in early dev.
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum RegisteredExecutor {
/// the debug executor is single threaded and really, *really* slow. And unstable. Don't use. Unless you're a dev working on this.
Debug,
}
trait Executor {
fn execute(instruction: Kind, input: Option<Dynamic>) -> Option<Dynamic>;
}
pub fn execute_all(instructions: Vec<Kind>) {
let mut tmp = None;
for instruction in instructions {
tmp = debug::Executor::execute(instruction, tmp);
}
}
// scratchpad lol:
// execution structure:
// 1. take in rpl
// 2. analyse/validate structure against allowed executors
// 3. assign executors to instructions
// 4. optimize
// 5. prepare memory management patterns
// 6. run

View file

@ -0,0 +1,5 @@
use image::DynamicImage;
pub enum Dynamic {
Image(DynamicImage),
}