File tree Expand file tree Collapse file tree 5 files changed +107
-1
lines changed
main/java/dev/xdark/ssvm/execution Expand file tree Collapse file tree 5 files changed +107
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ plugins {
5
5
}
6
6
7
7
group ' dev.xdark'
8
- version ' 1.4.1 '
8
+ version ' 1.4.2 '
9
9
10
10
repositories {
11
11
mavenCentral()
Original file line number Diff line number Diff line change @@ -97,6 +97,35 @@ public void close() {
97
97
deallocate ();
98
98
}
99
99
100
+ @ Override
101
+ public boolean equals (Object o ) {
102
+ if (o == this ) return true ;
103
+ if (!(o instanceof Locals )) return false ;
104
+ val other = (Locals ) o ;
105
+ val table = this .table ;
106
+ int length = table .length ();
107
+ val otherTable = other .table ;
108
+ if (table .length () != otherTable .length ()) return false ;
109
+ for (int i = 0 ; i < length ; i ++) {
110
+ if (!Objects .equals (table .get (i ), otherTable .get (i ))) {
111
+ return false ;
112
+ }
113
+ }
114
+ return true ;
115
+ }
116
+
117
+ @ Override
118
+ public int hashCode () {
119
+ int result = 1 ;
120
+ val table = this .table ;
121
+ int cursor = table .length ();
122
+ for (int i = 0 ; i < cursor ; i ++) {
123
+ result *= 31 ;
124
+ result += Objects .hashCode (table .get (i ).hashCode ());
125
+ }
126
+ return result ;
127
+ }
128
+
100
129
@ Override
101
130
public String toString () {
102
131
return "Locals{" +
Original file line number Diff line number Diff line change @@ -337,6 +337,33 @@ public void close() {
337
337
deallocate ();
338
338
}
339
339
340
+ @ Override
341
+ public boolean equals (Object o ) {
342
+ if (o == this ) return true ;
343
+ if (!(o instanceof Stack )) return false ;
344
+ val other = (Stack ) o ;
345
+ int cursor = this .cursor ;
346
+ if (cursor != other .cursor ) return false ;
347
+ for (int i = 0 ; i < cursor ; i ++) {
348
+ if (!Objects .equals (getAt (i ), other .getAt (i ))) {
349
+ return false ;
350
+ }
351
+ }
352
+ return true ;
353
+ }
354
+
355
+ @ Override
356
+ public int hashCode () {
357
+ int result = 1 ;
358
+ int cursor = this .cursor ;
359
+ val stack = this .stack ;
360
+ for (int i = 0 ; i < cursor ; i ++) {
361
+ result *= 31 ;
362
+ result += Objects .hashCode (stack .get (i ).hashCode ());
363
+ }
364
+ return result ;
365
+ }
366
+
340
367
@ Override
341
368
public String toString () {
342
369
return "Stack{" +
Original file line number Diff line number Diff line change
1
+ package dev .xdark .ssvm ;
2
+
3
+ import dev .xdark .ssvm .execution .Locals ;
4
+ import dev .xdark .ssvm .execution .Stack ;
5
+ import dev .xdark .ssvm .value .DoubleValue ;
6
+ import dev .xdark .ssvm .value .IntValue ;
7
+ import dev .xdark .ssvm .value .LongValue ;
8
+ import dev .xdark .ssvm .value .NullValue ;
9
+ import lombok .val ;
10
+ import org .junit .jupiter .api .Test ;
11
+
12
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
13
+
14
+ public class LocalsTest {
15
+
16
+ @ Test
17
+ public void testEquality () {
18
+ try (val locals1 = new Locals (5 ); val locals2 = new Locals (5 )) {
19
+ fillLocals (locals1 );
20
+ fillLocals (locals2 );
21
+ assertEquals (locals1 , locals2 );
22
+ }
23
+ }
24
+
25
+ private static void fillLocals (Locals locals ) {
26
+ locals .set (0 , IntValue .ONE );
27
+ locals .setWide (1 , LongValue .ONE );
28
+ locals .set (3 , IntValue .of (5 ));
29
+ locals .setWide (4 , new DoubleValue (6.7D ));
30
+ }
31
+ }
Original file line number Diff line number Diff line change 1
1
package dev .xdark .ssvm ;
2
2
3
3
import dev .xdark .ssvm .execution .Stack ;
4
+ import dev .xdark .ssvm .value .DoubleValue ;
4
5
import dev .xdark .ssvm .value .IntValue ;
5
6
import dev .xdark .ssvm .value .LongValue ;
7
+ import dev .xdark .ssvm .value .NullValue ;
6
8
import lombok .val ;
7
9
import org .junit .jupiter .api .Test ;
8
10
@@ -190,4 +192,21 @@ public void testSwap() {
190
192
assertTrue (stack .isEmpty ());
191
193
}
192
194
}
195
+
196
+ @ Test
197
+ public void testEquality () {
198
+ try (val stack1 = new Stack (8 ); val stack2 = new Stack (8 )) {
199
+ filLStack (stack1 );
200
+ filLStack (stack2 );
201
+ assertEquals (stack1 , stack2 );
202
+ }
203
+ }
204
+
205
+ private static void filLStack (Stack stack ) {
206
+ stack .push (IntValue .ONE );
207
+ stack .pushWide (LongValue .ZERO );
208
+ stack .pushWide (new DoubleValue (1.3D ));
209
+ stack .push (NullValue .INSTANCE );
210
+ stack .pushWide (LongValue .ONE );
211
+ }
193
212
}
You can’t perform that action at this time.
0 commit comments