From dead068fc0e3d637419fa5508c32856bc8340dc9 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 18 Aug 2024 09:40:56 -0700 Subject: handle all unsigned int variants and-masking and typenames for all! --- .../java/com/seaofnodes/simple/Chapter12Test.java | 2 +- .../java/com/seaofnodes/simple/Chapter14Test.java | 44 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'chapter14/src/test/java/com') diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java index 8eceb0fa..99c08f16 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter12Test.java @@ -169,6 +169,6 @@ n.i = 3.14; return n.i; """); try { parser.parse(true).iterate(true); fail(); } - catch( Exception e ) { assertEquals("Cannot store 3.14 into field IntBot i",e.getMessage()); } + catch( Exception e ) { assertEquals("Cannot store 3.14 into field int i",e.getMessage()); } } } diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java index 4bf04b88..f76e1903 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java @@ -42,11 +42,51 @@ return c; """ u8 b = 123; b = b + 456;// Truncate -return 67; +return b; """); StopNode stop = parser.parse(false).iterate(false); assertEquals("return 67;", stop.toString()); - assertEquals(67, Evaluator.evaluate(stop, 0)); + assertEquals(67L, Evaluator.evaluate(stop, 0)); } + @Test + public void testU1() { + Parser parser = new Parser( +""" +bool b = 123; +b = b + 456;// Truncate +u1 c = b; // No more truncate needed +return c; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 1;", stop.toString()); + assertEquals(1L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testAnd() { + Parser parser = new Parser( +""" +int b = 123; +b = b+456 & 31; // Precedence +return b; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 3;", stop.toString()); + assertEquals(3L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testRefLoad() { + Parser parser = new Parser( +""" +struct Foo { u1 b; } +Foo f = new Foo; +f.b = 123; +return f.b; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 1;", stop.toString()); + assertEquals(1L, Evaluator.evaluate(stop, 0)); + } } -- cgit v1.2.3