From f4bd723d929e53475f7990374dca7b7dfcbbdc42 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 1 Nov 2026 10:33:55 -0800 Subject: Add Chapter 29 for tech debt cleanup with the parser split Keep Chapter 28b intact and carry the grammar-oriented parser package, Var move, IterPeeps move, and parser regression tests into Chapter 29. Defer privacy and exclude its experimental tests and fixture changes. Register the chapter in the indexes, IntelliJ modules and run configurations, Maven reactor, roadmap, and linear-history publisher. Windows and Linux each pass 573 tests, release builds, 199 allocation replays, and 29 native checks. --- .../com/seaofnodes/simple/PrefixUpdateTest.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 chapter29/src/test/java/com/seaofnodes/simple/PrefixUpdateTest.java (limited to 'chapter29/src/test/java/com/seaofnodes/simple/PrefixUpdateTest.java') diff --git a/chapter29/src/test/java/com/seaofnodes/simple/PrefixUpdateTest.java b/chapter29/src/test/java/com/seaofnodes/simple/PrefixUpdateTest.java new file mode 100644 index 00000000..71612cc0 --- /dev/null +++ b/chapter29/src/test/java/com/seaofnodes/simple/PrefixUpdateTest.java @@ -0,0 +1,58 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import org.junit.Test; +import static org.junit.Assert.*; + +public class PrefixUpdateTest { + @Test public void testMethodFieldWrites() { + String[] fields = {"int x=0", "int x=3", "u8 x=0", "f32 x=0"}; + String[] updates = {"++x", "--x", "++x", "++x"}; + String[] results = {"221", "112", "221", "221.0"}; + for(int i=0;i "+updates[i]+"; }; }; " + +"var c=new C; val a=c.change_noInline(); val b=c.change_noInline(); return a+10*b+100*c.x;"; + CodeGen code=new CodeGen(src,seed,true).driver(CodeGen.Phase.TypeCheck); + assertEquals(fields[i],results[i],Eval2.eval(code,0)); + } + } + + @Test public void testLocalAndFinalUpdates() { + CodeGen code=new CodeGen("int x=arg; return ++x*100 + --x*10 + x;").driver(CodeGen.Phase.TypeCheck); + assertEquals("433",Eval2.eval(code,3)); + code=new CodeGen("struct C { int x=7; val f={int x -> ++x;}; }; var c=new C; return c.f(3)+10*c.x;") + .driver(CodeGen.Phase.TypeCheck); + assertEquals("74",Eval2.eval(code,0)); + for(String src:new String[]{"val x=1; return ++x;", + "struct C { val x=1; val f={ -> ++x; }; }; var c=new C; return c.f();"}) { + try { + new CodeGen(src).driver(CodeGen.Phase.TypeCheck); + fail("final update"); + } catch(RuntimeException e) { + assertTrue(e.getMessage(),e.getMessage().contains("final")); + } + } + } + + @Test public void testNativeByteOverflow() throws java.io.IOException { + String src="val prefixUpdate={int arg -> " + +"struct C { u8 x=255; val inc_noInline={ -> ++x; }; }; " + +"var c=new C; val a=c.inc_noInline(); val b=c.inc_noInline(); return a+10*b+100*c.x; };"; + var dir=java.nio.file.Path.of("build/objs"); + java.nio.file.Files.createDirectories(dir); + var driver=dir.resolve("prefixUpdate.c"); + java.nio.file.Files.writeString(driver,""" + __attribute__((CALL_CONV)) extern long long prefixUpdate(long long); + int main(void) { return prefixUpdate(0)!=110; } + """); + String abi=TestC.OS.startsWith("Windows") ? "ms_abi" : "sysv_abi"; + TestC.run(src,"prefixUpdate",null,TestC.CALL_CONVENTION,abi,driver.toString(),"",-1); + } + + @Test public void testModuleFieldWrites() { + CodeGen code=new CodeGen("int calls=0; val next_noInline={ -> ++calls; }; return next_noInline()+10*next_noInline();") + .driver(CodeGen.Phase.TypeCheck); + assertEquals("21",Eval2.eval(code,0)); + } +} -- cgit v1.2.3