diff options
| author | Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> | 2026-09-26 06:35:22 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-25 15:35:22 -0700 |
| commit | dd907c2d86eaaad0910e7bfe3f0d25e5caf8bdf7 (patch) | |
| tree | 8b71264016c53914912e1cd30527b1bf86ed9bf3 /chapter15/src/test | |
| parent | e922879e9dfa402934e2b5860900661b1169492c (diff) | |
| download | Simple-dd907c2d86eaaad0910e7bfe3f0d25e5caf8bdf7.tar.gz Simple-dd907c2d86eaaad0910e7bfe3f0d25e5caf8bdf7.zip | |
Extend and backport SubNode peephole (#254)
* Extend and backport SubNode peephole
* Add tests
* Restrict subtraction zero peepholes to integer operands
Require resolved integer mode in chapter 25 so zero subtraction preserves floating-point signed zero. Keep nonnumeric operands in the graph for subtraction diagnostics.
Add signed-zero coverage from chapter 12 and null-subtraction diagnostics from chapter 22. Confirmed the regressions fail on the original PR. Full Make suites pass in chapters 4-25 (5462 tests), including fresh chapter 25 sys.o compilation.
---------
Co-authored-by: Cliff Click <cliffc@acm.org>
Diffstat (limited to 'chapter15/src/test')
| -rw-r--r-- | chapter15/src/test/java/com/seaofnodes/simple/Chapter04Test.java | 28 | ||||
| -rw-r--r-- | chapter15/src/test/java/com/seaofnodes/simple/Chapter12Test.java | 7 |
2 files changed, 35 insertions, 0 deletions
diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter04Test.java index 80cdb3f2..a3109ff7 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter04Test.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter04Test.java @@ -51,6 +51,34 @@ public class Chapter04Test { } @Test + public void testSub0() { + Parser parser = new Parser("return arg-0;"); + StopNode ret = parser.parse(); + assertEquals("return arg;", ret.print()); + } + + @Test + public void test0Sub() { + Parser parser = new Parser("return 0-arg;"); + StopNode ret = parser.parse(); + assertEquals("return (-arg);", ret.print()); + } + + @Test + public void testSubNeg() { + Parser parser = new Parser("return 3--arg;"); + StopNode ret = parser.parse(); + assertEquals("return (arg+3);", ret.print()); + } + + @Test + public void testNegSub() { + Parser parser = new Parser("return -arg-3;"); + StopNode ret = parser.parse(); + assertEquals("return (-(arg+3));", ret.print()); + } + + @Test public void testVarArg() { Parser parser = new Parser("return arg; "); StopNode stop = parser.parse(); diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter12Test.java index c8802f4c..4eaf81df 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter12Test.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter12Test.java @@ -8,6 +8,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public class Chapter12Test { + @Test public void testSubZeroFloat() { + var stop = new Parser("flt x = arg; return 0-x;").parse().iterate(); + // Compare strings so +0.0 and -0.0 remain distinct. + assertEquals("0.0", Evaluator.evaluate(stop,0).toString()); + assertEquals("-1.0", Evaluator.evaluate(stop,1).toString()); + } + @Test public void testDeadNumericReturns() { for( String[] test : new String[][] { {"if(1) return 7; else return 2.5;", "7"}, |
