box(type, src) This converts from a potentially unboxed representation to a straight Python object. Only supported for types with an unboxed representation.
| 1152 | |
| 1153 | @final |
| 1154 | class Box(RegisterOp): |
| 1155 | """box(type, src) |
| 1156 | |
| 1157 | This converts from a potentially unboxed representation to a straight Python object. |
| 1158 | Only supported for types with an unboxed representation. |
| 1159 | """ |
| 1160 | |
| 1161 | error_kind = ERR_NEVER |
| 1162 | |
| 1163 | def __init__(self, src: Value, line: int = -1) -> None: |
| 1164 | super().__init__(line) |
| 1165 | self.src = src |
| 1166 | self.type = object_rprimitive |
| 1167 | # When we box None and bool values, we produce a borrowed result |
| 1168 | if is_none_rprimitive(self.src.type) or is_bool_or_bit_rprimitive(self.src.type): |
| 1169 | self.is_borrowed = True |
| 1170 | |
| 1171 | def sources(self) -> list[Value]: |
| 1172 | return [self.src] |
| 1173 | |
| 1174 | def set_sources(self, new: list[Value]) -> None: |
| 1175 | (self.src,) = new |
| 1176 | |
| 1177 | def stolen(self) -> list[Value]: |
| 1178 | return [self.src] |
| 1179 | |
| 1180 | def accept(self, visitor: OpVisitor[T]) -> T: |
| 1181 | return visitor.visit_box(self) |
| 1182 | |
| 1183 | |
| 1184 | @final |
no outgoing calls