From 0f56449bc90e77cc9a0e490413585a8823bc1bf2 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 6 Sep 2024 09:32:28 -0700 Subject: Fix bugs AND on floats Shift-extend idiom smartly makes sharper int types. --- .../java/com/seaofnodes/simple/Chapter07Test.java | 1 - .../java/com/seaofnodes/simple/Chapter14Test.java | 25 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'chapter14/src/test') diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter07Test.java index f9251be7..faa81347 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter07Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter07Test.java @@ -1,7 +1,6 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.node.*; -import com.seaofnodes.simple.type.TypeInteger; import org.junit.Test; import static org.junit.Assert.*; diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java index 8b3c3c9a..962b8e4d 100644 --- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java +++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java @@ -115,6 +115,19 @@ return b; // Sign extend assertEquals(-1L, Evaluator.evaluate(stop, 0)); } + @Test + public void testI8() { + Parser parser = new Parser( +""" +i8 b = arg; +b = b + 1;// Truncate +return b; +"""); + StopNode stop = parser.parse(false).iterate(false); + assertEquals("return (((((arg<<56)>>56)+1)<<56)>>56);", stop.toString()); + assertEquals(1L, Evaluator.evaluate(stop, 0)); + } + @Test public void testMask() { Parser parser = new Parser( @@ -128,6 +141,18 @@ return c; // assertEquals(52501L, Evaluator.evaluate(stop, 0)); } + @Test + public void testMaskFloat() { + Parser parser = new Parser( +""" +flt f = arg; +arg = f & 0; +return arg; +"""); + try { parser.parse(true).iterate(true); fail(); } + catch( Exception e ) { assertEquals("Cannot '&' FltBot",e.getMessage()); } + } + @Test public void testTypes() { Parser parser = new Parser( -- cgit v1.2.3