From 3df967056bf48bd9f87900f3a1ad9af2aedce948 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Wed, 28 Oct 2026 16:14:30 -0700 Subject: Backport some minor speedups --- .../seaofnodes/simple/SchedulingScratchTest.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 chapter13/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java (limited to 'chapter13/src/test/java') diff --git a/chapter13/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java b/chapter13/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java new file mode 100644 index 00000000..6acdcd52 --- /dev/null +++ b/chapter13/src/test/java/com/seaofnodes/simple/SchedulingScratchTest.java @@ -0,0 +1,32 @@ +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; + +public class SchedulingScratchTest { + @Test public void testScratchAcrossCompilations() { + String src = """ + struct Box { int x; }; + Box b = new Box; + b.x = arg; + int sum = 0; + int i = 0; + while( i<5 ) { + int old = b.x; + b.x = 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++ ) { + StopNode stop = new Parser(src).parse().iterate(); + assertEquals(6L,Evaluator.evaluate(stop,0)); + assertEquals(7L,Evaluator.evaluate(stop,1)); + assertEquals(8L,Evaluator.evaluate(stop,2)); + } + } +} -- cgit v1.2.3