From 2aa8c5d1d0659bd1c828134f1a1f14d025a2d0f1 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 7 Feb 2025 08:58:36 -0800 Subject: Ch# Chapter 19: Instruction Selection and Portable Compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hadha Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com> --- .../java/com/seaofnodes/simple/Chapter04Test.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/test/java/com/seaofnodes/simple/Chapter04Test.java') diff --git a/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/src/test/java/com/seaofnodes/simple/Chapter04Test.java index afed67d1..d09b1748 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter04Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter04Test.java @@ -34,14 +34,14 @@ public class Chapter04Test { public void testAddAddMul() { CodeGen code = new CodeGen("return arg+0+arg;"); code.parse(); - assertEquals("return (arg*2);", code.print()); + assertEquals("return (arg<<1);", code.print()); } @Test public void testPeephole3() { CodeGen code = new CodeGen("return 1+arg+2+arg+3; "); code.parse(); - assertEquals("return ((arg*2)+6);", code.print()); + assertEquals("return ((arg<<1)+6);", code.print()); } @Test @@ -62,8 +62,7 @@ public class Chapter04Test { // Adding functions means `main` does not constant fold the incoming arg value @Ignore @Test public void testConstantArg() { - CodeGen code = new CodeGen("return arg; ", TypeInteger.constant(2)); - code.parse(); + CodeGen code = new CodeGen("return arg; ", TypeInteger.constant(2), 123L).parse(); assertEquals("return 2;", code.expr().in(1).toString()); } @@ -111,12 +110,8 @@ public class Chapter04Test { @Test public void testBug3() { - try { - new Parser("inta=1; return a;").parse(); - fail(); - } catch( RuntimeException e ) { - assertEquals("Undefined name 'inta'",e.getMessage()); - } + try { new CodeGen("inta=1; return a;").parse(); fail(); } + catch( RuntimeException e ) { assertEquals("Undefined name 'inta'",e.getMessage()); } } @Test @@ -128,8 +123,8 @@ public class Chapter04Test { @Test public void testBug5() { - Parser parser = new Parser("return arg--2;"); - StopNode ret = parser.parse(); - assertEquals("return (arg--2);", ret.print()); + CodeGen code = new CodeGen("return arg--2;"); + code.parse(); + assertEquals("return (arg--2);", code.print()); } } -- cgit v1.2.3