diff options
| author | Cliff Click <cliffc@acm.org> | 2025-01-18 11:57:15 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-01-18 11:58:47 -0800 |
| commit | 366059262e7360e07955c0a1f41ad89ffe44423b (patch) | |
| tree | d00af977595bc798fa32f8003b809792e478e9ca /chapter18/src/test/java/com/seaofnodes | |
| parent | ce7b66515e23cff79ad5cd64e47a54872047495e (diff) | |
| download | Simple-366059262e7360e07955c0a1f41ad89ffe44423b.tar.gz Simple-366059262e7360e07955c0a1f41ad89ffe44423b.zip | |
Minor bugfix, allow "ptr.fld op= expr" form
Diffstat (limited to 'chapter18/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java | 26 | ||||
| -rw-r--r-- | chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java | 17 |
2 files changed, 39 insertions, 4 deletions
diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java index 98c30721..8ec95f33 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter17Test.java @@ -8,11 +8,11 @@ public class Chapter17Test { @Test public void testJig() { - CodeGen code = new CodeGen(""" + CodeGen code = new CodeGen( +""" int i = 0; i=i=1; return i; - //return 3.14; """); code.parse().opto(); assertEquals("return 1;", code.print()); @@ -157,14 +157,14 @@ return s.x; } @Test public void testVar4() { - CodeGen code = new CodeGen("struct S{int x;}; S s; s=new S; s.x++; return s.x; // Ok, no initializer so x is mutable "); + CodeGen code = new CodeGen("struct S{int x;}; S? s; s=new S; s.x++; return s.x; // Ok, no initializer so x is mutable "); code.parse().opto(); assertEquals("return 1;", code.print()); assertEquals("1", Eval2.eval(code, 0)); } @Test public void testVar5() { - CodeGen code = new CodeGen("struct S{int x;}; S s; s=new S{x=3;}; s.x++; return s.x; // Ok, no initializer so x is mutable "); + CodeGen code = new CodeGen("struct S{int x;}; S? s; s=new S{x=3;}; s.x++; return s.x; // Ok, no initializer so x is mutable "); code.parse().opto(); assertEquals("return 4;", code.print()); assertEquals("4", Eval2.eval(code, 0)); @@ -293,6 +293,24 @@ return x; catch( Exception e ) { assertEquals("Cannot reassign final 'x'",e.getMessage()); } } + @Test + public void testVar17() { + CodeGen code = new CodeGen( +""" +struct Person { + bool focused; +}; +val focus = { Person p -> + p.focused = true; +}; +Person me; // Person !me = new Person; +focus(me); +return me; +""" +); + try { code.parse().opto().typeCheck(); fail(); } + catch( Exception e ) { assertEquals("Syntax error, expected =expression: ;",e.getMessage()); } + } // --------------------------------------------------------------- @Test diff --git a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java index 1d7abde5..60f9b847 100644 --- a/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/chapter18/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -325,4 +325,21 @@ return f2f(o)(1); assertEquals("Stop[ return Phi(Region,o( arg),o( 1)); return Parm_i(o,int,arg,1); ]", code._stop.toString()); assertEquals("1", Eval2.eval(code, 2)); } + + @Test + public void testOperField() { + CodeGen code = new CodeGen( +""" +struct Person { + int coffee_count; +}; +Person !p = new Person; +p.coffee_count += 1; +return p.coffee_count; +"""); + code.parse().opto().typeCheck().GCM().localSched(); + assertEquals("return 1;", code._stop.toString()); + assertEquals("1", Eval2.eval(code, 2)); + } + } |
