summaryrefslogtreecommitdiff
path: root/chapter22/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2025-05-10 13:03:20 -0700
committerCliff Click <cliffc@acm.org>2025-05-10 13:03:20 -0700
commitdac097b61e847395a1526d4ecd593c25cdf5fd3c (patch)
tree12865388a265a76dcd1dada50910d93cf05a5655 /chapter22/src/test/java/com/seaofnodes
parent288912d2a84d035730cad405e32a6afa5dd4f9c6 (diff)
downloadSimple-dac097b61e847395a1526d4ecd593c25cdf5fd3c.tar.gz
Simple-dac097b61e847395a1526d4ecd593c25cdf5fd3c.zip
Remove some junk sign extends
Diffstat (limited to 'chapter22/src/test/java/com/seaofnodes')
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java4
-rw-r--r--chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp92
2 files changed, 7 insertions, 89 deletions
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
index 4823dff8..bfb20705 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
+++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java
@@ -15,8 +15,8 @@ public class Chapter22Test {
@Test @Ignore
public void testJig() throws IOException {
- //String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
- String src = Files.readString(Path.of("docs/examples/BubbleSort.smp"));
+ String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp"));
+ //String src = Files.readString(Path.of("docs/examples/BubbleSort.smp"));
testCPU(src,"x86_64_v2", "Win64" ,-1,null);
testCPU(src,"riscv" , "SystemV",-1,null);
testCPU(src,"arm" , "SystemV",-1,null);
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp b/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
index 70f45717..fd3e7b9c 100644
--- a/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
+++ b/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp
@@ -1,88 +1,6 @@
// -*- mode: java; -*-
-
-val _exit = { u8[~] msg ->
- sys.io.p(msg);
- sys.libc._exit(1);
-};
-val usage = { -> _exit("stdin must look like [4, 3, 2, 1]"); };
-
-// Scanner
-struct Scan {
- int !x;
- u8[~] buf;
-};
-
-// Skip whitespace
-val skip = { Scan s ->
- while( s.buf[s.x] <= 32 )
- s.x++;
-};
-
-// Require specific syntax or usage
-val require = { Scan s, u8 c ->
- skip(s);
- if( s.buf[s.x++] != c )
- usage();
-};
-
-val peek = { Scan s, u8 c ->
- skip(s);
- if( s.buf[s.x] != c ) return false;
- s.x++;
- return true;
-};
-
-val number = { Scan s ->
- skip(s);
- i32 n = 0;
- while( '0' <= s.buf[s.x] & s.buf[s.x] <= '9' )
- n = n*10 + (s.buf[s.x++] - '0');
- return n;
-};
-
-
-// Read from stdin a line of the form "[ 4, 3, 2, 1]" and print it sorted.
-val main = { ->
- Scan !s = new Scan{ buf = sys.io.stdin(); };
- require(s,'[');
- // Array of parsed results
- int[] !ns = new int[16];
- i32 num = 0;
- // Parse a list of numbers
- if( !peek(s,']') ) { // Handle the empty list
- // Parse "123, " until a something else
- while( s.x < s.buf# ) {
- int n = number(s);
- i32 q=n;
- ns[num++] = n;
- if( !peek(s,',') )
- break;
- };
- require(s,']'); // Close the list
- }
-
- // Print a list of numbers
- sys.io.p("[ ");
- u8[] !buf = new u8[20];
- for( int i=0; i<num; i++ ) {
- int x = ns[i];
- if( !x ) { sys.io.p("0, "); continue; }
-
- u32 log=0, q=x;
- while( q>0 )
- { q/=10; log++; }
- i32 raw=log;
- sys.libc._exit(raw);
- // for( int j=0, a=x; j<log; j++ ) {
- // q = x/10;
- // buf[log-j] = '0'+(x-q*10);
- // x = q;
- // }
- // int raw = buf;
- // sys.libc.write(1,raw,log);
- // sys.io.p(", ");
- }
- sys.io.p("]");
-
- return num;
-};
+// Should fold away sign extend
+struct Person { i8 age;};
+Person !p = new Person;
+p.age = (arg<<48)>>48;
+return 0;