From ff2c72dd5f9b7ccf7f24402e95cc9372e6439dc2 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Wed, 30 Apr 2025 10:47:38 -0700 Subject: "default main" requires a `return expr`, or else its just dead. Empty program can make an empty elf. Bug ShlNode losing precision. --- .../src/test/java/com/seaofnodes/simple/Chapter09Test.java | 13 +++++++------ .../src/test/java/com/seaofnodes/simple/Chapter10Test.java | 1 + .../src/test/java/com/seaofnodes/simple/Chapter11Test.java | 4 ++-- .../src/test/java/com/seaofnodes/simple/Chapter13Test.java | 3 ++- .../src/test/java/com/seaofnodes/simple/Chapter15Test.java | 2 ++ .../src/test/java/com/seaofnodes/simple/Chapter18Test.java | 3 ++- .../src/test/java/com/seaofnodes/simple/Chapter19Test.java | 1 + .../src/test/java/com/seaofnodes/simple/Chapter21Test.java | 6 +++--- .../src/test/java/com/seaofnodes/simple/Chapter22Test.java | 7 ++++++- chapter22/src/test/java/com/seaofnodes/simple/Eval2.java | 1 + 10 files changed, 27 insertions(+), 14 deletions(-) (limited to 'chapter22/src/test') diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java index 401f346f..a4aade16 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter09Test.java @@ -128,14 +128,14 @@ while(v1+arg) { } """); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test public void testWhile0() { - CodeGen code = new CodeGen("while(0) continue; if(0) arg=0;"); + CodeGen code = new CodeGen("while(0) continue; if(0) arg=0; return arg;"); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("return arg;", code.print()); } @Test @@ -145,6 +145,7 @@ if(0) while(0) { int arg=arg; while(0) {} } +return 0; """); code.parse().opto(); assertEquals("return 0;", code.print()); @@ -221,7 +222,7 @@ while(1) { } """); code.parse().opto(); - assertEquals("return Top;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test @@ -255,7 +256,7 @@ while(0==1) while(v0) v0=1+v0; """); code.parse().opto(); - assertEquals("return 0;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test @@ -271,7 +272,7 @@ while(1) return v1+v0; """); code.parse().opto(); - assertEquals("return Top;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter10Test.java index 1253e4a6..b7d65b95 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -304,6 +304,7 @@ if(0) { v0=v2; } } +return 0; """); code.parse().opto(); assertEquals("return 0;", code.print()); diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java index f6539ac4..1fb9f75a 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter11Test.java @@ -435,7 +435,7 @@ while(1) arg = arg+ptr.v; """); code.parse().opto(); - assertEquals("return Top;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test @@ -527,7 +527,7 @@ while(0>=0) { return 0; """); code.parse().opto(); - assertEquals("return Top;", code.print()); + assertEquals("Stop[ ]", code.print()); } @Test diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter13Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter13Test.java index 6bf45a22..a4644917 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter13Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter13Test.java @@ -130,7 +130,7 @@ return n.i; @Test public void testNullRef4() { - CodeGen code = new CodeGen("-null-5/null-5;"); + CodeGen code = new CodeGen("return -null-5/null-5;"); try { code.parse().opto().typeCheck(); fail(); } catch( Exception e ) { assertEquals("Cannot 'Add' null",e.getMessage()); } } @@ -146,6 +146,7 @@ return n.i; CodeGen code = new CodeGen( """ struct S{}; +return 0; """); code.parse().opto(); assertEquals("return 0;", code.print()); diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter15Test.java index 8b138b46..cebbf4a0 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -323,6 +323,7 @@ while(0) {} u32 v7=0; int v8=0; while(0<--1>>>---(v7*0==v8)) {} +return 0; """); code.parse().opto(); assertEquals("return 0;", code.print()); @@ -347,6 +348,7 @@ else { } } } +return 0; """); code.parse().opto(); assertEquals("return 0;", code.print()); diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter18Test.java index c0e28412..9c8ad66c 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -214,7 +214,7 @@ val fcn = { Person?[] ps, int x -> var ps = new Person?[2]; ps[0] = new Person; ps[1] = new Person; -fcn(ps,1); +return fcn(ps,1); """); code.driver(Phase.LocalSched); assertEquals("return 0;", code._stop.toString()); @@ -249,6 +249,7 @@ for(;;) { if (i2i(2) == arg) break; i2i = null; } +return 0; """); try { code.parse().opto().typeCheck(); fail(); } catch( Exception e ) { assertEquals("Might be null calling { int -> int #1}?",e.getMessage()); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java index bce75c81..f06d8a6a 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter19Test.java @@ -271,6 +271,7 @@ for( int i=0; i