Example #1
0
 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();
                      """)
Example #2
0
 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;
                         }
                      """)
Example #3
0
 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;
                         }
                      """)
Example #4
0
    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
Example #5
0
 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))