Created
April 13, 2026 14:39
-
-
Save xacrimon/e17b186486671c94329b6ac208f82695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro_rules! helpers { | |
| ($instruction:expr, $mc:expr, $thread:expr, $registers:expr, $ip:expr, $handlers:expr) => { | |
| #[allow(unused_macros)] | |
| macro_rules! dispatch { | |
| () => {{ | |
| unsafe { | |
| #[cfg(debug_assertions)] | |
| { | |
| let frame = $thread.frames.last().unwrap_unchecked(); | |
| debug_assert!($ip.offset_from_unsigned(frame.closure.proto.code.as_ptr()) < frame.closure.proto.code.len()); | |
| } | |
| let _ = $instruction; | |
| let instruction = *$ip; | |
| let pos = instruction.discriminant() as usize; | |
| debug_assert!(pos < handler_array!('static).len()); | |
| let handler = *$handlers.cast::<Handler<'gc>>().add(pos); | |
| let ip = $ip.add(1); | |
| become handler(instruction, $mc, $thread, $registers, ip, $handlers); | |
| } | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! args { | |
| ($$kind:path { $$($$field:ident),* }) => {{ | |
| match $instruction { | |
| $$kind { $$($$field),* } => ( $$($$field),* ), | |
| _ => unsafe { std::hint::unreachable_unchecked() }, | |
| } | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! raise { | |
| () => {{ | |
| become impl_error($instruction, $mc, $thread, $registers, $ip, $handlers); | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! check { | |
| ($$cond:expr) => {{ | |
| if std::hint::unlikely(!$$cond) { | |
| raise!(); | |
| } | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! reg { | |
| ($$idx:expr) => {{ | |
| #[cfg(debug_assertions)] | |
| { | |
| $registers[$$idx as usize] | |
| } | |
| #[cfg(not(debug_assertions))] | |
| unsafe { | |
| $registers.add($$idx as usize).read() | |
| } | |
| }}; | |
| (mut $$idx:expr) => {{ | |
| #[cfg(debug_assertions)] | |
| { | |
| &mut $registers[$$idx as usize] | |
| } | |
| #[cfg(not(debug_assertions))] | |
| unsafe { | |
| &mut *$registers.add($$idx as usize) | |
| } | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! constant { | |
| ($$idx:expr) => {{ | |
| let frame = $thread.frames.last().unwrap(); | |
| frame.closure.proto.constants[$$idx as usize] | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! upvalue { | |
| ($$idx:expr) => {{ | |
| let frame = $thread.frames.last().unwrap(); | |
| frame.closure.upvalues[$$idx as usize] | |
| }}; | |
| } | |
| #[allow(unused_macros)] | |
| macro_rules! skip { | |
| () => {{ | |
| $ip = unsafe { $ip.add(1) }; | |
| }}; | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment