mindustry logic execution, map- and schematic- parsing and rendering
add funny colors
| -rw-r--r-- | lemu/Cargo.toml | 3 | ||||
| -rw-r--r-- | lemu/rust-toolchain.toml | 2 | ||||
| -rw-r--r-- | lemu/src/instructions/draw.rs | 2 | ||||
| -rw-r--r-- | lemu/src/lexer.rs | 52 | ||||
| -rw-r--r-- | lemu/src/lib.rs | 1 | ||||
| -rw-r--r-- | lemu/src/main.rs | 1 |
6 files changed, 59 insertions, 2 deletions
diff --git a/lemu/Cargo.toml b/lemu/Cargo.toml index b12e365..bacfdea 100644 --- a/lemu/Cargo.toml +++ b/lemu/Cargo.toml @@ -19,6 +19,9 @@ beef = "0.5" lerr = { version = "0.1.5", optional = true } comat = { version = "0.1.2", optional = true } vecto = "0.1.1" +phf = { version = "0.12.1", features = ["macros"] } +atools = "0.1.7" +car = "0.1.2" [features] debug = ["comat"] diff --git a/lemu/rust-toolchain.toml b/lemu/rust-toolchain.toml new file mode 100644 index 0000000..b67ba8f --- /dev/null +++ b/lemu/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-07-29" diff --git a/lemu/src/instructions/draw.rs b/lemu/src/instructions/draw.rs index db0b52e..1644da0 100644 --- a/lemu/src/instructions/draw.rs +++ b/lemu/src/instructions/draw.rs @@ -1,4 +1,4 @@ -use super::{get_num, Flow, LInstruction}; +use super::{Flow, LInstruction, get_num}; use crate::{ debug::{info::DebugInfo, printable::Printable}, executor::{Display, DisplayState, ExecutorContext}, diff --git a/lemu/src/lexer.rs b/lemu/src/lexer.rs index f7a5b3d..3552101 100644 --- a/lemu/src/lexer.rs +++ b/lemu/src/lexer.rs @@ -1,4 +1,6 @@ +use atools::prelude::*; use beef::lean::Cow; +use fimg::Pack; use logos::{Lexer as RealLexer, Logos, Span}; macro_rules! instrs { @@ -16,12 +18,22 @@ macro_rules! instrs { #[regex(r#"0[xX][0-9a-fA-F]+"#, |lex| u64::from_str_radix(&lex.slice()[2..], 16).map(|v| v as f64).ok())] #[regex(r#"0[bB][01]+"#, |lex| u64::from_str_radix(&lex.slice()[2..], 2).map(|v| v as f64).ok())] #[regex(r#""[0-9]+(\.[0-9]+)?""#, callback = |lex| lex.slice()[1..lex.slice().len()-1].parse().ok(), priority = 13)] + #[regex(r#"%\[([a-z]+)\]"#, |lex| COLORS.get(dbg!(&lex.slice()[2..lex.slice().len()-1])).copied().unwrap_or_default().join(255).pack() as f64)] + #[regex(r#"%[0-9a-fA-F]+"#, callback = |lex| { + let mut x = lex.slice()[1..].bytes() + .map(|b| (b & 0xF) + 9 * (b >> 6)) + .array_chunks::<2>() + .map(|[a, b]| a * 16 + b); + if lex.slice()[1..].len() == 6 { x.carr::<3>().join(255) } + else if lex.slice()[1..].len() == 8 { x.carr::<4>() } + else { [255; 4] }.pack() as f64 + })] Num(f64), // TODO have bool and integer tokens, and parser converts #[regex(r#""([^\\"\n])*""#, callback = |lex| Cow::from(&lex.slice()[1..lex.slice().len()-1]), priority = 12)] #[regex(r#"@[^ "\n]*"#, |lex| Cow::from(lex.slice()))] #[regex(r#""[^"]*""#, callback = |lex| Cow::from(lex.slice()[1..lex.slice().len()-1].replace(r"\n", "\n")), priority = 8)] String(Cow<'strings, str>), - #[regex("[^@0-9- \t\n][^ \t\n]*", priority = 7)] + #[regex("[^@%0-9- \t\n][^ \t\n]*", priority = 7)] Ident(&'strings str), $(#[token($z, priority = 8)] $v,)+ @@ -162,3 +174,41 @@ fn lexer() { Num(4), ]; } + +const COLORS: phf::Map<&str, [u8; 3]> = phf::phf_map! { + "clear" => [0, 0, 0], + "black" => [0, 0, 0], + "white" => [255, 255, 255], + "lightgray" => [191, 191, 191], + "gray" => [127, 127, 127], + "darkgray" => [63, 63, 63], + "blue" => [0, 0, 255], + "navy" => [0, 0, 128], + "royal" => [65, 105, 225], + "slate" => [112, 128, 144], + "sky" => [135, 206, 235], + "cyan" => [0, 255, 255], + "teal" => [0, 128, 128], + "green" => [0, 255, 0], + "acid" => [127, 255, 0], + "lime" => [50, 205, 50], + "forest" => [34, 139, 34], + "olive" => [107, 142, 35], + "yellow" => [255, 255, 0], + "gold" => [255, 215, 0], + "goldenrod" => [218, 165, 32], + "orange" => [255, 165, 0], + "brown" => [139, 69, 19], + "tan" => [210, 180, 140], + "brick" => [178, 34, 34], + "red" => [255, 0, 0], + "scarlet" => [255, 52, 28], + "coral" => [255, 127, 80], + "salmon" => [250, 128, 114], + "pink" => [255, 105, 180], + "magenta" => [255, 0, 255], + "purple" => [160, 32, 240], + "violet" => [238, 130, 238], + "maroon" => [176, 48, 96], + "accent" => [255, 211, 127], +}; diff --git a/lemu/src/lib.rs b/lemu/src/lib.rs index ce81f1d..25d571b 100644 --- a/lemu/src/lib.rs +++ b/lemu/src/lib.rs @@ -2,6 +2,7 @@ #![allow(clippy::redundant_closure_call)] // yeah so like well you see i kinda well kinda have to yes but sorta #![allow(clippy::fn_address_comparisons)] +#![feature(generic_const_exprs, iter_array_chunks)] #![warn( clippy::multiple_unsafe_ops_per_block, clippy::missing_const_for_fn, diff --git a/lemu/src/main.rs b/lemu/src/main.rs index bbb45b4..2be36c8 100644 --- a/lemu/src/main.rs +++ b/lemu/src/main.rs @@ -20,6 +20,7 @@ fn main() -> ExitCode { return ExitCode::FAILURE; } }; + println!("{lex}"); lex.run(); dbg!(lex.instructions_ran); let Output { displays, .. } = lex.output(); |