58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
|
use std::mem;
|
||
|
|
||
|
use ir::{
|
||
|
instruction::{Filter, Kind},
|
||
|
GraphIr, Instruction, InstructionRef,
|
||
|
};
|
||
|
|
||
|
use crate::value::Dynamic;
|
||
|
mod instr;
|
||
|
|
||
|
#[derive(Debug, Default)]
|
||
|
pub struct Evaluator {
|
||
|
ir: GraphIr,
|
||
|
}
|
||
|
|
||
|
impl crate::Evaluator for Evaluator {
|
||
|
fn feed(&mut self, ir: GraphIr) {
|
||
|
// TODO: should add instead of replace, see note in Evaluator trait above this method
|
||
|
self.ir = ir;
|
||
|
}
|
||
|
|
||
|
fn eval_full(&mut self) {
|
||
|
let queue: Vec<Instruction> = self
|
||
|
.ir
|
||
|
.topological_sort()
|
||
|
.into_iter()
|
||
|
.map(Into::into)
|
||
|
.collect();
|
||
|
for instr in queue {
|
||
|
self.step(instr);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Evaluator {
|
||
|
#[allow(clippy::needless_pass_by_value)]
|
||
|
fn step(&mut self, instr: Instruction) {
|
||
|
let _ = match instr.kind {
|
||
|
Kind::Read(details) => Some(Dynamic::Image(instr::read::read(details))),
|
||
|
Kind::Write(details) => {
|
||
|
instr::write::write(details, todo!());
|
||
|
None
|
||
|
}
|
||
|
Kind::Math(_) => todo!(),
|
||
|
Kind::Blend(_) => todo!(),
|
||
|
Kind::Noise(_) => todo!(),
|
||
|
Kind::Filter(filter_instruction) => match filter_instruction {
|
||
|
Filter::Invert => Some(Dynamic::Image(instr::filters::invert::invert(
|
||
|
match todo!() {
|
||
|
Some(Dynamic::Image(img)) => img,
|
||
|
_ => panic!("invalid value type for invert"),
|
||
|
},
|
||
|
))),
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
}
|