summaryrefslogtreecommitdiff
path: root/chapter15
diff options
context:
space:
mode:
Diffstat (limited to 'chapter15')
-rw-r--r--chapter15/src/main/java/com/seaofnodes/simple/node/StoreNode.java1
-rw-r--r--chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java14
2 files changed, 15 insertions, 0 deletions
diff --git a/chapter15/src/main/java/com/seaofnodes/simple/node/StoreNode.java b/chapter15/src/main/java/com/seaofnodes/simple/node/StoreNode.java
index a27aee2b..6bdbbc61 100644
--- a/chapter15/src/main/java/com/seaofnodes/simple/node/StoreNode.java
+++ b/chapter15/src/main/java/com/seaofnodes/simple/node/StoreNode.java
@@ -53,6 +53,7 @@ public class StoreNode extends MemOpNode {
// required init-store being stomped by a first user store.
if( mem() instanceof StoreNode st &&
ptr()==st.ptr() && // Must check same object
+ off()==st.off() && // And same offset
ptr()._type instanceof TypeMemPtr && // No bother if weird dead pointers
// Must have exactly one use of "this" or you get weird
// non-serializable memory effects in the worse case.
diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java
index f08abed0..6ba6eed4 100644
--- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java
+++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java
@@ -47,6 +47,20 @@ return is[1];
}
@Test
+ public void testBasic3() {
+ Parser parser = new Parser(
+"""
+int[] a = new int[2];
+a[0] = 1;
+a[1] = 2;
+return a[0];
+""");
+ StopNode stop = parser.parse(false).iterate(true);
+ assertEquals("return .[];", stop.toString());
+ assertEquals(1L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
public void testRollingSum() {
Parser parser = new Parser(
"""