Skip to content

Commit 761fa4a

Browse files
committed
Simplify emit macro
1 parent 1a5c72b commit 761fa4a

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

crates/codegen/src/compile.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -274,33 +274,25 @@ pub fn compile_expression(
274274
Ok(code)
275275
}
276276

277-
// TODO: Unify Real and Pseudo arms
278277
macro_rules! emit {
279-
// Real
280-
($c:expr, RealInstruction::$op:ident { $arg:ident$(,)? }$(,)?) => {
281-
$c.emit_arg($arg, |x| RealInstruction::$op { $arg: x })
278+
// Struct variant with single identifier (e.g., Foo::A { arg })
279+
($c:expr, $enum:ident :: $op:ident { $arg:ident $(,)? } $(,)?) => {
280+
$c.emit_arg($arg, |x| $enum::$op { $arg: x })
282281
};
283-
($c:expr, RealInstruction::$op:ident { $arg:ident : $arg_val:expr $(,)? }$(,)?) => {
284-
$c.emit_arg($arg_val, |x| RealInstruction::$op { $arg: x })
285-
};
286-
($c:expr, RealInstruction::$op:ident( $arg_val:expr $(,)? )$(,)?) => {
287-
$c.emit_arg($arg_val, RealInstruction::$op)
288-
};
289-
($c:expr, RealInstruction::$op:ident$(,)?) => {
290-
$c.emit_no_arg(RealInstruction::$op)
291-
};
292-
// Pseudo
293-
($c:expr, PseudoInstruction::$op:ident { $arg:ident$(,)? }$(,)?) => {
294-
$c.emit_arg($arg, |x| PseudoInstruction::$op { $arg: x })
295-
};
296-
($c:expr, PseudoInstruction::$op:ident { $arg:ident : $arg_val:expr $(,)? }$(,)?) => {
297-
$c.emit_arg($arg_val, |x| PseudoInstruction::$op { $arg: x })
282+
283+
// Struct variant with explicit value (e.g., Foo::A { arg: 42 })
284+
($c:expr, $enum:ident :: $op:ident { $arg:ident : $arg_val:expr $(,)? } $(,)?) => {
285+
$c.emit_arg($arg_val, |x| $enum::$op { $arg: x })
298286
};
299-
($c:expr, PseudoInstruction::$op:ident( $arg_val:expr $(,)? )$(,)?) => {
300-
$c.emit_arg($arg_val, PseudoInstruction::$op)
287+
288+
// Tuple variant (e.g., Foo::B(42))
289+
($c:expr, $enum:ident :: $op:ident($arg_val:expr $(,)? ) $(,)?) => {
290+
$c.emit_arg($arg_val, $enum::$op)
301291
};
302-
($c:expr, PseudoInstruction::$op:ident$(,)?) => {
303-
$c.emit_no_arg(PseudoInstruction::$op)
292+
293+
// No-arg variant (e.g., Foo::C)
294+
($c:expr, $enum:ident :: $op:ident $(,)?) => {
295+
$c.emit_no_arg($enum::$op)
304296
};
305297
}
306298

0 commit comments

Comments
 (0)