Instance of user-defined class (compiled to C extension class). The runtime representation is 'PyObject *', and these are always boxed and thus reference-counted. These support fast method calls and fast attribute access using vtables, and they usually use a dict-free, struct-based
| 954 | |
| 955 | @final |
| 956 | class RInstance(RType): |
| 957 | """Instance of user-defined class (compiled to C extension class). |
| 958 | |
| 959 | The runtime representation is 'PyObject *', and these are always |
| 960 | boxed and thus reference-counted. |
| 961 | |
| 962 | These support fast method calls and fast attribute access using |
| 963 | vtables, and they usually use a dict-free, struct-based |
| 964 | representation of attributes. Method calls and attribute access |
| 965 | can skip the vtable if we know that there is no overriding. |
| 966 | |
| 967 | These are also sometimes called 'native' types, since these have |
| 968 | the most efficient representation and ops (along with certain |
| 969 | RPrimitive types and RTuple). |
| 970 | """ |
| 971 | |
| 972 | is_unboxed = False |
| 973 | |
| 974 | def __init__(self, class_ir: ClassIR) -> None: |
| 975 | # name is used for formatting the name in messages and debug output |
| 976 | # so we want the fullname for precision. |
| 977 | self.name = class_ir.fullname |
| 978 | self.class_ir = class_ir |
| 979 | self._ctype = "PyObject *" |
| 980 | |
| 981 | def accept(self, visitor: RTypeVisitor[T]) -> T: |
| 982 | return visitor.visit_rinstance(self) |
| 983 | |
| 984 | @property |
| 985 | def may_be_immortal(self) -> bool: |
| 986 | return False |
| 987 | |
| 988 | def struct_name(self, names: NameGenerator) -> str: |
| 989 | return self.class_ir.struct_name(names) |
| 990 | |
| 991 | def getter_index(self, name: str) -> int: |
| 992 | return self.class_ir.vtable_entry(name) |
| 993 | |
| 994 | def setter_index(self, name: str) -> int: |
| 995 | return self.getter_index(name) + 1 |
| 996 | |
| 997 | def method_index(self, name: str) -> int: |
| 998 | return self.class_ir.vtable_entry(name) |
| 999 | |
| 1000 | def attr_type(self, name: str) -> RType: |
| 1001 | return self.class_ir.attr_type(name) |
| 1002 | |
| 1003 | def __repr__(self) -> str: |
| 1004 | return "<RInstance %s>" % self.name |
| 1005 | |
| 1006 | def __eq__(self, other: object) -> TypeGuard[RInstance]: |
| 1007 | return isinstance(other, RInstance) and other.name == self.name |
| 1008 | |
| 1009 | def __hash__(self) -> int: |
| 1010 | return hash(self.name) |
| 1011 | |
| 1012 | def serialize(self) -> str: |
| 1013 | return self.name |
no outgoing calls
searching dependent graphs…