diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-08 15:01:35 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-08 15:01:35 -0800 |
| commit | 394f0aba21eb7a73a00014b3ffcf2ad21eeb8e21 (patch) | |
| tree | fbaf83c18ca6cc620bddee9a0264fb4e762f9eb1 | |
| parent | 06fb5aceeb65a75b1cd643debd667c52fdcafcb9 (diff) | |
| download | Simple-394f0aba21eb7a73a00014b3ffcf2ad21eeb8e21.tar.gz Simple-394f0aba21eb7a73a00014b3ffcf2ad21eeb8e21.zip | |
BrainFuck uses aryu8
| -rw-r--r-- | chapter28b/Makefile | 4 | ||||
| -rw-r--r-- | chapter28b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java | 25 | ||||
| -rw-r--r-- | chapter29/Makefile | 4 | ||||
| -rw-r--r-- | chapter29/src/test/java/com/seaofnodes/simple/BrainFuckTest.java | 25 | ||||
| -rw-r--r-- | chapter30/Makefile | 4 | ||||
| -rw-r--r-- | chapter30/src/test/java/com/seaofnodes/simple/BrainFuckTest.java | 25 |
6 files changed, 54 insertions, 33 deletions
diff --git a/chapter28b/Makefile b/chapter28b/Makefile index ec59a033..5e176674 100644 --- a/chapter28b/Makefile +++ b/chapter28b/Makefile @@ -187,8 +187,8 @@ tests_raw1: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_raw1) -# Larger standalone tests, still JUnits, still no sys.smp -tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) +# Larger regressions, including BrainFuck's standard-library buffer variant. +tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) $(RELEASE_SYS) @echo "testing " $(test_alone) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_alone) diff --git a/chapter28b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter28b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index c2713e4f..d7b259ed 100644 --- a/chapter28b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/chapter28b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -5,14 +5,15 @@ import com.seaofnodes.isa.eval.EvalRisc5; import com.seaofnodes.isa.eval.EvalArm64; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class BrainFuckTest { - @Test public void testBrainFuck() throws IOException { + @Test public void testBrainFuckAryu8() throws IOException { String brain_fuck = "Hello World!\n"; String src = """ @@ -20,7 +21,7 @@ public class BrainFuckTest { val brain_fuck = { -> var !program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; int d = 0; - u8[] !output = new u8[0]; + val output = new sys.aryu8(); u8[] !data = new u8[100]; for( int pc = 0; pc < program#; pc++ ) { @@ -34,12 +35,7 @@ val brain_fuck = { -> } else if (command == '-') { data[d]--; } else if (command == '.') { - // Output a byte; increase the output array size - var old = output; - output = new u8[output# + 1]; - for( int i = 0; i < old#; i++ ) - output[i] = old[i]; - output[old#] = data[d]; // Add the extra byte on the end + output.add(data[d]); } else if (command == ',') { data[d] = 42; } else if (command == '[') { @@ -62,7 +58,18 @@ val brain_fuck = { -> } return output; }; +val main = { -> + brain_fuck().write(sys.libc.STDOUT); + return 0; +}; """; + TestC.runSYS(src,"brain_fuck_aryu8",brain_fuck,-1); + } + + @Test public void testBrainFuck() throws IOException { + // Retain the original workload for cross-target allocation comparisons. + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/spill/BrainFuckTest-testBrainFuck.smp")); + String brain_fuck = "Hello World!\n"; TestC.runC(src,"brain_fuck", brain_fuck, 40); EvalRisc5 R5 = TestRisc5.build( src, "brain_fuck", 0, 25, false); diff --git a/chapter29/Makefile b/chapter29/Makefile index ec59a033..5e176674 100644 --- a/chapter29/Makefile +++ b/chapter29/Makefile @@ -187,8 +187,8 @@ tests_raw1: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_raw1) -# Larger standalone tests, still JUnits, still no sys.smp -tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) +# Larger regressions, including BrainFuck's standard-library buffer variant. +tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) $(RELEASE_SYS) @echo "testing " $(test_alone) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_alone) diff --git a/chapter29/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter29/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index c2713e4f..d7b259ed 100644 --- a/chapter29/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/chapter29/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -5,14 +5,15 @@ import com.seaofnodes.isa.eval.EvalRisc5; import com.seaofnodes.isa.eval.EvalArm64; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class BrainFuckTest { - @Test public void testBrainFuck() throws IOException { + @Test public void testBrainFuckAryu8() throws IOException { String brain_fuck = "Hello World!\n"; String src = """ @@ -20,7 +21,7 @@ public class BrainFuckTest { val brain_fuck = { -> var !program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; int d = 0; - u8[] !output = new u8[0]; + val output = new sys.aryu8(); u8[] !data = new u8[100]; for( int pc = 0; pc < program#; pc++ ) { @@ -34,12 +35,7 @@ val brain_fuck = { -> } else if (command == '-') { data[d]--; } else if (command == '.') { - // Output a byte; increase the output array size - var old = output; - output = new u8[output# + 1]; - for( int i = 0; i < old#; i++ ) - output[i] = old[i]; - output[old#] = data[d]; // Add the extra byte on the end + output.add(data[d]); } else if (command == ',') { data[d] = 42; } else if (command == '[') { @@ -62,7 +58,18 @@ val brain_fuck = { -> } return output; }; +val main = { -> + brain_fuck().write(sys.libc.STDOUT); + return 0; +}; """; + TestC.runSYS(src,"brain_fuck_aryu8",brain_fuck,-1); + } + + @Test public void testBrainFuck() throws IOException { + // Retain the original workload for cross-target allocation comparisons. + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/spill/BrainFuckTest-testBrainFuck.smp")); + String brain_fuck = "Hello World!\n"; TestC.runC(src,"brain_fuck", brain_fuck, 40); EvalRisc5 R5 = TestRisc5.build( src, "brain_fuck", 0, 25, false); diff --git a/chapter30/Makefile b/chapter30/Makefile index e4537ca4..c2bf21f1 100644 --- a/chapter30/Makefile +++ b/chapter30/Makefile @@ -203,8 +203,8 @@ tests_raw1: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_raw1) -# Larger standalone tests, still JUnits, still no sys.smp -tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) +# Larger regressions, including BrainFuck's standard-library buffer variant. +tests_alone: $(CLZDIR)/main/.mtag $(CLZDIR)/test/.ttag $(RELEASE_CRT) $(RELEASE_SYS) @echo "testing " $(test_alone) @[ -d $(OBJS) ] || mkdir -p $(OBJS) @$(JVM) org.junit.runner.JUnitCore $(test_alone) diff --git a/chapter30/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter30/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index 166f5c5e..63858df0 100644 --- a/chapter30/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/chapter30/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -5,14 +5,15 @@ import com.seaofnodes.isa.eval.EvalRisc5; import com.seaofnodes.isa.eval.EvalArm64; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; public class BrainFuckTest { - @Test public void testBrainFuck() throws IOException { + @Test public void testBrainFuckAryu8() throws IOException { String brain_fuck = "Hello World!\n"; String src = """ @@ -20,7 +21,7 @@ public class BrainFuckTest { val brain_fuck = { -> var !program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; int d = 0; - u8[] !output = new u8[0]; + val output = new sys.aryu8(); u8[] !data = new u8[100]; for( int pc = 0; pc < program#; pc++ ) { @@ -34,12 +35,7 @@ val brain_fuck = { -> } else if (command == '-') { data[d]--; } else if (command == '.') { - // Output a byte; increase the output array size - var old = output; - output = new u8[output# + 1]; - for( int i = 0; i < old#; i++ ) - output[i] = old[i]; - output[old#] = data[d]; // Add the extra byte on the end + output.add(data[d]); } else if (command == ',') { data[d] = 42; } else if (command == '[') { @@ -62,7 +58,18 @@ val brain_fuck = { -> } return output; }; +val main = { -> + brain_fuck().write(sys.libc.STDOUT); + return 0; +}; """; + TestC.runSYS(src,"brain_fuck_aryu8",brain_fuck,-1); + } + + @Test public void testBrainFuck() throws IOException { + // Retain the original workload for cross-target allocation comparisons. + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/spill/BrainFuckTest-testBrainFuck.smp")); + String brain_fuck = "Hello World!\n"; TestC.runC(src,"brain_fuck", brain_fuck,165); EvalRisc5 R5 = TestRisc5.build( src, "brain_fuck", 0, 25, false); |
