예제 #1
0
 def test_get_element_ptr(self) -> None:
     r = RStruct("Foo", ["b", "i32", "i64"],
                 [bool_rprimitive, int32_rprimitive, int64_rprimitive])
     self.assert_emit(GetElementPtr(self.o, r, "b"),
                      """cpy_r_r0 = (CPyPtr)&((Foo *)cpy_r_o)->b;""")
     self.assert_emit(GetElementPtr(self.o, r, "i32"),
                      """cpy_r_r0 = (CPyPtr)&((Foo *)cpy_r_o)->i32;""")
     self.assert_emit(GetElementPtr(self.o, r, "i64"),
                      """cpy_r_r0 = (CPyPtr)&((Foo *)cpy_r_o)->i64;""")
예제 #2
0
 def test_get_element_ptr(self) -> None:
     info = StructInfo(
         "Foo", ["b", "i32", "i64"],
         [bool_rprimitive, int32_rprimitive, int64_rprimitive])
     r = RStruct(info)
     self.assert_emit(GetElementPtr(self.o, r, "b"),
                      """cpy_r_r0 = &cpy_r_o.b;""")
     self.assert_emit(GetElementPtr(self.o, r, "i32"),
                      """cpy_r_r00 = &cpy_r_o.i32;""")
     self.assert_emit(GetElementPtr(self.o, r, "i64"),
                      """cpy_r_r01 = &cpy_r_o.i64;""")
예제 #3
0
 def builtin_len(self, val: Value, line: int) -> Value:
     typ = val.type
     if is_list_rprimitive(typ) or is_tuple_rprimitive(typ):
         elem_address = self.add(GetElementPtr(val, PyVarObject, 'ob_size'))
         size_value = self.add(LoadMem(c_pyssize_t_rprimitive, elem_address, val))
         offset = self.add(LoadInt(1, line, rtype=c_pyssize_t_rprimitive))
         return self.binary_int_op(short_int_rprimitive, size_value, offset,
                                   BinaryIntOp.LEFT_SHIFT, line)
     elif is_dict_rprimitive(typ):
         size_value = self.call_c(dict_size_op, [val], line)
         offset = self.add(LoadInt(1, line, rtype=c_pyssize_t_rprimitive))
         return self.binary_int_op(short_int_rprimitive, size_value, offset,
                                   BinaryIntOp.LEFT_SHIFT, line)
     elif is_set_rprimitive(typ):
         elem_address = self.add(GetElementPtr(val, PySetObject, 'used'))
         size_value = self.add(LoadMem(c_pyssize_t_rprimitive, elem_address, val))
         offset = self.add(LoadInt(1, line, rtype=c_pyssize_t_rprimitive))
         return self.binary_int_op(short_int_rprimitive, size_value, offset,
                                   BinaryIntOp.LEFT_SHIFT, line)
     # generic case
     else:
         return self.call_c(generic_len_op, [val], line)