diff options
| author | Cliff Click <cliffc@acm.org> | 2026-11-08 15:05:54 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-11-12 13:48:30 -0800 |
| commit | a269fa7e8aea51b4fbdd2f2c6c24e84ef26f9ca4 (patch) | |
| tree | 90108fb0ffd70f3b9e7bedcaacfd6cdaccb48885 /chapter31/src/test/java/com/seaofnodes | |
| parent | 6fb3aac50c642ed73ec78e9ceb6e04b127796abb (diff) | |
| download | Simple-a269fa7e8aea51b4fbdd2f2c6c24e84ef26f9ca4.tar.gz Simple-a269fa7e8aea51b4fbdd2f2c6c24e84ef26f9ca4.zip | |
Brainfuck uses aryu8
Diffstat (limited to 'chapter31/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter31/src/test/java/com/seaofnodes/simple/BrainFuckTest.java | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/chapter31/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter31/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index 166f5c5e..07e702c7 100644 --- a/chapter31/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/chapter31/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -1,18 +1,21 @@ package com.seaofnodes.simple; import com.seaofnodes.isa.eval.EvalRisc5; - import com.seaofnodes.isa.eval.EvalArm64; - import java.io.IOException; - import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.Test; +import static org.junit.Assert.assertEquals; 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 +23,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 +37,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 +60,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); |
