Get item of a fixed-length tuple (src[index]).
| 1080 | |
| 1081 | @final |
| 1082 | class TupleGet(RegisterOp): |
| 1083 | """Get item of a fixed-length tuple (src[index]).""" |
| 1084 | |
| 1085 | error_kind = ERR_NEVER |
| 1086 | |
| 1087 | def __init__(self, src: Value, index: int, line: int = -1, *, borrow: bool = False) -> None: |
| 1088 | super().__init__(line) |
| 1089 | assert isinstance( |
| 1090 | src.type, RTuple |
| 1091 | ), f"TupleGet only operates on tuples, not {type(src.type).__name__}" |
| 1092 | src_len = len(src.type.types) |
| 1093 | self.src = src |
| 1094 | self.index = index |
| 1095 | if index < 0: |
| 1096 | self.index += src_len |
| 1097 | assert ( |
| 1098 | self.index <= src_len - 1 |
| 1099 | ), f"Index out of range.\nsource type: {src.type}\nindex: {index}" |
| 1100 | self.type = src.type.types[index] |
| 1101 | self.is_borrowed = borrow |
| 1102 | |
| 1103 | def sources(self) -> list[Value]: |
| 1104 | return [self.src] |
| 1105 | |
| 1106 | def set_sources(self, new: list[Value]) -> None: |
| 1107 | (self.src,) = new |
| 1108 | |
| 1109 | def accept(self, visitor: OpVisitor[T]) -> T: |
| 1110 | return visitor.visit_tuple_get(self) |
| 1111 | |
| 1112 | |
| 1113 | @final |
no outgoing calls
searching dependent graphs…