From a04599b6fc90bbab443d883595a415238586a526 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 18 Aug 2024 10:37:43 -0700 Subject: Shift operators; sign extension --- .../java/com/seaofnodes/simple/Chapter14Test.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'chapter14/src/test/java/com') diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java index f76e1903..268111d8 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java @@ -89,4 +89,30 @@ return f.b; assertEquals("return 1;", stop.toString()); assertEquals(1L, Evaluator.evaluate(stop, 0)); } + + @Test + public void testSigned() { + Parser parser = new Parser( +""" +i8 b = 255; // Chopped +return b; // Sign extend +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return -1;", stop.toString()); + assertEquals(-1L, Evaluator.evaluate(stop, 0)); + } + + @Test + public void testMask() { + Parser parser = new Parser( +""" +u16 mask = (1<<16)-1; // AND mask +int c = 123456789 & mask; +return c; // +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return 52501;", stop.toString()); + assertEquals(52501L, Evaluator.evaluate(stop, 0)); + } + } -- cgit v1.2.3