summaryrefslogtreecommitdiff
path: root/crates/parser/src/macros.rs
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-07-14 20:48:18 +0200
committerHenry <mail@henrygressmann.de>2026-07-14 20:48:18 +0200
commitdc366165b8cd0f8c43cfe7017cb37f0a16887d6d (patch)
treea0e9eeba6211fe9fddde96547a6338aca79d7c3f /crates/parser/src/macros.rs
parentfe43e4816efbf622e8cdc106a552dfb9aadfb80e (diff)
chore: simplify runtime, parser, types, and SIMD internals
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser/src/macros.rs')
-rw-r--r--crates/parser/src/macros.rs65
1 files changed, 11 insertions, 54 deletions
diff --git a/crates/parser/src/macros.rs b/crates/parser/src/macros.rs
index b21c1e8..8a5330a 100644
--- a/crates/parser/src/macros.rs
+++ b/crates/parser/src/macros.rs
@@ -105,61 +105,18 @@ pub(crate) mod visit {
pub(crate) mod optimize {
macro_rules! replace {
- ($instructions:ident, $read:ident, 1 => [$a:expr $(,)?]) => {{
- $instructions[$read - 1] = Instruction::Nop;
- $instructions[$read] = $a;
- }};
- ($instructions:ident, $read:ident, 1 => [$a:expr, $b:expr $(,)?]) => {{
- $instructions[$read - 1] = $a;
- $instructions[$read] = $b;
- }};
- ($instructions:ident, $read:ident, 2 => [$a:expr $(,)?]) => {{
- $instructions[$read - 2] = Instruction::Nop;
- $instructions[$read - 1] = Instruction::Nop;
- $instructions[$read] = $a;
- }};
- ($instructions:ident, $read:ident, 2 => [$a:expr, $b:expr $(,)?]) => {{
- $instructions[$read - 2] = Instruction::Nop;
- $instructions[$read - 1] = $a;
- $instructions[$read] = $b;
- }};
- ($instructions:ident, $read:ident, 2 => [$a:expr, $b:expr, $c:expr $(,)?]) => {{
- $instructions[$read - 2] = $a;
- $instructions[$read - 1] = $b;
- $instructions[$read] = $c;
- }};
- ($instructions:ident, $read:ident, 3 => [$a:expr $(,)?]) => {{
- $instructions[$read - 3] = Instruction::Nop;
- $instructions[$read - 2] = Instruction::Nop;
- $instructions[$read - 1] = Instruction::Nop;
- $instructions[$read] = $a;
- }};
- ($instructions:ident, $read:ident, 3 => [$a:expr, $b:expr $(,)?]) => {{
- $instructions[$read - 3] = Instruction::Nop;
- $instructions[$read - 2] = Instruction::Nop;
- $instructions[$read - 1] = $a;
- $instructions[$read] = $b;
- }};
- ($instructions:ident, $read:ident, 3 => [$a:expr, $b:expr, $c:expr $(,)?]) => {{
- $instructions[$read - 3] = Instruction::Nop;
- $instructions[$read - 2] = $a;
- $instructions[$read - 1] = $b;
- $instructions[$read] = $c;
- }};
- ($instructions:ident, $read:ident, 3 => [$a:expr, $b:expr, $c:expr, $d:expr $(,)?]) => {{
- $instructions[$read - 3] = $a;
- $instructions[$read - 2] = $b;
- $instructions[$read - 1] = $c;
- $instructions[$read] = $d;
+ ($instructions:ident, $read:ident, $consumed:literal => [$($out:expr),+ $(,)?]) => {{
+ const {
+ assert!($consumed >= 1 && $consumed <= 3);
+ assert!([$(stringify!($out)),+].len() <= $consumed + 1);
+ }
+ let replacements = [$($out),+];
+ let replacement_start = $read + 1 - replacements.len();
+ $instructions[$read - $consumed..replacement_start].fill(Instruction::Nop);
+ $instructions[replacement_start..=$read].copy_from_slice(&replacements);
}};
- ($instructions:ident, $read:ident, 1 => $out:expr) => {
- replace!($instructions, $read, 1 => [$out]);
- };
- ($instructions:ident, $read:ident, 2 => $out:expr) => {
- replace!($instructions, $read, 2 => [$out]);
- };
- ($instructions:ident, $read:ident, 3 => $out:expr) => {
- replace!($instructions, $read, 3 => [$out]);
+ ($instructions:ident, $read:ident, $consumed:literal => $out:expr) => {
+ replace!($instructions, $read, $consumed => [$out]);
};
}