def test_unbox(self) -> None: self.assert_emit( Unbox(self.n, self.m, IntRType()), """if (PyLong_Check(cpy_r_m)) cpy_r_n = CPyTagged_FromObject(cpy_r_m); else abort(); """)
def test_unbox(self) -> None: self.assert_emit( Unbox(self.m, int_rprimitive, 55), """if (PyLong_Check(cpy_r_m)) cpy_r_r0 = CPyTagged_FromObject(cpy_r_m); else { PyErr_SetString(PyExc_TypeError, "int object expected"); cpy_r_r0 = CPY_INT_TAG; } """)
def test_unbox(self) -> None: self.assert_emit( Unbox(self.m, int_rprimitive, 55), """if (likely(PyLong_Check(cpy_r_m))) cpy_r_r0 = CPyTagged_FromObject(cpy_r_m); else { CPy_TypeError("int", cpy_r_m); cpy_r_r0 = CPY_INT_TAG; } """)
def unbox_or_cast(self, src: Register, target_type: RType, target: Optional[Register] = None) -> Register: if target is None: target = self.alloc_temp(target_type) if target_type.supports_unbox: self.add(Unbox(target, src, target_type)) else: self.add(Cast(target, src, target_type)) return target
def unbox_or_cast(self, src: Value, target_type: RType, line: int) -> Value: if target_type.is_unboxed: return self.add(Unbox(src, target_type, line)) else: return self.add(Cast(src, target_type, line))