summaryrefslogtreecommitdiff
path: root/crates/parser/src/macros.rs
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-05-04 19:25:22 +0200
committerHenry <mail@henrygressmann.de>2026-05-04 19:25:22 +0200
commitc0b356b025ef93eb3c1378c203858c3a7486f398 (patch)
tree2051cd39b455351c54d7c0ea5e608b22d98de5ab /crates/parser/src/macros.rs
parent2aa1f31106b9c95500633f5bd9d5f041d408d3e3 (diff)
chore: simplify parser & reduce allocations
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser/src/macros.rs')
-rw-r--r--crates/parser/src/macros.rs87
1 files changed, 6 insertions, 81 deletions
diff --git a/crates/parser/src/macros.rs b/crates/parser/src/macros.rs
index dded6d8..b21c1e8 100644
--- a/crates/parser/src/macros.rs
+++ b/crates/parser/src/macros.rs
@@ -1,94 +1,19 @@
pub(crate) mod visit {
macro_rules! validate_then_visit {
- ($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*))*) => {
- $(validate_then_visit!(@@$proposal $op $({ $($arg: $argty),* })? => $visit ($($ann)*));)*
- };
-
- // These special-case arms exist so we only clone wasmparser's non-Copy payloads
- (@@mvp BrTable { $arg:ident: $argty:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, $arg: $argty) -> Self::Output {
- self.0.$visit($arg.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit($arg);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@reference_types TypedSelectMulti { $arg:ident: $argty:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, $arg: $argty) -> Self::Output {
- self.0.$visit($arg.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit($arg);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@exceptions TryTable { $arg:ident: $argty:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, $arg: $argty) -> Self::Output {
- self.0.$visit($arg.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit($arg);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@stack_switching Resume { cont_type_index: $cont:ty, resume_table: $table:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, cont_type_index: $cont, resume_table: $table) -> Self::Output {
- self.0.$visit(cont_type_index, resume_table.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit(cont_type_index, resume_table);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@stack_switching ResumeThrow { cont_type_index: $cont:ty, tag_index: $tag:ty, resume_table: $table:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, cont_type_index: $cont, tag_index: $tag, resume_table: $table) -> Self::Output {
- self.0.$visit(cont_type_index, tag_index, resume_table.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit(cont_type_index, tag_index, resume_table);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@stack_switching ResumeThrowRef { cont_type_index: $cont:ty, resume_table: $table:ty } => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self, cont_type_index: $cont, resume_table: $table) -> Self::Output {
- self.0.$visit(cont_type_index, resume_table.clone());
- let validation = self.0.validator.visitor(self.0.position).$visit(cont_type_index, resume_table);
- if let Err(e) = validation {
- cold_path();
- self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
- }
- }
- };
-
- (@@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*)) => {
+ ($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*))*) => {$(
fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
- self.0.$visit($($($arg),*)?);
+ self.0.$visit($($($arg.clone()),*)?);
let validation = self.0.validator.visitor(self.0.position).$visit($($($arg),*)?);
if let Err(e) = validation {
cold_path();
self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
}
}
- };
+ )*};
}
macro_rules! validate_then_visit_simd {
- ($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*))*) => {
- $(validate_then_visit_simd!(@@$proposal $op $({ $($arg: $argty),* })? => $visit ($($ann)*));)*
- };
-
- (@@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*)) => {
+ ($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*))*) => {$(
fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
self.0.$visit($($($arg),*)?);
let validation = self.0.validator.simd_visitor(self.0.position).$visit($($($arg),*)?);
@@ -97,7 +22,7 @@ pub(crate) mod visit {
self.0.record_error(crate::ParseError::ParseError { message: e.to_string(), offset: self.0.position });
}
}
- };
+ )*};
}
macro_rules! define_operand {
@@ -166,7 +91,7 @@ pub(crate) mod visit {
(@@tail_call $($rest:tt)* ) => {};
(@@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident ($($ann:tt)*)) => {
- fn $visit(&mut self $($(,_: $argty)*)?) {
+ fn $visit(&mut self $($(,_: $argty)*)?) -> Self::Output {
self.unsupported(stringify!($visit))
}
};