summaryrefslogtreecommitdiff
path: root/chapter16/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
Diffstat (limited to 'chapter16/src/test/java/com/seaofnodes')
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter05Test.java14
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter06Test.java10
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter07Test.java26
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter08Test.java18
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter09Test.java10
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java14
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java8
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter12Test.java2
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter13Test.java3
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java2
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java40
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java27
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/SchedulerTest.java4
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java24
-rw-r--r--chapter16/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java2
15 files changed, 111 insertions, 93 deletions
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 9d154413..b5920125 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -22,7 +22,7 @@ else {
return a;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region20,(arg+2),(arg-3));", ret.toString());
+ assertEquals("return Phi(Region23,(arg+2),(arg-3));", ret.toString());
}
@Test
@@ -37,7 +37,7 @@ if (arg == 1) {
}
return c;""", TypeInteger.BOT);
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region19,4,3);", ret.toString());
+ assertEquals("return Phi(Region22,4,3);", ret.toString());
}
@Test
@@ -65,7 +65,7 @@ else
b=a+1;
return a+b;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return ((arg*2)+Phi(Region23,2,3));", ret.toString());
+ assertEquals("return ((arg*2)+Phi(Region26,2,3));", ret.toString());
}
@Test
@@ -80,7 +80,7 @@ else
a=b+1;
return a+b;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return ((Phi(Region34,(arg*2),arg)+arg)+Phi(Region,4,5));", ret.toString());
+ assertEquals("return ((Phi(Region37,(arg*2),arg)+arg)+Phi(Region,4,5));", ret.toString());
}
@Test
@@ -100,7 +100,7 @@ else
return a;
""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region38,Phi(Region24,2,3),Phi(Region36,4,5));", stop.toString());
+ assertEquals("return Phi(Region43,Phi(Region28,2,3),Phi(Region41,4,5));", stop.toString());
}
@Test
@@ -116,7 +116,7 @@ if( arg==0 )
return arg+a+b;
""", TypeInteger.BOT);
StopNode stop = parser.parse();
- assertEquals("return ((arg+Phi(Region17,1,0))+Phi(Region33,2,0));", stop.toString());
+ assertEquals("return ((arg+Phi(Region20,1,0))+Phi(Region37,2,0));", stop.toString());
}
@Test
@@ -130,7 +130,7 @@ if( arg==1 )
}
return a;""");
StopNode ret = parser.parse().iterate();
- assertEquals("return (arg==Phi(Region19,3,2));", ret.toString());
+ assertEquals("return (arg==Phi(Region22,3,2));", ret.toString());
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index ae37a867..6308bdea 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -65,7 +65,7 @@ else
b=5;
return b;""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region39,42,5);", stop.toString());
+ assertEquals("return Phi(Region43,42,5);", stop.toString());
}
@Test
@@ -84,7 +84,7 @@ else
b=5;
return b;""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region32,2,5);", stop.toString());
+ assertEquals("return Phi(Region36,2,5);", stop.toString());
}
@Test
@@ -144,7 +144,7 @@ else
return a;
""", TypeInteger.BOT);
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region43,3,Phi(Region41,4,5));", stop.toString());
+ assertEquals("return Phi(Region48,3,Phi(Region46,4,5));", stop.toString());
}
@Test
@@ -200,7 +200,7 @@ if( arg ) {
return a+b;
""");
StopNode ret = parser.parse().iterate();
- assertEquals("return Phi(Region28,4,1);", ret.toString());
+ assertEquals("return Phi(Region32,4,1);", ret.toString());
}
@@ -251,7 +251,7 @@ if( arg ) {
return a+b+c;
""");
StopNode ret = parser.parse().iterate();
- assertEquals("return (Phi(Region40,Phi(Region25,2,3),0)+Phi(Region,3,1));", ret.toString());
+ assertEquals("return (Phi(Region45,Phi(Region29,2,3),0)+Phi(Region,3,1));", ret.toString());
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index e6e0560b..b54c24a3 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter07Test.java
@@ -18,7 +18,7 @@ public class Chapter07Test {
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop8,arg,(Phi_arg+1));", stop.toString());
+ assertEquals("return Phi(Loop10,arg,(Phi_arg+1));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -36,7 +36,7 @@ if(arg){}else{
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region26,1,Phi(Loop15,1,(Phi_a+1)));", stop.toString());
+ assertEquals("return Phi(Region31,1,Phi(Loop18,1,(Phi_a+1)));", stop.toString());
}
@Test
@@ -56,7 +56,7 @@ while(i < arg) {
return sum;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop10,0,Phi(Loop22,Phi_sum,(Phi_sum+Phi(Loop,0,(Phi_j+1)))));", stop.toString());
+ assertEquals("return Phi(Loop12,0,Phi(Loop26,Phi_sum,(Phi_sum+Phi(Loop,0,(Phi_j+1)))));", stop.toString());
}
@Test
@@ -73,7 +73,7 @@ return b;
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop10,2,Phi(Region29,Phi_b,4));", stop.toString());
+ assertEquals("return Phi(Loop12,2,Phi(Region34,Phi_b,4));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -93,7 +93,7 @@ while(a < 10) {
return b;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop10,2,(Phi(Region29,Phi_b,4)+1));", stop.toString());
+ assertEquals("return Phi(Loop12,2,(Phi(Region34,Phi_b,4)+1));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -111,7 +111,7 @@ return a;
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop11,1,((Phi_a+1)+2));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -128,7 +128,7 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
+ assertEquals("return Phi(Loop11,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -142,7 +142,7 @@ return a;
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,2);", stop.toString());
+ assertEquals("return Phi(Loop11,1,2);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -156,7 +156,7 @@ while(arg) a = 2;
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,1,2);", stop.toString());
+ assertEquals("return Phi(Loop11,1,2);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -173,7 +173,7 @@ return a;
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop9,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop11,1,((Phi_a+1)+2));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -190,7 +190,7 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,1,(Phi_a+3));", stop.toString());
+ assertEquals("return Phi(Loop11,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -208,7 +208,7 @@ return a;
""");
Node._disablePeephole = true;
StopNode stop = parser.parse();
- assertEquals("return Phi(Loop10,1,((Phi_a+1)+2));", stop.toString());
+ assertEquals("return Phi(Loop12,1,((Phi_a+1)+2));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
Node._disablePeephole = false;
}
@@ -226,7 +226,7 @@ while(a < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
+ assertEquals("return Phi(Loop12,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 7760ae09..8117b2d6 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -22,8 +22,8 @@ while(arg < 10) {
}
return arg;
""");
- StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region37,Phi(Region26,Phi(Loop8,arg,(Phi_arg+1)),Add),Add);", stop.toString());
+ StopNode stop = parser.parse().iterate(true);
+ assertEquals("return Phi(Region45,Phi(Region32,Phi(Loop10,arg,(Phi_arg+1)),Add),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
Assert.assertEquals(5L, Evaluator.evaluate(stop, 1));
Assert.assertEquals(10L, Evaluator.evaluate(stop, 6));
@@ -46,7 +46,7 @@ while(arg < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,1,Phi(Region43,Phi_a,(Phi_a+1)));", stop.toString());
+ assertEquals("return Phi(Loop11,1,Phi(Region52,Phi_a,(Phi_a+1)));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -65,7 +65,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region35,Phi(Loop8,arg,(Phi_arg+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region43,Phi(Loop10,arg,(Phi_arg+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -81,7 +81,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region26,Phi(Loop8,arg,(Phi_arg+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region32,Phi(Loop10,arg,(Phi_arg+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -100,7 +100,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,arg,(Phi_arg+1));", stop.toString());
+ assertEquals("return Phi(Loop10,arg,(Phi_arg+1));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -117,7 +117,7 @@ while(arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,arg,(Phi_arg+1));", stop.toString());
+ assertEquals("return Phi(Loop10,arg,(Phi_arg+1));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
@@ -185,7 +185,7 @@ while(arg < 10) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region29,Phi(Loop9,1,(Phi_a+1)),Add);", stop.toString());
+ assertEquals("return Phi(Region35,Phi(Loop11,1,(Phi_a+1)),Add);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof RegionNode);
}
@@ -201,7 +201,7 @@ while(1) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return (Phi(Loop9,1,Add)+1);", stop.toString());
+ assertEquals("return (Phi(Loop11,1,Add)+1);", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode prj && prj._idx==1 );
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter09Test.java
index 64bbf245..b1d9d6e5 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter09Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter09Test.java
@@ -69,7 +69,7 @@ while (arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,arg,(Phi_arg+2));", stop.toString());
+ assertEquals("return Phi(Loop11,arg,(Phi_arg+2));", stop.toString());
Assert.assertEquals(11L, Evaluator.evaluate(stop, 1));
}
@@ -86,7 +86,7 @@ while (arg < 10) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop10,arg,(Phi_arg+4));", stop.toString());
+ assertEquals("return Phi(Loop12,arg,(Phi_arg+4));", stop.toString());
Assert.assertEquals(13L, Evaluator.evaluate(stop, 1));
}
@@ -115,7 +115,7 @@ while (arg) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop16,arg,(Phi_arg+1));", stop.toString());
+ assertEquals("return Phi(Loop18,arg,(Phi_arg+1));", stop.toString());
}
@Test
@@ -185,7 +185,7 @@ while(arg) {
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop11,0,(-(Phi_a+3)));", stop.toString());
+ assertEquals("return Phi(Loop13,0,(-(Phi_a+3)));", stop.toString());
}
@Test
@@ -283,7 +283,7 @@ return v1+v0;
public void testFuzz8() {
Parser parser = new Parser("while(arg) arg = arg - 1; return arg;");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop8,arg,(Phi_arg-1));", stop.toString());
+ assertEquals("return Phi(Loop10,arg,(Phi_arg-1));", stop.toString());
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index 0b3e4110..10817e04 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -102,8 +102,8 @@ while (arg) {
}
return bar.a;
""");
- StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Loop15,0,(Phi_a+2));", stop.toString());
+ StopNode stop = parser.parse().iterate(true);
+ assertEquals("return Phi(Loop16,0,(Phi_a+2));", stop.toString());
}
@Test
@@ -155,7 +155,7 @@ if( bar ) bar.a = 1;
return bar;
""");
StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Region35,(*void)Phi(Region22,null,Bar),null);", stop.toString());
+ assertEquals("return Phi(Region38,(*void)Phi(Region24,null,Bar),null);", stop.toString());
}
@Test
@@ -171,7 +171,7 @@ else bar.a = 1;
return rez;
""");
StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Region41,4,3);", stop.toString());
+ assertEquals("return Phi(Region44,4,3);", stop.toString());
}
@Test
@@ -244,7 +244,7 @@ while(arg) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop15,s0,Phi(Region39,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop16,s0,Phi(Region43,s0,Phi_ret));", stop.toString());
}
@Test
@@ -262,7 +262,7 @@ while(arg) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop19,s0,Phi(Region40,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop20,s0,Phi(Region44,s0,Phi_ret));", stop.toString());
}
@@ -279,7 +279,7 @@ while(arg < 10) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop15,s0,Phi(Region37,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop16,s0,Phi(Region41,s0,Phi_ret));", stop.toString());
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index 90198098..a064e8e4 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -324,7 +324,7 @@ while( prime <= arg ) {
return primeCount;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ return 0; return Phi(Loop20,1,Phi(Region87,Phi_primeCount,Phi(Region81,(Phi_primeCount+1),Phi_primeCount))); ]", stop.toString());
+ assertEquals("Stop[ return 0; return Phi(Loop23,1,Phi(Region100,Phi_primeCount,Phi(Region93,(Phi_primeCount+1),Phi_primeCount))); ]", stop.toString());
assertEquals(0L, Evaluator.evaluate(stop, 1)); // No primes 1 or below
assertEquals(1L, Evaluator.evaluate(stop, 2)); // 2
assertEquals(2L, Evaluator.evaluate(stop, 3)); // 2, 3
@@ -369,7 +369,7 @@ if (arg) {
return i;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region42,.f,0);", stop.toString());
+ assertEquals("return Phi(Region45,.f,0);", stop.toString());
}
@Test
@@ -437,7 +437,7 @@ while( -arg )
while(1)
arg = arg+ptr.v;
""");
- StopNode stop = parser.parse().iterate();
+ StopNode stop = parser.parse().iterate(true);
assertEquals("Stop[ return 0; return 0; ]", stop.toString());
}
@@ -476,7 +476,7 @@ while(arg) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop19,arg,Phi(Region44,.f,0));", stop.toString());
+ assertEquals("return Phi(Loop20,arg,Phi(Region48,.f,0));", stop.toString());
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index 2a637ce6..c0f6266a 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter12Test.java
@@ -43,7 +43,7 @@ while( 1 ) {
return guess;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,(flt)arg,(((ToFloat/Phi_guess)+Phi_guess)/2.0));", stop.toString());
+ assertEquals("return Phi(Loop11,(flt)arg,(((ToFloat/Phi_guess)+Phi_guess)/2.0));", stop.toString());
assertEquals(3.0, Evaluator.evaluate(stop, 9));
assertEquals(1.414213562373095, Evaluator.evaluate(stop, 2));
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter13Test.java
index 750fe3d3..165d23e5 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter13Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter13Test.java
@@ -2,7 +2,6 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.StopNode;
-import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -35,7 +34,7 @@ while( arg ) {
return head.next.i;
""");
try { parser.parse().iterate(); fail(); }
- catch( Exception e ) { assertEquals("Might be null accessing 'next'",e.getMessage()); }
+ catch( Exception e ) { assertEquals("Might be null accessing 'i'",e.getMessage()); }
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
index 674196ee..ea577c6b 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter14Test.java
@@ -59,7 +59,7 @@ while( b ) b = b + 456;// Truncate
return b;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop9,123,((Phi_b+456)&255));", stop.toString());
+ assertEquals("return Phi(Loop11,123,((Phi_b+456)&255));", stop.toString());
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
index 3a379084..a9b34748 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter15Test.java
@@ -4,9 +4,6 @@ import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.StopNode;
import org.junit.Test;
import org.junit.Ignore;
-
-import java.nio.charset.StandardCharsets;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -27,9 +24,7 @@ return 3.14;
public void testCyclic() {
Parser parser = new Parser(
"""
-struct C {
- C? l;
-}
+struct C { C? l; };
C c = new C;
c.l = c;
return c;
@@ -54,8 +49,8 @@ output[i] = 1;
return output;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return u8[];", stop.toString());
- assertEquals("\u0001", Evaluator.evaluate(stop, 0).toString());
+ assertEquals("return [u8];", stop.toString());
+ assertEquals("Obj<[u8]>{#=1,[]=[1]}", Evaluator.evaluate(stop, 0).toString());
}
@Test
@@ -101,20 +96,20 @@ return a[0];
public void testBasic4() {
Parser parser = new Parser(
"""
-struct A { int i; }
+struct A { int i; };
A?[] a = new A?[2];
return a;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return *A?[];", stop.toString());
- assertEquals("Obj<*A?[]>{#=2,[]=[null,null]}", Evaluator.evaluate(stop, 0).toString());
+ assertEquals("return [*A?];", stop.toString());
+ assertEquals("Obj<[*A?]>{#=2,[]=[null,null]}", Evaluator.evaluate(stop, 0).toString());
}
@Test
public void testBasic5() {
Parser parser = new Parser(
"""
-struct S { int x; flt y; }
+struct S { int x; flt y; };
// A new S
S s = new S; s.x=99; s.y = 3.14;
@@ -135,7 +130,7 @@ else {
return rez;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region118,1.2,Phi(Region115,2.3,.y));", stop.toString());
+ assertEquals("return Phi(Region117,1.2,Phi(Region114,2.3,.y));", stop.toString());
assertEquals(3.14, Evaluator.evaluate(stop, 0));
}
@@ -144,7 +139,7 @@ return rez;
public void testBasic6() {
Parser parser = new Parser(
"""
-struct S { int x; flt y; }
+struct S { int x; flt y; };
// A new S
S s = new S; s.x=99; s.y = 3.14;
@@ -170,7 +165,7 @@ return rez;
Parser parser = new Parser(
"""
// Can we define a forward-reference array?
-struct Tree { Tree?[] _kids; }
+struct Tree { Tree?[]? _kids; };
Tree root = new Tree;
root._kids = new Tree?[2];
root._kids[0] = new Tree;
@@ -178,17 +173,14 @@ return root;
""");
StopNode stop = parser.parse().iterate();
assertEquals("return Tree;", stop.toString());
- assertEquals("Obj<Tree>{_kids=Obj<*Tree?[]>{#=2,[]=[Obj<Tree>{_kids=null},null]}}", Evaluator.evaluate(stop, 0).toString());
+ assertEquals("Obj<Tree>{_kids=Obj<[*Tree?]>{#=2,[]=[Obj<Tree>{_kids=null},null]}}", Evaluator.evaluate(stop, 0).toString());
}
@Test
public void testNestedStructAddMemProj() {
Parser parser = new Parser(
"""
-struct S {
- int a;
- int[] b;
-}
+struct S { int a; int[] b; };
return 0;
""");
StopNode stop = parser.parse();
@@ -258,9 +250,9 @@ while( j < nprimes ) {
return rez;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return int[];", stop.toString());
+ assertEquals("return [int];", stop.toString());
Evaluator.Obj obj = (Evaluator.Obj)Evaluator.evaluate(stop, 20);
- assertEquals("int[] {\n # :int;\n [] :int;\n}",obj.struct().toString());
+ assertEquals("[int] { # :int; [] :int; }",obj.struct().toString());
long nprimes = (Long)obj.fields()[0];
long[] primes = new long[]{2,3,5,7,11,13,17,19};
for( int i=0; i<nprimes; i++ )
@@ -271,7 +263,7 @@ return rez;
public void testNewNodeInit() {
Parser parser = new Parser(
"""
-struct S {int i; flt f;}
+struct S {int i; flt f;};
S s1 = new S;
S s2 = new S;
s2.i = 3;
@@ -302,7 +294,7 @@ return new flt;
int is = new int[2];
""");
try { parser.parse().iterate(); fail(); }
- catch( Exception e ) { assertEquals("Type *int[] is not of declared type int",e.getMessage()); }
+ catch( Exception e ) { assertEquals("Type *[int] is not of declared type int",e.getMessage()); }
}
@Test
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
index 9a56bc94..6878a836 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/Chapter16Test.java
@@ -79,7 +79,7 @@ if( arg ) { int x = y; x = x*x; y=x; } // Shadow final x
return y;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region18,9,3);", stop.toString());
+ assertEquals("return Phi(Region21,9,3);", stop.toString());
assertEquals(3L, Evaluator.evaluate(stop, 0));
assertEquals(9L, Evaluator.evaluate(stop, 1));
}
@@ -133,4 +133,29 @@ return p;
assertEquals("Obj<Point>{x=3,y=4}", Evaluator.evaluate(stop, 0).toString());
}
+ // Same as the Chapter13 test with the same name, but using the new
+ // constructor syntax
+ @Test
+ public void testLinkedList1() {
+ Parser parser = new Parser(
+"""
+struct LLI { LLI? next; int i; };
+LLI? head = null;
+while( arg ) {
+ head = new LLI { next=head; i=arg; };
+ arg = arg-1;
+}
+if( !head ) return 0;
+LLI? next = head.next;
+if( !next ) return 1;
+return next.i;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("Stop[ return 0; return 1; return .i; ]", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ assertEquals(1L, Evaluator.evaluate(stop, 1));
+ assertEquals(2L, Evaluator.evaluate(stop, 3));
+ }
+
+
}
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/SchedulerTest.java b/chapter16/src/test/java/com/seaofnodes/simple/SchedulerTest.java
index 853999b1..168e0ed7 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/SchedulerTest.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/SchedulerTest.java
@@ -41,7 +41,7 @@ return i;
Parser parser = new Parser("""
struct S {
int f;
-}
+};
S v0=new S;
if(arg) v0.f=1;
return v0;
@@ -57,7 +57,7 @@ return v0;
Parser parser = new Parser("""
struct S {
int f;
-}
+};
S v=new S;
v.f = 2;
int i=new S.f;
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java b/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
index fccec969..28896283 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
@@ -192,20 +192,21 @@ public class Evaluator {
if( n < 0 )
throw new NegativeArraySizeException(""+n);
body = new Object[(int)n+1]; // Array body
- var c = type._fields[type._fields.length-1]._type;
- if (c instanceof TypeInteger) {
- for (int i=0; i<n; i++) body[i+type._fields.length-1] = 0L;
- } else if (c instanceof TypeFloat) {
- for (int i = 0; i < n; i++) body[i+type._fields.length-1] = 0D;
+ var elem = type._fields[1]._type;
+ if (elem instanceof TypeInteger) {
+ for (int i=0; i<n; i++) body[i+1] = 0L;
+ } else if (elem instanceof TypeFloat) {
+ for (int i = 0; i < n; i++) body[i+1] = 0D;
} else {
- assert c instanceof TypeMemPtr;
+ assert elem instanceof TypeMemPtr;
}
- num = type._fields.length-1;
+ // Length value
+ body[0] = vall(alloc.in(2+2));
} else {
body = new Object[num = type._fields.length];
+ for (int i=0; i<num; i++)
+ body[i] = val(alloc.in(2+i+num));
}
- for (int i=0; i<num; i++)
- body[i] = alloc.in(2+i+num)._type;
Object[] mems = new Object[type._fields.length+2];
// mems[0] is control
mems[1] = new Obj(type,body); // the ref
@@ -306,6 +307,7 @@ public class Evaluator {
case NewNode alloc -> alloc(alloc);
case CProjNode cproj -> ((Object[])val(cproj.ctrl()))[cproj._idx];
case ProjNode proj -> ((Object[])val( proj.in(0) ))[ proj._idx];
+ case ScopeMinNode mem -> null;
default -> throw new AssertionError("Unexpected node " + node);
};
}
@@ -316,8 +318,8 @@ public class Evaluator {
public Object evaluate(long parameter, int loops) {
if (start == null) return Status.TIMEOUT;
var s = new Object[start.compute()._types.length];
- s[1] = parameter;
- for(int i=2;i<s.length;i++) s[i] = MEMORY;
+ s[1] = MEMORY;
+ s[2] = parameter;
values[start._nid] = s;
int i=0;
Scheduler.Block block = this.startBlock;
diff --git a/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java b/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
index 59c15d3f..06169e2c 100644
--- a/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
+++ b/chapter16/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
@@ -560,7 +560,7 @@ public class Scheduler {
blocks.put(first, switch(last) {
case null -> new Block(arr, null, -1, new Block[0]);
case IfNode i -> new Block(arr, i, -1, new Block[2]);
- case RegionNode r -> new Block(arr, r, Utils.find(r._inputs, prev), new Block[1]);
+ case RegionNode r -> new Block(arr, r, r._inputs.find(prev), new Block[1]);
case ReturnNode r -> new Block(arr, r, -1, new Block[0]);
default -> throw new AssertionError("Unexpected block exit node");
});