BitBounce
One long string of bits. Its first bits say how wide a cell is, and the program may rewrite them.
Hakerh400, 2019 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Hakerh400 made BitBounce in 2019 as a step towards proving that his Bitwise Trance is Turing complete. The plan is a BitBounce interpreter written in Bitwise Trance. The specification says that has not been done yet, and that BitBounce itself is only probably Turing complete.
Read the story
The source is 0s and 1s, and every other character is a comment. Those bits are the whole memory, zeros beyond. Before each instruction the memory is cut into 2^n cells of n bits, each read lowest bit first. Cell 0 holds n - 4, cell 1 points to the two registers IP and SP, and the stack grows down from SP. All of them live in plain memory, so any write can move them, and a write to cell 0 changes how every bit is read.
The machine
The instruction is the lowest 4 bits of the cell at IP. Operands are popped from the top of the stack.
| Opcode | Name | Does |
|---|---|---|
| 0 | CONST | Push the next cell; IP moves by 2 |
| 1 | JZ | Pop an address and a value, jump there if the value is 0 |
| 2 | CALL | Pop an address, push the return address, jump |
| 3 | RET | Pop an address and jump |
| 4 5 | PUSH POP | Copy the top; drop it |
| 6 7 | GET SET | Read or write the cell an offset away from SP |
| 8 9 | READ WRITE | Read or write the cell at an address |
| 10 11 | NEG IMP | Flip every bit; not a, or b |
| 12 13 | SHL ADD | Shift left, right when the amount is negative; add |
| 14 15 | IN OUT | Push the next input bit; output the lowest bit |
Input is each byte's bits, lowest first, each after a 1, then zeros for ever. Output bits pair up. A pair that starts with 1 adds its second bit, and a pair that starts with 0 ends the run. That is the only way to halt.
Example
A program that flips the lowest bit of the first byte.
A program that flips the lowest bit of the first byte. Its first four cells make cells of 8 bits, put the registers at cell 2, start at cell 5 and put the stack at cell 255. Cell 4 is a flag set to 1. The loop reads a flag bit and copies it out, reads a data bit and calls the function at cell 17, which reads the flag, clears it and adds it to the bit. So only the first bit changes, and 1, 0x31, becomes 0.
The cat is the same program with the flag at 0.
The Hello, World! program uses cells of 10 bits. It keeps a 1 on the stack and copies it out as the flag before each of its 104 bits. Then it pushes 15 and runs on through empty memory, where every cell reads as CONST 0, and over its own stack. At cell 1020 the 15 and the 1 it left there read as CONST 15 and JZ, which jumps to cell 15, an OUT, and that outputs a 0 flag. The whole run takes 667 steps.
Patterns it teaches
- Stack machines: the stack pointer is an ordinary cell.
- Self-modifying code: IP, SP and the cell width are all memory.
- Encoding tricks: n - 4 is stored as Bitwise Trance stores an address.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from BitBounce
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bitbounce.
Command line
shib run bitbounce -e '1110000001000000101000001111111100000000011100001111000001110000000000001000100001000000111100000000
0000000000000000000010100000100000000000000001000000011000000000000000100000000100000000000000000000
0000000000100000100100001011000000000000110000001110000011' --input 'Hello'shib manual bitbounceSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/bitbounce.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org