You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wanted to get thoughts on adding a JitFn wrapper to make ExecutionEngine calls easier.
Pseudo(-ish) code example:
// Based on inkwells JitFn// https://github.com/TheDan64/inkwell/blob/master/src/execution_engine.rs#L508pubstructJitFn<'a,F>{engine:&'a ExecutionEngine,inner:F,}impl<'a,F>JitFn<'a,F>whereF:UnsafeFunctionPointer,{fnnew(engine:&'a ExecutionEngine,func_name:&str) -> Result<Self,LookupError>{let address = engine.lookup(func_name);if address.is_null(){Err(LookupError::new(func_name))}else{let inner = unsafe{transmute_copy(&address)};Ok(Self{ engine, inner })}}}/// Marker trait representing an unsafe function pointer (`unsafe extern "C" fn(A, B, ...) -> Output`).pubtraitUnsafeFunctionPointer: private::SealedUnsafeFunctionPointer{}impl<F: private::SealedUnsafeFunctionPointer>UnsafeFunctionPointerforF{}mod private {/// A sealed trait which ensures nobody outside this crate can implement/// `UnsafeFunctionPointer`.////// See https://rust-lang-nursery.github.io/api-guidelines/future-proofing.htmlpubtraitSealedUnsafeFunctionPointer:Copy{}}macro_rules! impl_unsafe_fn {(@recurse $first:ident $(, $rest:ident )*) => {
impl_unsafe_fn!($( $rest ),*);};(@recurse) => {};($( $param:ident ),*) => {impl<Output, $( $param ),*> private::SealedUnsafeFunctionPointerforunsafe extern "C"fn($( $param ),*) -> Output{}impl<'a,Output, $( $param ),*> JitFunction<'a,unsafe extern "C"fn($( $param ),*) -> Output> {
#[allow(non_snake_case)]
#[inline(always)]pubunsafefn call(&self, $(mut $param: $param ),*) -> Output{(self.inner)($( $param ),*)}}
impl_unsafe_fn!(@recurse $( $param ),*);};}// Recursively implement the trait for each parameter countimpl_unsafe_fn!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P);
The text was updated successfully, but these errors were encountered:
BadBastion
changed the title
[Feature request] wrapper(s) for callable JIT functions.
[Feature request] Wrapper type for callable JIT functions.
Mar 14, 2024
Wanted to get thoughts on adding a JitFn wrapper to make ExecutionEngine calls easier.
Pseudo(-ish) code example:
The text was updated successfully, but these errors were encountered: