From 34c2efae1f2dac2449a52fd2913b4737111e692c Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 10 Aug 2026 14:40:04 -0700 Subject: Handle some escaped chars in strings Add a explicit "emit_main" flag in case you use no_run. Fix a make parallel bug --- .../src/test/java/com/seaofnodes/simple/Chapter25Test.java | 13 +++++++++++-- chapter25/src/test/java/com/seaofnodes/simple/Simple.java | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'chapter25/src/test/java/com/seaofnodes') diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java b/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java index cf9d764e..313ae1cf 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/Chapter25Test.java @@ -38,6 +38,15 @@ public class Chapter25Test { assertEquals("1",Eval2.eval(code,0)); } + @Test + public void testStringEscapes() { + String src = "u8[~] s=\"A\\n\\t\\r\\\\\\\"B\"; " + + "return s#==7 && s[0]=='A' && s[1]==10 && s[2]==9 && s[3]==13 && " + + "s[4]==92 && s[5]==34 && s[6]=='B';"; + CodeGen code = new CodeGen(src).driver(CodeGen.Phase.TypeCheck); + assertEquals("1",Eval2.eval(code,0)); + } + @Test @Ignore public void testModule0() throws IOException { @@ -197,7 +206,7 @@ public class Chapter25Test { File sys_file = buildTestSys(false); assertTrue("Missing "+sys_file+"; testHelloWorld depends on testSys building it", sys_file.exists()); - String expected = "Hello, World!"; + String expected = "Hello, World!\n"; String prog = "return sys.io.p(\""+expected+"\") - "+expected.length()+";"; TestC.run(prog,"helloWorld",new Ary<>(new String[]{SYS_BLDDIR}), TestC.CALL_CONVENTION, null, null, expected,0); @@ -223,7 +232,7 @@ public class Chapter25Test { assertTrue("Missing "+sys_file+"; testHelloWorldNoInline depends on testSys building it", sys_file.exists()); String base = "helloWorldNoInline"; - String expected = "Hello, World!"; + String expected = "Hello, World!\n"; String prog = "return sys.io.p_noInline(\""+expected+"\") - "+expected.length()+";"; CodeGen code = new CodeGen(null,"build/objs",new Ary<>(new String[]{SYS_BLDDIR}), base,prog,123L,TypeInteger.BOT); diff --git a/chapter25/src/test/java/com/seaofnodes/simple/Simple.java b/chapter25/src/test/java/com/seaofnodes/simple/Simple.java index 870792c0..35b9b922 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/Simple.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/Simple.java @@ -35,6 +35,7 @@ Options: -L path - add an external Simple object search path --eval - (slowly) evaluate the compiled code in emulator --run - run the compiled code natively; this is the default + --main - export the top-level initializer as C `main` --cpu - use specific CPU (x86_64_v2, riscv, arm) --abi - use specific ABI variant (SystemV) --target - print native CPU and ABI @@ -89,6 +90,7 @@ Options: boolean do_eval = false; boolean do_run = true; boolean do_codegen = false; + boolean emit_main = false; boolean dump_dot = false; boolean print_time = false; boolean print_size = false; @@ -129,6 +131,7 @@ Options: case "--eval": do_eval = true ; do_run = false; break; case "--run": do_run = true ; break; case "--norun": do_run = false; break; + case "--main": emit_main = true; break; case "--dump-size": print_size = true; break; case "--dump-time": print_time = true; break; case "-o": if (out != null || i + 1 >= args.length || args[i + 1].charAt(0) == '-') bad_usage(); @@ -221,7 +224,7 @@ Options: // Compilation pipeline Ary externPaths = libPaths.isEmpty() ? null : new Ary<>(libPaths.toArray(new String[0])); CodeGen code = new CodeGen(modPath.toString(), outPath.toString(), externPaths, srcName, src, 456, TypeInteger.BOT ); - code.driver(Phase.LastPhase,cpu,abi, false, do_run || do_eval, dump); + code.driver(Phase.LastPhase,cpu,abi, false, emit_main || do_run || do_eval, dump); if( do_codegen && print_asm ) System.out.println(code.asm()); -- cgit v1.2.3