(&mut self, val: JitValue)
| 326 | } |
| 327 | |
| 328 | fn return_value(&mut self, val: JitValue) -> Result<(), JitCompileError> { |
| 329 | if let Some(ref ty) = self.sig.ret { |
| 330 | // If the signature has a return type, enforce it |
| 331 | if val.to_jit_type().as_ref() != Some(ty) { |
| 332 | return Err(JitCompileError::NotSupported); |
| 333 | } |
| 334 | } else { |
| 335 | // First time we see a return, define it in the signature |
| 336 | let ty = val.to_jit_type().ok_or(JitCompileError::NotSupported)?; |
| 337 | self.sig.ret = Some(ty.clone()); |
| 338 | self.builder |
| 339 | .func |
| 340 | .signature |
| 341 | .returns |
| 342 | .push(AbiParam::new(ty.to_cranelift())); |
| 343 | } |
| 344 | |
| 345 | // If this is e.g. an Int, Float, or Bool we have a Cranelift `Value`. |
| 346 | // If we have JitValue::None or .Tuple(...) but can't handle that, error out (or handle differently). |
| 347 | let cr_val = val.into_value().ok_or(JitCompileError::NotSupported)?; |
| 348 | |
| 349 | self.builder.ins().return_(&[cr_val]); |
| 350 | Ok(()) |
| 351 | } |
| 352 | |
| 353 | pub fn add_instruction<C: bytecode::Constant>( |
| 354 | &mut self, |
no test coverage detected