diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-08 16:52:27 -0700 |
| commit | d32f97238c903765dec4e9a9f3cbfa5fd12cded6 (patch) | |
| tree | a5ac731801ef7066bab6359c4e85c2bdd20082a6 /src/test/java/com/seaofnodes/simple/Chapter17aTest.java | |
| parent | b5ebb2032aa04cf4506d533127d373d4cf5a25c6 (diff) | |
| download | Simple-linear.tar.gz Simple-linear.zip | |
Chapter 25: Modules, Separate Compilation, and SSA Constructionlinear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter17aTest.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter17aTest.java | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter17aTest.java b/src/test/java/com/seaofnodes/simple/Chapter17aTest.java index 8597b799..52acff57 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter17aTest.java +++ b/src/test/java/com/seaofnodes/simple/Chapter17aTest.java @@ -24,8 +24,8 @@ return y; @Test public void testConstruct1() { CodeGen code = new CodeGen(""" -struct X { int ~x; }; -X z = new X { x=3; }; +struct _X { int ~x; new _X = { int xx -> x=xx; }; }; +_X z = new _X(3); return z.x; """); code.parse().opto(); @@ -36,20 +36,20 @@ return z.x; @Test public void testStructFinal0() { CodeGen code = new CodeGen(""" -struct Point { int ~x, ~y; }; -Point p = new Point { x=3; y=4; }; +struct _Point { int ~x, ~y; new _Point = { int xx, int yy -> x=xx; y=yy; }; }; +_Point p = new _Point(3,4); return p; """); code.parse().opto(); - assertEquals("return (const)Point;", code.print()); - assertEquals("Point{x=3,y=4}", Eval2.eval(code, 0)); + assertEquals("return (const)Test._Point;", code.print()); + assertEquals("Test._Point{x=3,y=4}", Eval2.eval(code, 0)); } @Test public void testStructFinal1() { CodeGen code = new CodeGen(""" -struct Point { int x=3, y=4; }; -~Point p = new Point { x=5; y=6; }; +struct _Point { int x=3, y=4; new _Point = { int xx, int yy -> x=xx; y=yy; }; }; +~_Point p = new _Point(5,6); p.x++; return p; """); @@ -60,8 +60,8 @@ return p; @Test public void testStructFinal2() { CodeGen code = new CodeGen(""" -struct Point { int x=3, y=4; }; -~Point p = new Point; +struct _Point { int x=3, y=4; }; +~_Point p = new _Point; p.x++; return p; """); @@ -71,18 +71,21 @@ return p; @Test public void testStructFinal3() { - for( String fields : new String[] { "var x; var y;", "int[] !x;", "int[] !x;" } ) { - String src = "struct Point { "+fields+" }; Point p = new Point; p.x++; return p;"; - try { new CodeGen(src).parse().opto(); fail(fields); } - catch( Exception e ) { assertEquals("'Point' is not fully initialized, field 'x' needs to be set in a constructor",e.getMessage()); } - } + CodeGen code = new CodeGen(""" +struct _Point { var x; var y; }; +_Point p = new _Point; +p.x++; +return p; +"""); + try { code.parse().opto(); fail(); } + catch( Exception e ) { assertEquals("'Test._Point' is not fully initialized, field 'x' needs to be set in a constructor",e.getMessage()); } } @Test public void testStructFinal4() { CodeGen code = new CodeGen(""" -struct Point { val x=3; val y=4; }; -Point p = new Point; +struct _Point { val x=2; val y=4; }; +_Point p = new _Point; p.x++; return p; """); @@ -93,14 +96,14 @@ return p; @Test public void testStructFinal5() { CodeGen code = new CodeGen(""" -struct Point { var x=3; var y=4; }; -!Point !p = new Point; +struct _Point { var x=3; var y=4; }; +!_Point !p = new _Point; p.x++; return p; """); code.parse().opto(); - assertEquals("return Point;", code.print()); - assertEquals("Point{x=4,y=4}", Eval2.eval(code, 0)); + assertEquals("return Test._Point;", code.print()); + assertEquals("Test._Point{x=4,y=4}", Eval2.eval(code, 0)); } } |
