|
| 1 | +macro_rules! invoke_fn_impl { |
| 2 | + ($( |
| 3 | + fn $FnName:ident($($Arg:tt: $T:ident),*); |
| 4 | + )+) => { |
| 5 | + $( |
| 6 | + impl MunRuntime { |
| 7 | + /// Invokes the method `method_name` with arguments `args`, in the library compiled based on |
| 8 | + /// the manifest at `manifest_path`. |
| 9 | + /// |
| 10 | + /// If an error occurs when invoking the method, an error message is logged. The runtime |
| 11 | + /// continues looping until the cause of the error has been resolved. |
| 12 | + pub fn $FnName<$($T: Reflection,)* Output: Reflection>( |
| 13 | + &mut self, |
| 14 | + function_name: &str, |
| 15 | + $($Arg: $T,)* |
| 16 | + ) -> Output { |
| 17 | + // Initialize `updated` to `true` to guarantee the method is run at least once |
| 18 | + let mut updated = true; |
| 19 | + loop { |
| 20 | + if updated { |
| 21 | + let function: core::result::Result<fn($($T),*) -> Output, String> = self |
| 22 | + .get_function_info(function_name) |
| 23 | + .ok_or(format!("Failed to obtain function '{}'", function_name)) |
| 24 | + .and_then(|function| mun_abi::downcast_fn!(function, fn($($T),*) -> Output)); |
| 25 | + |
| 26 | + match function { |
| 27 | + Ok(function) => return function($($Arg),*), |
| 28 | + Err(ref e) => { |
| 29 | + eprintln!("{}", e); |
| 30 | + updated = false; |
| 31 | + } |
| 32 | + } |
| 33 | + } else { |
| 34 | + updated = self.update(); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + )+ |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +#[macro_export] |
| 44 | +macro_rules! invoke_fn { |
| 45 | + ($Runtime:expr, $FnName:expr) => { |
| 46 | + $Runtime.invoke_fn0($FnName) |
| 47 | + }; |
| 48 | + ($Runtime:expr, $FnName:expr, $A:expr) => { |
| 49 | + $Runtime.invoke_fn1($FnName, $A) |
| 50 | + }; |
| 51 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr) => { |
| 52 | + $Runtime.invoke_fn2($FnName, $A, $B) |
| 53 | + }; |
| 54 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr) => { |
| 55 | + $Runtime.invoke_fn3($FnName, $A, $B, $C) |
| 56 | + }; |
| 57 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr) => { |
| 58 | + $Runtime.invoke_fn4($FnName, $A, $B, $C, $D) |
| 59 | + }; |
| 60 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr) => { |
| 61 | + $Runtime.invoke_fn5($FnName, $A, $B, $C, $D, $E) |
| 62 | + }; |
| 63 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr) => { |
| 64 | + $Runtime.invoke_fn6($FnName, $A, $B, $C, $D, $E, $F) |
| 65 | + }; |
| 66 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr) => { |
| 67 | + $Runtime.invoke_fn7($FnName, $A, $B, $C, $D, $E, $F, $G) |
| 68 | + }; |
| 69 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr, $H:expr) => { |
| 70 | + $Runtime.invoke_fn8($FnName, $A, $B, $C, $D, $E, $F, $G, $H) |
| 71 | + }; |
| 72 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr, $H:expr, $I:expr) => { |
| 73 | + $Runtime.invoke_fn9($FnName, $A, $B, $C, $D, $E, $F, $G, $H, $I) |
| 74 | + }; |
| 75 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr, $H:expr, $I:expr, $J:expr) => { |
| 76 | + $Runtime.invoke_fn10($FnName, $A, $B, $C, $D, $E, $F, $G, $H, $I, $J) |
| 77 | + }; |
| 78 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr, $H:expr, $I:expr, $J:expr, $K:expr) => { |
| 79 | + $Runtime.invoke_fn11($FnName, $A, $B, $C, $D, $E, $F, $G, $H, $I, $J, $K) |
| 80 | + }; |
| 81 | + ($Runtime:expr, $FnName:expr, $A:expr, $B:expr, $C:expr, $D:expr, $E:expr, $F:expr, $G:expr, $H:expr, $I:expr, $J:expr, $K:expr, $L:expr) => { |
| 82 | + $Runtime.invoke_fn12($FnName, $A, $B, $C, $D, $E, $F, $G, $H, $I, $J, $K, $L) |
| 83 | + }; |
| 84 | +} |
0 commit comments