@@ -59,7 +59,7 @@ pub trait ExecutionEngine<'a>:'a + Sized + DisposeRef where LLVMExecutionEngineR
59
59
///
60
60
/// To convert the arguments to `GenericValue`s, you should use the `GenericValueCast::to_generic` method.
61
61
/// To convert the return value from a `GenericValue`, you should use the `GenericValueCast::from_generic` method.
62
- fn run_function ( & ' a self , function : & ' a Function , args : & [ GenericValue < ' a > ] ) -> GenericValue < ' a > {
62
+ fn run_function ( & ' a self , function : & ' a Function , args : & [ & ' a GenericValue ] ) -> & ' a GenericValue {
63
63
let ptr = args. as_ptr ( ) as * mut LLVMGenericValueRef ;
64
64
unsafe { engine:: LLVMRunFunction ( self . into ( ) , function. into ( ) , args. len ( ) as c_uint , ptr) . into ( ) }
65
65
}
@@ -164,16 +164,6 @@ impl<'a> ExecutionEngine<'a> for JitEngine {
164
164
pub struct Interpreter ( PhantomData < [ u8 ] > ) ;
165
165
native_ref ! { & Interpreter = LLVMExecutionEngineRef }
166
166
dispose ! { Interpreter , LLVMOpaqueExecutionEngine , LLVMDisposeExecutionEngine }
167
- impl < ' a > Interpreter {
168
- /// Run `function` with the arguments given as ``GenericValue`s, then return the result as one.
169
- ///
170
- /// To convert the arguments to `GenericValue`s, you should use the `GenericValueCast::to_generic` method.
171
- /// To convert the return value from a `GenericValue`, you should use the `GenericValueCast::from_generic` method.
172
- pub fn run_function ( & self , function : & ' a Function , args : & [ GenericValue < ' a > ] ) -> GenericValue < ' a > {
173
- let ptr = args. as_ptr ( ) as * mut LLVMGenericValueRef ;
174
- unsafe { engine:: LLVMRunFunction ( self . into ( ) , function. into ( ) , args. len ( ) as c_uint , ptr) . into ( ) }
175
- }
176
- }
177
167
impl < ' a > ExecutionEngine < ' a > for Interpreter {
178
168
type Options = ( ) ;
179
169
fn new ( module : & ' a Module , _: ( ) ) -> Result < CSemiBox < ' a , Interpreter > , CBox < str > > {
@@ -191,52 +181,43 @@ impl<'a> ExecutionEngine<'a> for Interpreter {
191
181
}
192
182
}
193
183
/// A wrapped value that can be passed to an interpreted function or returned from one
194
- pub struct GenericValue < ' a > {
195
- value : LLVMGenericValueRef ,
196
- marker : PhantomData < & ' a ( ) >
197
- }
198
- native_ref ! ( contra GenericValue , value: LLVMGenericValueRef ) ;
199
- impl < ' a > Drop for GenericValue < ' a > {
200
- fn drop ( & mut self ) {
201
- unsafe {
202
- engine:: LLVMDisposeGenericValue ( self . value )
203
- }
204
- }
205
- }
184
+ pub struct GenericValue ( PhantomData < [ u8 ] > ) ;
185
+ native_ref ! { & GenericValue = LLVMGenericValueRef }
186
+ dispose ! { GenericValue , LLVMOpaqueGenericValue , LLVMDisposeGenericValue }
206
187
207
188
/// A value that can be cast into a `GenericValue` and that a `GenericValue` can be cast into.
208
189
///
209
190
/// Both these methods require contexts because some `Type` constructors are needed for the
210
191
/// conversion and these constructors need a context.
211
- pub trait GenericValueCast < ' a > {
192
+ pub trait GenericValueCast {
212
193
/// Create a `GenericValue` from this value.
213
- fn to_generic ( self , context : & ' a Context ) -> GenericValue < ' a > ;
194
+ fn to_generic ( self , context : & Context ) -> CSemiBox < GenericValue > ;
214
195
/// Convert the `GenericValue` into a value of this type again.
215
- fn from_generic ( value : GenericValue < ' a > , context : & ' a Context ) -> Self ;
196
+ fn from_generic ( value : & GenericValue , context : & Context ) -> Self ;
216
197
}
217
198
218
- impl < ' a > GenericValueCast < ' a > for f64 {
219
- fn to_generic ( self , ctx : & ' a Context ) -> GenericValue < ' a > {
199
+ impl GenericValueCast for f64 {
200
+ fn to_generic ( self , ctx : & Context ) -> CSemiBox < GenericValue > {
220
201
unsafe {
221
202
let ty = core:: LLVMDoubleTypeInContext ( ctx. into ( ) ) ;
222
- engine:: LLVMCreateGenericValueOfFloat ( ty, self ) . into ( )
203
+ CSemiBox :: new ( engine:: LLVMCreateGenericValueOfFloat ( ty, self ) )
223
204
}
224
205
}
225
- fn from_generic ( value : GenericValue < ' a > , ctx : & ' a Context ) -> f64 {
206
+ fn from_generic ( value : & GenericValue , ctx : & Context ) -> f64 {
226
207
unsafe {
227
208
let ty = core:: LLVMDoubleTypeInContext ( ctx. into ( ) ) ;
228
209
engine:: LLVMGenericValueToFloat ( ty, value. into ( ) )
229
210
}
230
211
}
231
212
}
232
- impl < ' a > GenericValueCast < ' a > for f32 {
233
- fn to_generic ( self , ctx : & ' a Context ) -> GenericValue < ' a > {
213
+ impl GenericValueCast for f32 {
214
+ fn to_generic ( self , ctx : & Context ) -> CSemiBox < GenericValue > {
234
215
unsafe {
235
216
let ty = core:: LLVMFloatTypeInContext ( ctx. into ( ) ) ;
236
- engine:: LLVMCreateGenericValueOfFloat ( ty, self as f64 ) . into ( )
217
+ CSemiBox :: new ( engine:: LLVMCreateGenericValueOfFloat ( ty, self as f64 ) )
237
218
}
238
219
}
239
- fn from_generic ( value : GenericValue < ' a > , ctx : & ' a Context ) -> f32 {
220
+ fn from_generic ( value : & GenericValue , ctx : & Context ) -> f32 {
240
221
unsafe {
241
222
let ty = core:: LLVMFloatTypeInContext ( ctx. into ( ) ) ;
242
223
engine:: LLVMGenericValueToFloat ( ty, value. into ( ) ) as f32
@@ -245,14 +226,14 @@ impl<'a> GenericValueCast<'a> for f32 {
245
226
}
246
227
macro_rules! generic_int(
247
228
( $ty: ty, $signed: expr) => (
248
- impl < ' a> GenericValueCast < ' a> for $ty {
249
- fn to_generic( self , ctx: & ' a Context ) -> GenericValue < ' a > {
229
+ impl GenericValueCast for $ty {
230
+ fn to_generic( self , ctx: & Context ) -> CSemiBox < GenericValue > {
250
231
unsafe {
251
- let ty = <Self as Compile < ' a> >:: get_type( ctx) ;
252
- engine:: LLVMCreateGenericValueOfInt ( ty. into( ) , self as c_ulonglong, $signed as c_int) . into ( )
232
+ let ty = <Self as Compile >:: get_type( ctx) ;
233
+ CSemiBox :: new ( engine:: LLVMCreateGenericValueOfInt ( ty. into( ) , self as c_ulonglong, $signed as c_int) )
253
234
}
254
235
}
255
- fn from_generic( value: GenericValue < ' a> , _: & ' a Context ) -> $ty {
236
+ fn from_generic( value: & GenericValue , _: & Context ) -> $ty {
256
237
unsafe {
257
238
engine:: LLVMGenericValueToInt ( value. into( ) , $signed as c_int) as $ty
258
239
}
@@ -265,14 +246,14 @@ macro_rules! generic_int(
265
246
) ;
266
247
) ;
267
248
268
- impl < ' a > GenericValueCast < ' a > for bool {
269
- fn to_generic ( self , ctx : & ' a Context ) -> GenericValue < ' a > {
249
+ impl GenericValueCast for bool {
250
+ fn to_generic ( self , ctx : & Context ) -> CSemiBox < GenericValue > {
270
251
unsafe {
271
- let ty = <Self as Compile < ' a > >:: get_type ( ctx) ;
272
- engine:: LLVMCreateGenericValueOfInt ( ty. into ( ) , self as c_ulonglong , 0 ) . into ( )
252
+ let ty = <Self as Compile >:: get_type ( ctx) ;
253
+ CSemiBox :: new ( engine:: LLVMCreateGenericValueOfInt ( ty. into ( ) , self as c_ulonglong , 0 ) )
273
254
}
274
255
}
275
- fn from_generic ( value : GenericValue < ' a > , _: & ' a Context ) -> bool {
256
+ fn from_generic ( value : & GenericValue , _: & Context ) -> bool {
276
257
unsafe {
277
258
engine:: LLVMGenericValueToInt ( value. into ( ) , 0 ) != 0
278
259
}
@@ -282,3 +263,4 @@ generic_int!{some i8, u8}
282
263
generic_int ! { some i16 , u16 }
283
264
generic_int ! { some i32 , u32 }
284
265
generic_int ! { some i64 , u64 }
266
+ generic_int ! { some isize , usize }
0 commit comments