basic conversion thing do worky!!!
This commit is contained in:
parent
f046393af8
commit
b92977d8f1
13 changed files with 680 additions and 14 deletions
|
@ -6,3 +6,6 @@ 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"
|
||||
rpl = { path = "../rpl" }
|
||||
|
|
1
crates/executor/src/cpu/mod.rs
Normal file
1
crates/executor/src/cpu/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub(crate) struct CpuExecutor;
|
30
crates/executor/src/debug/instructions/mod.rs
Normal file
30
crates/executor/src/debug/instructions/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
pub mod Read {
|
||||
use image::{io::Reader as ImageReader, DynamicImage};
|
||||
use rpl::instructions::read::{Read, SourceType};
|
||||
|
||||
pub fn read(Read { source, format }: Read) -> DynamicImage {
|
||||
let mut 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::{io::Reader as ImageReader, DynamicImage, ImageFormat};
|
||||
use rpl::instructions::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,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
30
crates/executor/src/debug/mod.rs
Normal file
30
crates/executor/src/debug/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use crate::{value::DynamicValue, Executor};
|
||||
mod instructions;
|
||||
|
||||
pub struct DebugExecutor;
|
||||
|
||||
impl Executor for DebugExecutor {
|
||||
fn execute(
|
||||
instruction: rpl::instructions::Instruction,
|
||||
input: Option<DynamicValue>,
|
||||
) -> Option<DynamicValue> {
|
||||
match instruction {
|
||||
rpl::instructions::Instruction::Read(read_instruction) => Some(DynamicValue::Image(
|
||||
instructions::Read::read(read_instruction),
|
||||
)),
|
||||
rpl::instructions::Instruction::Write(write_instruction) => {
|
||||
instructions::Write::write(
|
||||
write_instruction,
|
||||
match input {
|
||||
Some(DynamicValue::Image(img)) => img,
|
||||
_ => panic!("awawwawwa"),
|
||||
},
|
||||
);
|
||||
None
|
||||
}
|
||||
rpl::instructions::Instruction::Math(_) => todo!(),
|
||||
rpl::instructions::Instruction::Blend(_) => todo!(),
|
||||
rpl::instructions::Instruction::Noise(_) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,38 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
use rpl::instructions::Instruction;
|
||||
use value::DynamicValue;
|
||||
|
||||
mod debug;
|
||||
mod value;
|
||||
|
||||
/// The available executors
|
||||
/// unused in early dev.
|
||||
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
|
||||
pub enum Executors {
|
||||
/// the debug executor is single threaded and really, *really* slow. And unstable. Don't use. Unless you're a dev working on this.
|
||||
Debug,
|
||||
/// the CPU executor primarily uses the CPU. Most likely most feature complete, and the fallback.
|
||||
Cpu,
|
||||
/// the Vulkan executor (obviously) uses vulkan. there's a good chance this isn't implemented yet as you're reading this.
|
||||
Vulkan,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
trait Executor {
|
||||
fn execute(instruction: Instruction, input: Option<DynamicValue>) -> Option<DynamicValue>;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
pub fn execute_all(instructions: Vec<Instruction>) {
|
||||
let mut tmp = None;
|
||||
|
||||
for instruction in instructions {
|
||||
tmp = debug::DebugExecutor::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/executor/src/value/mod.rs
Normal file
5
crates/executor/src/value/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use image::DynamicImage;
|
||||
|
||||
pub enum DynamicValue {
|
||||
Image(DynamicImage),
|
||||
}
|
|
@ -6,3 +6,6 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { workspace = true, features = [ "derive" ] }
|
||||
rpl = { path = "../rpl" }
|
||||
executor = { path = "../executor" }
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use executor::{execute_all, Executors};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {
|
||||
file: PathBuf,
|
||||
primary_executor: Executors,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = dbg!(Args::parse());
|
||||
|
||||
let f = fs::read_to_string(args.file).unwrap();
|
||||
let pl = rpl::from_ron(&f);
|
||||
|
||||
execute_all(pl.0);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn from_ron(raw: &str) -> Rpl {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub struct Rpl(Vec<Instruction>);
|
||||
pub struct Rpl(pub Vec<Instruction>);
|
||||
|
||||
#[test]
|
||||
fn test_simple_deserialize() {
|
||||
|
|
3
crates/rpl/src/value/mod.rs
Normal file
3
crates/rpl/src/value/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub enum DynamicValue {
|
||||
Image(DynamicImage),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue