| 128 | } |
| 129 | |
| 130 | fn get_jit_value(vm: &VirtualMachine, obj: &PyObject) -> Result<AbiValue, ArgsError> { |
| 131 | // This does exact type checks as subclasses of int/float can't be passed to jitted functions |
| 132 | let cls = obj.class(); |
| 133 | if cls.is(vm.ctx.types.int_type) { |
| 134 | int::get_value(obj) |
| 135 | .to_i64() |
| 136 | .map(AbiValue::Int) |
| 137 | .ok_or(ArgsError::IntOverflow) |
| 138 | } else if cls.is(vm.ctx.types.float_type) { |
| 139 | Ok(AbiValue::Float( |
| 140 | obj.downcast_ref::<float::PyFloat>().unwrap().to_f64(), |
| 141 | )) |
| 142 | } else if cls.is(vm.ctx.types.bool_type) { |
| 143 | Ok(AbiValue::Bool(bool_::get_value(obj))) |
| 144 | } else { |
| 145 | Err(ArgsError::NonJitType) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /// Like `fill_locals_from_args` but to populate arguments for calling a jit function. |
| 150 | /// This also doesn't do full error handling but instead return None if anything is wrong. In |