Skip to content

Commit 22ab85c

Browse files
committed
removed dead method + support for match
1 parent 5db8654 commit 22ab85c

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

grape/program.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,42 @@ def __eq__(self, other: object) -> bool:
1111
def __repr__(self):
1212
return str(self)
1313

14-
def can_be_embed_into(self, other: "Program") -> bool:
15-
return False
16-
1714
@abstractmethod
1815
def size(self) -> int:
1916
pass
2017

2118

2219
class Variable(Program):
20+
__match_args__ = ("no",)
21+
2322
def __init__(self, no: int):
2423
self.no = no
2524
self._hash = no
2625

2726
def __str__(self):
2827
return f"var{self.no}"
2928

30-
def can_be_embed_into(self, other: "Program") -> bool:
31-
return True
32-
3329
def size(self) -> int:
3430
return 1
3531

3632

3733
class Primitive(Program):
34+
__match_args__ = ("name",)
35+
3836
def __init__(self, name: str):
3937
self.name: str = name
4038
self._hash = hash(name)
4139

4240
def __str__(self):
4341
return self.name
4442

45-
def can_be_embed_into(self, other: "Program") -> bool:
46-
return self == other
47-
4843
def size(self) -> int:
4944
return 1
5045

5146

5247
class Function(Program):
48+
__match_args__ = ("function", "arguments")
49+
5350
def __init__(self, function: Program, arguments: list[Program]):
5451
self.function = function
5552
self.arguments = arguments
@@ -59,15 +56,6 @@ def __str__(self):
5956
args = " ".join(map(str, self.arguments))
6057
return f"({self.function} {args})"
6158

62-
def can_be_embed_into(self, other: "Program") -> bool:
63-
if isinstance(other, Function):
64-
return self.function.can_be_embed_into(other.function) and all(
65-
argm.can_be_embed_into(argo)
66-
for argm, argo in zip(self.arguments, other.arguments)
67-
)
68-
else:
69-
return False
70-
7159
def size(self) -> int:
7260
return self.function.size() + sum(arg.size() for arg in self.arguments)
7361

0 commit comments

Comments
 (0)