repo: rename executor -> eval
This commit is contained in:
parent
23fadce867
commit
c4207af8da
8 changed files with 3 additions and 3 deletions
14
crates/eval/Cargo.toml
Normal file
14
crates/eval/Cargo.toml
Normal 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
|
1
crates/eval/src/cpu/mod.rs
Normal file
1
crates/eval/src/cpu/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub(crate) struct CpuExecutor;
|
44
crates/eval/src/debug/instructions/mod.rs
Normal file
44
crates/eval/src/debug/instructions/mod.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
37
crates/eval/src/debug/mod.rs
Normal file
37
crates/eval/src/debug/mod.rs
Normal 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
34
crates/eval/src/lib.rs
Normal 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
|
5
crates/eval/src/value/mod.rs
Normal file
5
crates/eval/src/value/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use image::DynamicImage;
|
||||
|
||||
pub enum Dynamic {
|
||||
Image(DynamicImage),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue