Interstack
A stack, one value cell and loops that count. Every loop knows how often it runs before it starts.
PythonshellDebugwindow, 2019 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
PythonshellDebugwindow made Interstack in November 2019, first under the name Brainstack. It mixes a stack with a little of brainfuck. Values live on the stack or in one value cell, and all of them are bytes from 0 to 255 that wrap round. Input, output and arithmetic go through the value cell.
Read the story
The only loop is (, which runs as many times as the value cell says when it starts. Changing the value inside does not change the count. So every program stops, and the specification says the language is total. To make a choice, a program leaves a loop early with ;, or it uses /, which turns the character three places further on into a : that does nothing.
The machine
| Command | Does |
|---|---|
+ | Push the value, then set it to 0 |
^ @ | Pop the top into the value; copy the top into it |
% _ | Swap the top and the value; set the top to the value, then the value to 0 |
& | Add the value to the top, then set the value to 0 |
~ | Reverse the stack |
* # | Set the value to 0; to 65 |
< > | Take 1 off the value; add 1 |
? ! | Read a line, the value being the sum of its character codes; print the value's character |
( ) ; | Loop as many times as the value says; end the loop; leave it |
/ : | Turn the character three places on into :; do nothing |
. | Halt |
The specification leaves a pop from an empty stack, a ; outside a loop and a / on a bracket undefined. This implementation makes them errors. It also says that a program that runs % more than once must end in a ., or it does not end well. This implementation makes that an error too.
Example
Hello, world.
Hello, world. # starts the value at 65 and seven > make it 72, an H. After a value of 10, (>>>>>>>>>) adds 9 ten times, which gives 100. Values it needs again, such as e, l and the space, wait on the stack.
The sum of two characters, one per line. 0 is 48 and 1 is 49, so it prints 97, which is a.
The comparison takes the second character from the first in a loop, pushes N and Y, and runs (/;) on the difference. When the difference is not 0 the loop runs once, and / blanks the first ^ after it, so the program prints N and not Y.
The truth machine on 0 prints 0. On 1 it nests four loops of 255 and prints 255 to the fourth plus one characters, 4,228,250,626 of them, as the specification says. A loop that never ends cannot be written.
Patterns it teaches
- Stack machines: a stack and one register in front of it.
- Self-modifying code:
/rewrites the program to make a choice.
Further
See also
Stack-based
Write your own in Run Convert a program from Interstack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: interstack.
Command line
shib run interstack -e '?+?&^!' --input '0
1'shib manual interstackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/interstack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org