Slim
Seven commands on a stack of bits. The only jump goes to the nth colon, n being the number of 1s it just threw away.
Scoppini, 2015 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Scoppini made Slim in 2015. The stack holds bits and starts empty. There are no numbers and no labels. The one control command, :, pops the 1s off the top, counts them and jumps to the colon with that number. So a program lays down a run of 1s to say where to go next.
Read the story
@ flips the top bit and sends it to the bottom, and < brings the bottom bit back to the top. The stack can be turned round like a ring.
The machine
| Command | Does |
|---|---|
0 | Push a 0 |
@ | Flip the top bit and move it to the bottom |
< | Move the bottom bit to the top |
X | Pop |
^ | Print the top bit, without popping it |
| | Push the next bit of input |
: | On a 1, pop the 1s on top and jump to the colon with that number |
Bits go out and come in eight to a byte, the highest first. With one bit on the stack @ just flips it, and that is all the Hello, World! program does. Its 104 ^ print Hello World! and a line feed.
The interpreter is a download that is not in the specification, so a few things are this implementation's choice. Other characters are passed over, after the end of the input | pushes 0, and taking from an empty stack is an error.
Example
The cat starts with nine 1s, so its first : jumps to the ninth colon, at the start of the last line.
The cat starts with nine 1s, so its first : jumps to the ninth colon, at the start of the last line. There it reads a byte bit by bit. Each 0 bit is flipped to a 1 and sent to the bottom, and the first 1 bit makes : pop them all and jump to the line that prints a byte with that many 0s in front. That line lays down nine 1s again for the way back. A byte of 0 leaves a 0 on top at the last :, and the run ends there.
The truth machine reads the eight bits of a 0 or a 1 and throws away the first seven. On 0 it prints 0 and ends. On 1 the eighth : pops nine 1s and jumps to the ninth, the line after it prints 1 and lays down nine 1s, and the last : sends it back there forever.
Patterns it teaches
- Stack machines: a stack of bits that also turns at its bottom, with a jump counted in popped 1s.
Further
See also
Stack-based
Write your own in Run Convert a program from Slim
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: slim.
Command line
shib run slim -e '0@0@0@0@0@0@0@0@0@|
:X|
:X|@<
:X|@<
:X|
:X|
:X|
:XX|
:^^@^^@<^^^^@0@
:0^^@^^@^^^@^0@0@0@0@0@0@0@0@
:' --input '0'shib manual slimSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/slim.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org