diff options
| author | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-08 14:10:02 -0800 |
| commit | 44505aa5b75b1046f13f2bc2a52fe0b16d975838 (patch) | |
| tree | cc558485c807ac3842cd73943cf5e294c4a307de /src/test/java/com/seaofnodes/simple/Chapter21Test.java | |
| parent | 2560096fb4636263798ae56c88687973c72cdf6e (diff) | |
| download | Simple-linear-chapter30.tar.gz Simple-linear-chapter30.zip | |
Chapter 30: Text Formatting and Diagnosticslinear-chapter30
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Symious <14933944+symious@users.noreply.github.com>
Co-authored-by: Jun Kawasaki <jun784@gmail.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter21Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter21Test.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/src/test/java/com/seaofnodes/simple/Chapter21Test.java index e15c2581..c6d558eb 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -17,7 +17,7 @@ import static org.junit.Assert.*; public class Chapter21Test { @Test public void testFloatToInteger() throws IOException { - String src = "val float_to_int={ flt x -> int i=x; return i; };"+ + String src = "val float_to_int={ flt x -> i64 i=x; return i; };"+ "val float_to_u8={ flt x -> u8 i=x; return i; };"; TestC.runC(src,"floatToInteger","",-1); for( double x : new double[]{0.0,-0.0,6.92,-6.92,255.75,-257.75, @@ -138,9 +138,10 @@ public class Chapter21Test { String src = """ val sum = { int n -> if( n<=0 ) return 1; - return sum(n-1)+n; + int prev=n-1; + return sum(prev)+n; }; - val run = { int n -> return sum(n)+sum(n+1); }; + val run = { int n -> int next=n+1; return sum(n)+sum(next); }; """; assertTrue("Ordinary calls must survive optimization",checkArmCalls(src,"run",4,27)>0); } @@ -157,7 +158,7 @@ public class Chapter21Test { buf=buf2; }; val add = { int e -> - if( len>=buf# ) grow(buf#*2); + if( len>=buf# ) { int size=buf#*2; grow(size); } buf[len++]=e; return self; }; @@ -323,9 +324,9 @@ for( int i=0; i<ary#-1; i++ ) ary[i+1] += ary[i]; return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 """; - testCPU(src,"x86_64_v2", "SystemV",-1,"return mov(.[]);"); - testCPU(src,"riscv" , "SystemV", 7,"return (add,.[],(mul,.[],1000));"); - testCPU(src,"arm" , "SystemV", 5,"return (add,.[],(mul,.[],1000));"); + testCPU(src,"x86_64_v2", "SystemV",-1,"return (add,.[],(muli,.[]));"); + testCPU(src,"riscv" , "SystemV",9,"return (add,.[],(mul,.[],1000));"); + testCPU(src,"arm" , "SystemV",13,"return (add,.[],(mul,.[],1000));"); } @Test @@ -384,7 +385,7 @@ val hashCode = { !String self -> }; """; // Return the public hashCode wrapper; keep its helper private. - testCPU(src,"x86_64_v2", "SystemV",12,null); + testCPU(src,"x86_64_v2", "SystemV",28,null); testCPU(src,"riscv" , "SystemV",8,null); testCPU(src,"arm" , "SystemV",6,null); } @@ -423,7 +424,7 @@ val hashCode = { !String self -> : (self._hashCode = _hashCodeString(self)); }; """; - TestC.runC(src, "stringHash", "",12); + TestC.runC(src, "stringHash", "",28); } @Test public void testLoop2() { @@ -439,9 +440,9 @@ while(true) { } return i; """; - testCPU(src,"x86_64_v2", "win64" ,0,"return (!=0)(inc,Phi(Loop,0,Phi(Region,(!=0),(!=0),0)));"); - testCPU(src,"riscv" , "SystemV",0,"return (!=0)( Phi(Loop,0,Phi(Region,(!=0),(!=0),0)) + #1 );"); - testCPU(src,"arm" , "SystemV",0,"return (!=0)(inc,Phi(Loop,0,Phi(Region,(!=0),(!=0),0)));"); + testCPU(src,"x86_64_v2", "win64" ,0,"return (!=0)(sari,(shli,(inc,Phi(Loop,0,Phi(Region,(!=0),(!=0),0)))));"); + testCPU(src,"riscv" , "SystemV",0,"return (!=0)( ( ( Phi(Loop,0,Phi(Region,(!=0),(!=0),0)) + #1 ) << #32 ) >> #1056 );"); + testCPU(src,"arm" , "SystemV",0,"return (!=0)(asri,(lsli,(inc,Phi(Loop,0,Phi(Region,(!=0),(!=0),0)))));"); } @Test public void testNewtonExport() throws IOException { @@ -530,7 +531,7 @@ val sieve = { int N -> String sprimes = sb.p("]").toString(); // Compile, link against native C; expect the above string of primes to be printed out by C - TestC.runC(src, "sieve", sprimes, 186); + TestC.runC(src, "sieve", sprimes,344); // Evaluate on RISC5 emulator; expect return of an array of primes in // the simulated heap. |
