From 366059262e7360e07955c0a1f41ad89ffe44423b Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 18 Jan 2025 11:57:15 -0800 Subject: Minor bugfix, allow "ptr.fld op= expr" form --- .../java/com/seaofnodes/simple/Chapter17Test.java | 26 ++++++++++++++++++---- .../java/com/seaofnodes/simple/Chapter18Test.java | 17 ++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'chapter18/src/test/java/com/seaofnodes') 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)); + } + } -- cgit v1.2.3