|
13 | 13 |
|
14 | 14 | from kirin import ir, types, interp, lowering |
15 | 15 | from kirin.decl import info, statement |
16 | | -from kirin.print.printer import Printer |
17 | 16 | from kirin.dialects.py.constant import Constant |
18 | 17 |
|
19 | 18 | dialect = ir.Dialect("py.slice") |
@@ -63,55 +62,18 @@ def __init__( |
63 | 62 | ) |
64 | 63 |
|
65 | 64 |
|
66 | | -@dataclass |
67 | | -class SliceAttribute(ir.Data[slice]): |
68 | | - |
69 | | - start: int | None |
70 | | - stop: int | None |
71 | | - step: int | None |
72 | | - |
73 | | - def __post_init__(self) -> None: |
74 | | - if self.start is None and self.step is None: |
75 | | - self.type = types.Slice[types.Literal(self.stop)] |
76 | | - else: |
77 | | - self.type = types.Slice3[ |
78 | | - types.Literal(self.start), |
79 | | - types.Literal(self.stop), |
80 | | - types.Literal(self.step), |
81 | | - ] |
82 | | - |
83 | | - def unwrap(self): |
84 | | - return slice(self.start, self.stop, self.step) |
85 | | - |
86 | | - def __hash__(self): |
87 | | - return hash((type(self), self.start, self.stop, self.step)) |
88 | | - |
89 | | - def print_impl(self, printer: Printer) -> None: |
90 | | - return printer.plain_print(f"slice({self.start}, {self.stop}, {self.step})") |
91 | | - |
92 | | - def is_structurally_equal( |
93 | | - self, other: ir.Attribute, context: dict | None = None |
94 | | - ) -> bool: |
95 | | - return ( |
96 | | - isinstance(other, SliceAttribute) |
97 | | - and self.start == other.start |
98 | | - and self.stop == other.stop |
99 | | - and self.step == other.step |
100 | | - ) |
101 | | - |
102 | | - |
103 | 65 | @dialect.register |
104 | 66 | class Concrete(interp.MethodTable): |
105 | 67 |
|
106 | 68 | @interp.impl(Slice) |
107 | 69 | def _slice(self, interp, frame: interp.Frame, stmt: Slice): |
108 | 70 | start, stop, step = frame.get_values(stmt.args) |
109 | 71 | if start is None and step is None: |
110 | | - return (SliceAttribute(None, stop, None),) |
| 72 | + return (slice(stop),) |
111 | 73 | elif step is None: |
112 | | - return (SliceAttribute(start, stop, None),) |
| 74 | + return (slice(start, stop),) |
113 | 75 | else: |
114 | | - return (SliceAttribute(start, stop, step),) |
| 76 | + return (slice(start, stop, step),) |
115 | 77 |
|
116 | 78 |
|
117 | 79 | @dialect.register |
|
0 commit comments