diff options
Diffstat (limited to 'chapter22/src')
4 files changed, 31 insertions, 27 deletions
diff --git a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java index 1dc6db5b..0cf7f254 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/Chapter22Test.java @@ -49,14 +49,9 @@ return cc.cz; } @Test @Ignore - public void testNo() { - String src = "val foo = { int arg -> 3; };"; - CodeGen code = new CodeGen(src).parse().opto().typeCheck(); - } - - @Test @Ignore public void testHelloWorld() throws IOException { - TestC.run("helloWorld", 9); + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/helloWorld.smp")); + TestC.run(src,TestC.CALL_CONVENTION,null,null,"build/objs/helloWorld","","Hello, World!",0); } diff --git a/chapter22/src/test/java/com/seaofnodes/simple/TestC.java b/chapter22/src/test/java/com/seaofnodes/simple/TestC.java index 5609758b..e772ab07 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/TestC.java +++ b/chapter22/src/test/java/com/seaofnodes/simple/TestC.java @@ -35,29 +35,32 @@ public abstract class TestC { // Compile and export Simple String src = Files.readString(Path.of(sfile)); - _run(src,CALL_CONVENTION,"",cfile,efile,"S",expected,spills); + run(src,CALL_CONVENTION,"",cfile,efile,"S",expected,spills); } - static void _run( String src, String simple_conv, String c_conv, String cfile, String efile, String xtn, String expected, int spills ) throws IOException { + public static void run( String src, String simple_conv, String c_conv, String cfile, String efile, String xtn, String expected, int spills ) throws IOException { String bin = efile+xtn; String obj = bin+".o"; // Compile simple, emit ELF CodeGen code = new CodeGen(src).driver( CPU_PORT, simple_conv, obj); // Compile the C program - var params = new String[] { - //if (USE_WSL) "wsl.exe"; - "gcc", - cfile, - obj, + var params = new Ary<>(String.class); + params.add("gcc"); + if( cfile!=null ) params.add(cfile); // Associated C driver, usually has a `main` + params.addAll(new String[] { "-lm", // Picks up 'sqrt' for newtonFloat tests to compare "-g", "-o", bin, - "-D", - "CALL_CONV="+c_conv, - }; - Process gcc = new ProcessBuilder(params).redirectErrorStream(true).start(); + }); + // Calling convention for C calls, if any + if( cfile!=null ) { + params.add("-D"); + params.add("CALL_CONV="+c_conv); + } + + Process gcc = new ProcessBuilder(params.asAry()).redirectErrorStream(true).start(); byte error; try { error = (byte)gcc.waitFor(); } catch( InterruptedException e ) { throw new IOException("interrupted"); } String result = new String(gcc.getInputStream().readAllBytes()); diff --git a/chapter22/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp b/chapter22/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp index 0234aa73..97400501 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp +++ b/chapter22/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp @@ -1,2 +1,2 @@ // -*- mode: java; -*- -sys.libc.write(1,"Hello, World!\n",14); +return sys.libc.write(1,"Hello, World!\n",14); 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 00c2a161..073200e3 100644 --- a/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp +++ b/chapter22/src/test/java/com/seaofnodes/simple/progs/jig.smp @@ -1,9 +1,15 @@ // -*- mode: java; -*- -struct s0 { - i16 v1; - u8 v2; -}; -s0 !l4Hi9BCnsd = new s0; -if( new s0.v2+arg ) - while(1) l4Hi9BCnsd=new s0; -while(new s0.v2+new s0.v1<=0) {} +//8942465726750756914 +while(0) { + struct s0 { + byte v0; + i32 v1; + i8 v2; + }; + s0 !JHRiBybfX=new s0; + while(1<<JHRiBybfX.v2) {} + int v3=JHRiBybfX.v1; + while(JHRiBybfX.v2) + v3=JHRiBybfX.v0; +} +return 0;
\ No newline at end of file |
