diff --git a/src/gboml/ast/expression_operators.py b/src/gboml/ast/expression_operators.py index 685e0eba97ea3109fc47dc73dda0c8ffabb1b947..267ac57b95c6409f59bff34d21f61613d64b160b 100644 --- a/src/gboml/ast/expression_operators.py +++ b/src/gboml/ast/expression_operators.py @@ -41,6 +41,13 @@ class BoolExpressionComparison(BoolExpression): operator: Operator rhs: Expression + def __bool__(self): + """ Checks if lhs and rhs are *exactly* the same tree in an eq relation """ + #TODO improve me + if self.operator == Operator.equal: + return self.lhs is self.rhs + return False + @dataclass class ExpressionUseGenScope(ExpressionObj): diff --git a/src/gboml/ast/expressions.py b/src/gboml/ast/expressions.py index fc7e42165ee7478518a487c373d9b826ad9f706b..04d4494fc1cc0b5a3ba9f8c27e3d61c84623d955 100644 --- a/src/gboml/ast/expressions.py +++ b/src/gboml/ast/expressions.py @@ -5,7 +5,14 @@ from gboml.ast.base import GBOMLObject @dataclass class ExpressionObj(GBOMLObject): - pass + def __eq__(self, obj): + from gboml.ast.expression_operators import Operator, BoolExpressionComparison + # first: check type + if not isinstance(obj, Expression): + return False + if self is obj: + return True + return BoolExpressionComparison(self, Operator.equal, obj) Expression = int | float | ExpressionObj