Compare commits

..

2 commits

Author SHA1 Message Date
2c147fd77b
docs: fix typo 2024-01-18 20:10:50 +01:00
7994cd4f2b
feat(ir): replace Rpl with GraphIr
Semi-broken as atm the CLI just does nothing except printing the parsed
IR, instead of actually executing it.
2024-01-18 20:10:13 +01:00
8 changed files with 29 additions and 26 deletions

18
Cargo.lock generated
View file

@ -161,6 +161,15 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"clap",
"executor",
"ir",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@ -419,15 +428,6 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "pl-cli"
version = "0.1.0"
dependencies = [
"clap",
"executor",
"ir",
]
[[package]]
name = "png"
version = "0.17.10"

View file

@ -1,5 +1,5 @@
[package]
name = "pl-cli"
name = "cli"
version = "0.1.0"
edition = "2021"

View file

@ -1,7 +1,7 @@
use std::{fs, path::PathBuf};
use clap::Parser;
use executor::{execute_all, Executors};
use executor::Executors;
#[derive(Parser, Debug)]
pub struct Args {
@ -16,5 +16,5 @@ fn main() {
.expect("reading IR failed — come back to this later handle errors properly");
let pl = ir::from_ron(&f).expect("handle me properly");
execute_all(pl);
dbg!(pl);
}

View file

@ -1,6 +1,6 @@
pub mod read {
use image::{io::Reader as ImageReader, DynamicImage};
use rpl::instructions::read::{Read, SourceType};
use ir::instruction::read::{Read, SourceType};
pub fn read(Read { source, .. }: Read) -> DynamicImage {
// TODO: actual error handling
@ -15,7 +15,7 @@ pub mod read {
pub mod write {
use image::{DynamicImage, ImageFormat};
use rpl::instructions::write::{TargetFormat, TargetType, Write};
use ir::instruction::write::{TargetFormat, TargetType, Write};
pub fn write(Write { target, format }: Write, input_data: &DynamicImage) {
input_data

View file

@ -1,4 +1,4 @@
use rpl::instructions::{Filter, Instruction};
use ir::instruction::{Filter, Kind};
use crate::value::Dynamic;
mod instructions;
@ -6,12 +6,12 @@ mod instructions;
pub struct Executor;
impl crate::Executor for Executor {
fn execute(instruction: Instruction, input: Option<Dynamic>) -> Option<Dynamic> {
fn execute(instruction: Kind, input: Option<Dynamic>) -> Option<Dynamic> {
match instruction {
Instruction::Read(read_instruction) => {
Kind::Read(read_instruction) => {
Some(Dynamic::Image(instructions::read::read(read_instruction)))
}
Instruction::Write(write_instruction) => {
Kind::Write(write_instruction) => {
instructions::write::write(
write_instruction,
match input {
@ -21,10 +21,10 @@ impl crate::Executor for Executor {
);
None
}
Instruction::Math(_) => todo!(),
Instruction::Blend(_) => todo!(),
Instruction::Noise(_) => todo!(),
Instruction::Filter(filter_instruction) => match filter_instruction {
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,

View file

@ -1,4 +1,4 @@
use rpl::instructions::Instruction;
use ir::instruction::Kind;
use value::Dynamic;
mod debug;
@ -17,10 +17,10 @@ pub enum Executors {
}
trait Executor {
fn execute(instruction: Instruction, input: Option<Dynamic>) -> Option<Dynamic>;
fn execute(instruction: Kind, input: Option<Dynamic>) -> Option<Dynamic>;
}
pub fn execute_all(instructions: Vec<Instruction>) {
pub fn execute_all(instructions: Vec<Kind>) {
let mut tmp = None;
for instruction in instructions {

View file

@ -7,6 +7,9 @@ pub mod instruction;
pub type Map<K, V> = ahash::AHashMap<K, V>;
pub type Set<V> = ahash::AHashSet<V>;
/// # Errors
///
/// Returns an error if the parsed source is not a valid graph IR.
pub fn from_ron(source: &str) -> ron::error::SpannedResult<GraphIr> {
ron::from_str(source)
}

View file

@ -40,7 +40,7 @@
just nushell
typst typst-lsp
mold
cargo-nextest
cargo-nextest cargo-watch
];
})
];