Skip to content

Commit c77a931

Browse files
#57 Operands (constants and register operands) can be compared for equality
1 parent fe514cf commit c77a931

File tree

1 file changed

+28
-0
lines changed
  • optvm/src/main/java/com/compilerprogramming/ezlang/compiler

1 file changed

+28
-0
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Operand.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.compilerprogramming.ezlang.types.Symbol;
44
import com.compilerprogramming.ezlang.types.EZType;
55

6+
import java.util.Objects;
7+
68
public class Operand {
79

810
EZType type;
@@ -17,6 +19,19 @@ public ConstantOperand(long value, EZType type) {
1719
public String toString() {
1820
return String.valueOf(value);
1921
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) return true;
26+
if (o == null || getClass() != o.getClass()) return false;
27+
ConstantOperand that = (ConstantOperand) o;
28+
return value == that.value;
29+
}
30+
31+
@Override
32+
public int hashCode() {
33+
return Objects.hashCode(value);
34+
}
2035
}
2136

2237
public static class NullConstantOperand extends Operand {
@@ -46,6 +61,19 @@ public RegisterOperand copy(Register register) {
4661
public String toString() {
4762
return reg.name();
4863
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o) return true;
68+
if (o == null || getClass() != o.getClass()) return false;
69+
RegisterOperand operand = (RegisterOperand) o;
70+
return Objects.equals(reg, operand.reg);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hashCode(reg);
76+
}
4977
}
5078

5179
public static class LocalRegisterOperand extends RegisterOperand {

0 commit comments

Comments
 (0)