summaryrefslogtreecommitdiff
path: root/chapter21/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter21/src/test/java')
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/BrainFuckTest.java2
-rw-r--r--chapter21/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java32
2 files changed, 33 insertions, 1 deletions
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter21/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
index 97d33b70..40eb9719 100644
--- a/chapter21/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
+++ b/chapter21/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
@@ -20,7 +20,7 @@ public class BrainFuckTest {
String brain_fuck = "Hello World!\n";
TestC.run("brain_fuck", brain_fuck, 40);
- EvalRisc5 R5 = TestRisc5.build("brain_fuck", 0, 42, false);
+ EvalRisc5 R5 = TestRisc5.build("brain_fuck", 0, 114, false);
int trap = R5.step(100000);
assertEquals(0,trap);
int ptr = (int)R5.regs[riscv.A0];
diff --git a/chapter21/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java b/chapter21/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java
new file mode 100644
index 00000000..319c94b0
--- /dev/null
+++ b/chapter21/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java
@@ -0,0 +1,32 @@
+package com.seaofnodes.simple;
+
+import com.seaofnodes.simple.codegen.CodeGen;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class SchedulingScratchTest {
+ @Test public void testScratchAcrossCompilations() {
+ String src = """
+ int[] !xs = new int[2];
+ xs[0] = arg;
+ int sum = 0;
+ int i = 0;
+ while( i<5 ) {
+ int old = xs[arg&1];
+ xs[0] = i;
+ sum = sum + old;
+ i = i + 1;
+ }
+ return sum;
+ """;
+ // Each fresh compilation reuses node IDs and the scheduler's scratch.
+ for( int round=0; round<3; round++ ) {
+ CodeGen code = new CodeGen(src).driver(CodeGen.Phase.TypeCheck);
+ // A small graph after many earlier node allocations.
+ if( round==0 ) code._uid += 100_000;
+ assertEquals("6",Eval2.eval(code,0));
+ assertEquals("0",Eval2.eval(code,1));
+ assertEquals("8",Eval2.eval(code,2));
+ }
+ }
+}