yet another attempt at building an evaluator

This commit is contained in:
Schrottkatze 2024-10-10 10:23:54 +02:00
parent 3412eb9395
commit a693b57447
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
3 changed files with 783 additions and 11 deletions

View file

@ -4,6 +4,10 @@ version = "0.1.0"
edition = "2021"
[dependencies]
image = "0.25.1"
indexmap = "2.2.6"
nalgebra = "0.33.0"
petgraph.workspace = true
[lints]
workspace = true

View file

@ -1,14 +1,128 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
use indexmap::IndexMap;
use instructions::Instruction;
use petgraph::graph::DiGraph;
use types::Type;
trait Node {
fn inputs() -> IndexMap<String, Type>;
fn outputs() -> IndexMap<String, Type>;
}
#[cfg(test)]
mod tests {
use super::*;
struct NodeGraph {
graph: DiGraph<Instruction, TypedEdge>,
}
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
struct TypedEdge {
from: String,
to: String,
typ: Type,
}
mod instructions {
//! This is the lowest level of the IR, the one the executor will use.
use std::path::Path;
use indexmap::{indexmap, IndexMap};
pub enum Instruction {
// File handling
LoadFile,
SaveFile,
ColorMatrix,
PosMatrix,
Blend,
SplitChannels,
}
impl Instruction {
fn inputs(&self) -> IndexMap<String, Type> {
match self {
Instruction::LoadFile => indexmap! {
"path" => Type::Path
},
Instruction::SaveFile => indexmap! {
"path" => Type::Path
},
Instruction::ColorMatrix => indexmap! {
"image" => Type::ImageData,
"matrix" => Type::Mat(4,5)
},
Instruction::PosMatrix => indexmap! {
"image" => Type::ImageData,
"matrix" => Type::Mat(2, 3),
},
Instruction::Blend => todo!(),
Instruction::SplitChannels => todo!(),
}
}
fn outputs(&self) -> IndexMap<String, Type> {
match self {
Instruction::LoadFile => indexmap! {
"image" => Type::ImageData
},
Instruction::SaveFile => indexmap! {},
Instruction::ColorMatrix => indexmap! {
"resut" => Type::ImageData
},
Instruction::PosMatrix => todo!(),
Instruction::Blend => todo!(),
Instruction::SplitChannels => todo!(),
}
}
}
}
mod types {
pub enum Type {
// TODO: later do lower level type system for this stuff?
// Image(Size, PixelType),
// // image data for processing.
// // always PixelType::Rgba32F
// ImageData(Size),
// // stuff that's still to be generated, not sized and no pixeltype
// ProceduralImage,
ImageData,
Text,
Integer,
Float,
Double,
Path,
Bool,
Vec(
// length,
u8,
),
Mat(
// Rows
u8,
// Columns
u8,
),
}
// pub struct Size {
// width: u16,
// height: u16,
// }
// Pixel types. Taken from variants [here](https://docs.rs/image/latest/image/pub enum.DynamicImage.html).
// pub enum PixelType {
// Luma8,
// LumaA8,
// Rgb8,
// Rgba8,
// Luma16,
// LumaA16,
// Rgb16,
// Rgba16,
// Rgb32F,
// #[default]
// Rgba32F,
// }
}