summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter05Test.java14
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter06Test.java10
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter07Test.java26
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter08Test.java16
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter09Test.java10
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter10Test.java67
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter11Test.java65
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter12Test.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter13Test.java41
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter14Test.java37
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter15Test.java124
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter16Test.java199
-rw-r--r--src/test/java/com/seaofnodes/simple/FuzzerWrap.java14
-rw-r--r--src/test/java/com/seaofnodes/simple/SchedulerTest.java4
-rw-r--r--src/test/java/com/seaofnodes/simple/TypeTest.java8
-rw-r--r--src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java35
-rw-r--r--src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java2
-rw-r--r--src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java2
18 files changed, 490 insertions, 186 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 9d154413..b5920125 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/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/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index ae37a867..ff1f3251 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/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(Region38,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(Region35,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(Region48,Phi(Region29,2,3),0)+Phi(Region,3,1));", ret.toString());
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index e6e0560b..b54c24a3 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/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/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 7760ae09..c199b78c 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -23,7 +23,7 @@ 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());
+ 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/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/src/test/java/com/seaofnodes/simple/Chapter09Test.java
index 64bbf245..b1d9d6e5 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter09Test.java
+++ b/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/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/src/test/java/com/seaofnodes/simple/Chapter10Test.java
index def9aaa6..2a33031d 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter10Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter10Test.java
@@ -1,5 +1,6 @@
package com.seaofnodes.simple;
+import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.StopNode;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -38,10 +39,10 @@ return p-r;
struct Bar {
int a;
int b;
-}
+};
struct Foo {
int x;
-}
+};
Foo? foo = null;
Bar bar = new Bar;
bar.a = 1;
@@ -55,7 +56,7 @@ return bar.a;
@Test
public void testExample() {
Parser parser = new Parser("""
-struct Vector2D { int x; int y; }
+struct Vector2D { int x; int y; };
Vector2D v = new Vector2D;
v.x = 1;
if (arg)
@@ -73,7 +74,7 @@ return v;
Parser parser = new Parser("""
struct s0 {
int v0;
-}
+};
s0? v1=null;
int v3=v1.zAicm;
""");
@@ -84,7 +85,7 @@ int v3=v1.zAicm;
@Test
public void testBug2() {
Parser parser = new Parser("""
-struct s0 { int v0; }
+struct s0 { int v0; };
arg=0+new s0.0;
""");
try { parser.parse(); fail(); }
@@ -94,7 +95,7 @@ arg=0+new s0.0;
@Test
public void testLoop() {
Parser parser = new Parser("""
-struct Bar { int a; }
+struct Bar { int a; };
Bar bar = new Bar;
while (arg) {
bar.a = bar.a + 2;
@@ -102,14 +103,14 @@ while (arg) {
}
return bar.a;
""");
- StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Loop13,0,(Phi_a+2));", stop.toString());
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Phi(Loop16,0,(Phi_a+2));", stop.toString());
}
@Test
public void testIf() {
Parser parser = new Parser("""
-struct Bar { int a; }
+struct Bar { int a; };
Bar bar = new Bar;
if (arg) bar = null;
bar.a = 1;
@@ -122,7 +123,7 @@ return bar.a;
@Test
public void testIf2() {
Parser parser = new Parser("""
-struct Bar { int a; }
+struct Bar { int a; };
Bar? bar = null;
if (arg) bar = new Bar;
bar.a = 1;
@@ -135,7 +136,7 @@ return bar.a;
@Test
public void testIf3() {
Parser parser = new Parser("""
-struct Bar { int a; }
+struct Bar { int a; };
Bar bar = null;
if (arg) bar = null;
bar.a = 1;
@@ -148,21 +149,21 @@ return bar.a;
@Test
public void testIfOrNull() {
Parser parser = new Parser("""
-struct Bar { int a; }
+struct Bar { int a; };
Bar? bar = new Bar;
if (arg) bar = null;
if( bar ) bar.a = 1;
return bar;
""");
StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Region33,(*void)Phi(Region20,null,Bar),null);", stop.toString());
+ assertEquals("return Phi(Region38,(*void)Phi(Region24,null,Bar),null);", stop.toString());
}
@Test
public void testIfOrNull2() {
Parser parser = new Parser(
"""
-struct Bar { int a; }
+struct Bar { int a; };
Bar? bar = new Bar;
if (arg) bar = null;
int rez = 3;
@@ -171,13 +172,13 @@ else bar.a = 1;
return rez;
""");
StopNode stop = parser.parse(false).iterate();
- assertEquals("return Phi(Region39,4,3);", stop.toString());
+ assertEquals("return Phi(Region44,4,3);", stop.toString());
}
@Test
public void testWhileWithNullInside() {
Parser parser = new Parser("""
-struct s0 {int v0;}
+struct s0 {int v0;};
s0? v0 = new s0;
int ret = 0;
while(arg) {
@@ -197,7 +198,7 @@ return ret;
Parser parser = new Parser("""
struct s0 {
int v0;
-}
+};
s0? v1=new s0;
s0? v1;
v1=new s0;
@@ -214,7 +215,7 @@ v1=new s0;
struct Iter {
int x;
int len;
-}
+};
Iter i = new Iter;
i.len = arg;
int sum=0;
@@ -225,16 +226,14 @@ while( i.x < i.len ) {
return sum;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop18,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString());
+ assertEquals("return Phi(Loop21,0,(Phi(Loop,0,(Phi_x+1))+Phi_sum));", stop.toString());
}
-
-
@Test
public void test1() {
Parser parser = new Parser("""
-struct s0 {int v0;}
+struct s0 {int v0;};
s0 ret = new s0;
while(arg) {
s0 v0 = new s0;
@@ -246,13 +245,13 @@ while(arg) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop13,s0,Phi(Region37,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop16,s0,Phi(Region43,s0,Phi_ret));", stop.toString());
}
@Test
public void test2() {
Parser parser = new Parser("""
-struct s0 {int v0;}
+struct s0 {int v0;};
s0 ret = new s0;
s0 v0 = new s0;
while(arg) {
@@ -264,14 +263,14 @@ while(arg) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop17,s0,Phi(Region38,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop20,s0,Phi(Region44,s0,Phi_ret));", stop.toString());
}
@Test
public void test3() {
Parser parser = new Parser("""
-struct s0 {int v0;}
+struct s0 {int v0;};
s0 ret = new s0;
while(arg < 10) {
s0 v0 = new s0;
@@ -281,21 +280,19 @@ while(arg < 10) {
return ret;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop13,s0,Phi(Region35,s0,Phi_ret));", stop.toString());
+ assertEquals("return Phi(Loop16,s0,Phi(Region41,s0,Phi_ret));", stop.toString());
}
@Test
public void testBug3() {
Parser parser = new Parser("""
-struct s0 {
- int f0;
-}
-if(0>=0) return new s0;
+struct s0 { int f0; };
return new s0;
int v0=null.f0;
""");
- try { parser.parse(); fail(); }
- catch( Exception e ) { assertEquals("Accessing unknown field 'f0' from 'null'", e.getMessage()); }
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return s0;", stop.toString());
+ assertEquals("Obj<s0>{f0=0}", Evaluator.evaluate(stop, 0).toString());
}
@Test
@@ -319,7 +316,7 @@ if(0) {
Parser parser = new Parser("""
struct s0 {
int f0;
-}
+};
if(0) return 0;
else return new s0;
if(new s0.f0) return 0;
@@ -346,7 +343,7 @@ return 0;
@Test
public void testBug7() {
Parser parser = new Parser("""
-struct s0 { int f0; }
+struct s0 { int f0; };
s0 v0 = new s0;
while(v0.f0) {}
s0 v1 = v0;
diff --git a/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index 5f9f9cac..d6b7bb00 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -292,7 +292,7 @@ else {
}
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ return 9; return 0; return 0; return 0; ]", stop.toString());
+ assertEquals("Stop[ return 9; return 0; return 0; ]", stop.toString());
}
@@ -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
@@ -337,7 +337,7 @@ return primeCount;
public void testAntiDeps1() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v=new S;
v.f = 2;
int i=new S.f;
@@ -355,7 +355,7 @@ return i;
public void testAntiDeps2() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
v.f = arg;
S t = new S;
@@ -369,14 +369,14 @@ if (arg) {
return i;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region40,.f,0);", stop.toString());
+ assertEquals("return Phi(Region45,.f,0);", stop.toString());
}
@Test
public void testAntiDeps3() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v0 = new S;
S? v1;
if (arg) v1 = new S;
@@ -396,7 +396,7 @@ return v0;
public void testAntiDeps4() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
v.f = arg;
S t = new S;
@@ -413,7 +413,7 @@ return i;
public void testAntiDeps5() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
while(1) {
while(arg+1) { arg=arg-1; }
@@ -430,7 +430,7 @@ return v;
public void testAntiDeps6() {
Parser parser = new Parser(
"""
-struct s { int v; }
+struct s { int v; };
s ptr=new s;
while( -arg )
ptr = new s;
@@ -445,7 +445,7 @@ while(1)
public void testAntiDeps7() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
S t = new S;
int i = v.f;
@@ -463,7 +463,7 @@ return i;
public void testAntiDeps8() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
S t = new S;
while(arg) {
@@ -476,14 +476,14 @@ while(arg) {
return arg;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Loop17,arg,Phi(Region42,.f,0));", stop.toString());
+ assertEquals("return Phi(Loop20,arg,Phi(Region48,.f,0));", stop.toString());
}
@Test
public void testAntiDeps9() {
Parser parser = new Parser(
"""
-struct S { int f; }
+struct S { int f; };
S v = new S;
S t = new S;
if (arg) {
@@ -500,8 +500,8 @@ return v;
@Test
public void testExample2() {
Parser parser = new Parser(
- """
-struct S { int f; }
+"""
+struct S { int f; };
S v = new S;
int i = arg;
while (arg > 0) {
@@ -515,4 +515,39 @@ return v;
StopNode stop = parser.parse().iterate();
//assertEquals("return new S;", stop.toString());
}
+
+ @Test
+ public void testScheduleUse() {
+ Parser parser = new Parser(
+"""
+int v0=0;
+while(0>=0) {
+ u1 v1=0;
+ v1=v0;
+ if(v1*0)
+ v0=-v1;
+}
+return 0;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
+
+ @Test
+ public void testLoopCarriedDep() {
+ Parser parser = new Parser(
+"""
+u32 v0=0;
+{
+ int v1=0;
+ while(v1) {
+ v1=1>>>v0!=0;
+ v0=v1/0;
+ }
+}
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
+
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index 2a637ce6..c0f6266a 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/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/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/src/test/java/com/seaofnodes/simple/Chapter13Test.java
index 416aba31..165d23e5 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter13Test.java
+++ b/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;
@@ -23,7 +22,7 @@ return 3.14;
public void testLinkedList0() {
Parser parser = new Parser(
"""
-struct LLI { LLI? next; int i; }
+struct LLI { LLI? next; int i; };
LLI? head = null;
while( arg ) {
LLI x = new LLI;
@@ -35,14 +34,14 @@ 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
public void testLinkedList1() {
Parser parser = new Parser(
"""
-struct LLI { LLI? next; int i; }
+struct LLI { LLI? next; int i; };
LLI? head = null;
while( arg ) {
LLI x = new LLI;
@@ -65,8 +64,8 @@ return next.i;
public void testCoRecur() {
Parser parser = new Parser(
"""
-struct int0 { int i; flt0? f; }
-struct flt0 { flt f; int0? i; }
+struct int0 { int i; flt0? f; };
+struct flt0 { flt f; int0? i; };
int0 i0 = new int0;
i0.i = 17;
flt0 f0 = new flt0;
@@ -83,7 +82,7 @@ return f0.i.f.i.i;
public void testNullRef0() {
Parser parser = new Parser(
"""
-struct N { N next; int i; }
+struct N { N? next; int i; };
N n = new N;
return n.next;
""");
@@ -95,33 +94,33 @@ return n.next;
public void testNullRef1() {
Parser parser = new Parser(
"""
-struct N { N next; int i; }
-N n = new N;
-n.next = new N;
+struct M { int m; };
+struct N { M next; int i; };
+N n = new N { next = new M; };
return n.next;
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return N;", stop.toString());
+ assertEquals("return M;", stop.toString());
}
@Test
public void testNullRef2() {
Parser parser = new Parser(
"""
-struct N { N next; int i; }
-N n = new N;
-n.next = null;
+struct M { int m; };
+struct N { M next; int i; };
+N n = new N { next = null; }
return n.next;
""");
try { parser.parse().iterate(); fail(); }
- catch( Exception e ) { assertEquals("Cannot store null into field *N next",e.getMessage()); }
+ catch( Exception e ) { assertEquals("Type null is not of declared type *M",e.getMessage()); }
}
@Test
public void testNullRef3() {
Parser parser = new Parser(
"""
-struct N { N next; int i; }
+struct N { N? next; int i; };
N n = new N;
n.i = 3.14;
return n.i;
@@ -145,7 +144,7 @@ struct S{};
public void testForwardRef0() {
Parser parser = new Parser(
"""
-struct S1 { S2 s; }
+struct S1 { S2 s; };
return new S2;
""");
try { parser.parse().iterate(); fail(); }
@@ -156,8 +155,8 @@ return new S2;
public void testForwardRef1() {
Parser parser = new Parser(
"""
-struct S1 { S2? s; }
-struct S2 { int x; }
+struct S1 { S2? s; };
+struct S2 { int x; };
return new S1.s=new S2;
""");
StopNode stop = parser.parse().iterate();
@@ -168,8 +167,8 @@ return new S1.s=new S2;
public void testcheckNull() {
Parser parser = new Parser(
"""
-struct I {int i;}
-struct P {I pi;}
+struct I {int i;};
+struct P { I? pi; };
P p1 = new P;
P p2 = new P;
p2.pi = new I;
diff --git a/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/src/test/java/com/seaofnodes/simple/Chapter14Test.java
index 048cb93a..7d7bb25a 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter14Test.java
+++ b/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
@@ -93,7 +93,7 @@ return b;
public void testRefLoad() {
Parser parser = new Parser(
"""
-struct Foo { u1 b; }
+struct Foo { u1 b; };
Foo f = new Foo;
f.b = 123;
return f.b;
@@ -166,6 +166,39 @@ return arg;
}
@Test
+ public void testCloneAnd() {
+ Parser parser = new Parser("""
+int v0=0;
+u32 v1 = 1&(1<<arg)&(1<<arg);
+while(arg) v1=-v0;
+while(v1) break;
+return v1;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return (Phi(Loop18,((1<<arg)&1),0)&Phi(Loop,Shl,4294967295));", stop.toString());
+ assertEquals(1L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testAndHigh() {
+ Parser parser = new Parser("""
+int v0=0;
+if(0&0>>>0) {
+ while(0) {
+ u8 v1=0;
+ v0=0>>>0;
+ v1=arg;
+ while(v1+0) {}
+ }
+}
+return v0;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
public void testTypes() {
Parser parser = new Parser(
"""
diff --git a/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/src/test/java/com/seaofnodes/simple/Chapter15Test.java
index 6ec7cc1a..d2d60b34 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter15Test.java
+++ b/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;
@@ -14,7 +11,8 @@ public class Chapter15Test {
@Test
public void testJig() {
- Parser parser = new Parser("""
+ Parser parser = new Parser(
+"""
return 3.14;
""");
StopNode stop = parser.parse().iterate();
@@ -23,29 +21,10 @@ return 3.14;
}
@Test
- public void testLifetime() {
- Parser parser = new Parser("""
-u8[] b = new u8[5];
-if (arg) {
- b[0] = b[0] + 1;
-} else {
- b[1] = b[1] * 2;
-}
-return b[0] + b[1];
-""");
- StopNode stop = parser.parse().iterate();
- assertEquals("return Phi(Region69,1,0);", stop.toString());
- assertEquals(0L, Evaluator.evaluate(stop, 0));
- assertEquals(1L, Evaluator.evaluate(stop, 1));
- }
-
- @Test
public void testCyclic() {
Parser parser = new Parser(
"""
-struct C {
- C? l;
-}
+struct C { C? l; };
C c = new C;
c.l = c;
return c;
@@ -70,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
@@ -117,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;
@@ -151,8 +130,9 @@ 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,3.14));", stop.toString());
assertEquals(3.14, Evaluator.evaluate(stop, 0));
+ assertEquals(1.2 , Evaluator.evaluate(stop, 1));
}
@Ignore
@@ -160,7 +140,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;
@@ -186,7 +166,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;
@@ -194,17 +174,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();
@@ -274,9 +251,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++ )
@@ -287,7 +264,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;
@@ -318,7 +295,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
@@ -348,4 +325,67 @@ return is[1];
catch( NegativeArraySizeException e ) { assertEquals("-1",e.getMessage()); }
}
+ @Test
+ public void testProgress() {
+ Parser parser = new Parser("""
+i8 v1=0&0;
+u8 v2=0;
+byte v4=0;
+if(0) {}
+while(v2<0) {
+ v4=0-v1;
+ break;
+}
+int v5=0&0;
+while(v5+(0&0)) {
+ int v7=0&0;
+ while(v7)
+ v4=0>>>v5;
+ while(v1)
+ return 0;
+}
+return v1;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testSharpNot() {
+ Parser parser = new Parser(
+"""
+if(0>>0) {}
+while(0) {}
+u32 v7=0;
+int v8=0;
+while(0<--1>>>---(v7*0==v8)) {}
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
+
+
+ @Test
+ public void testProgress2() {
+ Parser parser = new Parser(
+"""
+if(1) {}
+else {
+ while(arg>>>0&0>>>0) {}
+ byte v3=0>>>0;
+ while(0) {}
+ int v7=0>>>0;
+ while(v7<0>>>0) {
+ while(0+v7<=0) if(1) arg=-12;
+ if(arg) {
+ v3=arg+v3+0;
+ arg=0;
+ }
+ }
+}
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ }
}
diff --git a/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/src/test/java/com/seaofnodes/simple/Chapter16Test.java
new file mode 100644
index 00000000..ad287e82
--- /dev/null
+++ b/src/test/java/com/seaofnodes/simple/Chapter16Test.java
@@ -0,0 +1,199 @@
+package com.seaofnodes.simple;
+
+import com.seaofnodes.simple.evaluator.Evaluator;
+import com.seaofnodes.simple.node.StopNode;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class Chapter16Test {
+
+ @Test
+ public void testJig() {
+ Parser parser = new Parser(
+"""
+return 3.14;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 3.14;", stop.toString());
+ assertEquals(3.14, Evaluator.evaluate(stop, 0));
+ }
+
+
+ @Test
+ public void testMulti0() {
+ Parser parser = new Parser(
+"""
+int x, y;
+return x+y;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 0;", stop.toString());
+ assertEquals(0L, Evaluator.evaluate(stop, 0));
+ }
+ @Test
+ public void testMulti1() {
+ Parser parser = new Parser(
+"""
+int x=2, y=x+1;
+return x+y;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 5;", stop.toString());
+ assertEquals(5L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testFinal0() {
+ Parser parser = new Parser(
+"""
+int !x=2;
+x=3;
+return x;
+""");
+ try { parser.parse().iterate(); fail(); }
+ catch( Exception e ) { assertEquals("Cannot reassign final 'x'",e.getMessage()); }
+ }
+
+ @Test
+ public void testFinal1() {
+ Parser parser = new Parser(
+"""
+int !x=2, y=3;
+if( arg ) { int x = y; x = x*x; y=x; } // Shadow final x
+return y;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Phi(Region21,9,3);", stop.toString());
+ assertEquals(3L, Evaluator.evaluate(stop, 0));
+ assertEquals(9L, Evaluator.evaluate(stop, 1));
+ }
+
+ @Test
+ public void testConstruct0() {
+ Parser parser = new Parser("""
+struct X { int x=3; };
+X z = new X;
+return z.x;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 3;", stop.toString());
+ assertEquals(3L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testConstruct1() {
+ Parser parser = new Parser("""
+struct X { int !x; };
+X z = new X { x=3; };
+return z.x;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 3;", stop.toString());
+ assertEquals(3L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testConstruct2() {
+ Parser parser = new Parser("""
+struct X { int x=3; };
+X z = new X { x = 4; };
+return z.x;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return 4;", stop.toString());
+ assertEquals(4L, Evaluator.evaluate(stop, 0));
+ }
+
+
+ @Test
+ public void testStructFinal() {
+ Parser parser = new Parser("""
+struct Point { int !x, !y; };
+Point p = new Point { x=3; y=4; };
+return p;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Point;", stop.toString());
+ 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));
+ }
+
+ @Test
+ public void testLinkedList2() {
+ Parser parser = new Parser(
+"""
+struct LLI { LLI? next; int i; };
+LLI? head = null;
+while( arg ) {
+ head = new LLI {
+ next=head;
+ // Any old code in the constructor
+ int tmp=arg;
+ while( arg > 10 ) {
+ tmp = tmp + arg;
+ arg = arg - 1;
+ }
+ i=tmp;
+ };
+ 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, 11));
+ }
+
+ @Test
+ public void testSquare() {
+ Parser parser = new Parser(
+"""
+struct Square {
+ flt !side = arg;
+ // Newtons approximation to the square root, computed in a constructor.
+ // The actual allocation will copy in this result as the initial
+ // value for 'diag'.
+ flt diag = arg*arg/2;
+ while( 1 ) {
+ flt next = (side/diag + diag)/2;
+ if( next == diag ) break;
+ diag = next;
+ }
+};
+return new Square;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return Square;", stop.toString());
+ assertEquals("Obj<Square>{side=3.0,diag=1.7320508075688772}", Evaluator.evaluate(stop, 3).toString());
+ assertEquals("Obj<Square>{side=4.0,diag=2.0}", Evaluator.evaluate(stop, 4).toString());
+ }
+}
diff --git a/src/test/java/com/seaofnodes/simple/FuzzerWrap.java b/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
index 699711fc..eaeed8e2 100644
--- a/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
+++ b/src/test/java/com/seaofnodes/simple/FuzzerWrap.java
@@ -1,10 +1,9 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.fuzzer.Fuzzer;
-import org.junit.Test;
+import java.util.Random;
import org.junit.Ignore;
-
-
+import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
@@ -25,6 +24,15 @@ public class FuzzerWrap {
@Test
+ public void fuzzPeepsSmall() {
+ Random R = new Random(System.currentTimeMillis());
+ var fuzzer = new Fuzzer();
+ for (int i=0; i<100; i++)
+ fuzzer.fuzzPeeps(R.nextLong());
+ assertTrue(fuzzer.noExceptions());
+ }
+
+ @Test
@Ignore
public void fuzzPeepTiming() {
var fuzzer = new Fuzzer();
diff --git a/src/test/java/com/seaofnodes/simple/SchedulerTest.java b/src/test/java/com/seaofnodes/simple/SchedulerTest.java
index 853999b1..168e0ed7 100644
--- a/src/test/java/com/seaofnodes/simple/SchedulerTest.java
+++ b/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/src/test/java/com/seaofnodes/simple/TypeTest.java b/src/test/java/com/seaofnodes/simple/TypeTest.java
index cb45a0d7..6f7409cd 100644
--- a/src/test/java/com/seaofnodes/simple/TypeTest.java
+++ b/src/test/java/com/seaofnodes/simple/TypeTest.java
@@ -13,11 +13,11 @@ public class TypeTest {
@Test
public void testTypeAdHoc() {
TypeStruct s1 = TypeStruct.make("s1", new Field[]{
- Field.make("a",-1, TypeInteger.BOT),
- Field.make("b",-2, TypeInteger.BOT) });
+ Field.make("a", TypeInteger.BOT,-1, false),
+ Field.make("b", TypeInteger.BOT,-2, false) });
TypeStruct s2 = TypeStruct.make("s2", new Field[]{
- Field.make("a",-3, TypeInteger.BOT),
- Field.make("b",-4, TypeInteger.BOT) });
+ Field.make("a", TypeInteger.BOT,-3, false),
+ Field.make("b", TypeInteger.BOT,-4, false) });
Assert.assertEquals(s1, s1.glb());
Assert.assertNotEquals(s1, s1.dual());
Assert.assertEquals(s1, s1.dual().glb());
diff --git a/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java b/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
index 34921b94..28896283 100644
--- a/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
+++ b/src/test/java/com/seaofnodes/simple/evaluator/Evaluator.java
@@ -192,28 +192,20 @@ 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[type._fields.length];
- num = type._fields.length;
- }
- for (int i=0; i<num; i++) {
- var c = type._fields[i]._type;
- if (c instanceof TypeInteger) {
- body[i] = 0L;
- } else if (c instanceof TypeFloat) {
- body[i] = 0D;
- } else {
- assert c instanceof TypeMemPtr;
- }
+ body = new Object[num = type._fields.length];
+ for (int i=0; i<num; i++)
+ body[i] = val(alloc.in(2+i+num));
}
Object[] mems = new Object[type._fields.length+2];
// mems[0] is control
@@ -315,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);
};
}
@@ -325,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/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
index 59c15d3f..06169e2c 100644
--- a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java
+++ b/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");
});
diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
index 7cd854bf..d3cbb0ee 100644
--- a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
+++ b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java
@@ -109,7 +109,7 @@ public class ScriptGenerator {
static {
new Parser("", TypeInteger.BOT);
- for( var e : Parser.TYPES.entrySet() ) {
+ for( var e : Parser.defaultTypes().entrySet() ) {
if( e.getValue() instanceof TypeInteger ) {
INTTYPES.add(new TypeInt(e.getKey()));
}