Boxes
Every piece of code lives in a box drawn with slashes, dashes and bars, and every box holds one value.
Dominicentek · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Dominicentek made Boxes. A program is a set of boxes drawn in plain text, each with its name on the top edge. The boxes can stand anywhere in the source, and a box that is drawn wrongly is ignored. The run starts in the box called Main. When a box reaches its bottom it runs again from the top, so every box is a loop until something leaves it.
Read the story
A box is also a variable. Each one holds one value, a whole number or a string, 0 at first, and an instruction can read another box's value by its name. All boxes share one stack.
The machine
| Instruction | Does |
|---|---|
open B openwith B | Go into box B; openwith hands it the current value |
close return | Go back to the box that opened this one; return hands the value back |
if a is b open B | Open B if the test holds; the tests are is, not, greater and less |
else open B | Open B if the last if failed |
assign v | Set the box's value |
increase v decrease v | Add or subtract |
multiply v divide v modulo v | Multiply, divide or take the remainder |
toint tostr | Turn the value into a number or a string |
numinput input | Read a number or a line |
print v println v | Print a value; println adds a line feed |
push v pop get | Push a value, drop one, or pop one into the box |
duplicate swap reverse | Work the stack |
exit | End the run |
A value is a number, a string in double quotes, this for the box's own value, or the name of a box. close or return in Main ends the run.
Example
The truth machine reads a number into Main.
The truth machine reads a number into Main. On 0 it opens PrintZero, which prints and exits. On 1 it opens PrintOne, which prints 1 and, at its bottom, starts again forever.
Boxes can also stand side by side. Main hands its 0 to B, which prints 7, sets its own value to 5 and returns it.
The 99 bottles of beer program hands 99 to a Print box, which prints a verse, takes one down and loops until the value is 0, 99 verses in all. One line of its Main box is a character short. The specification says a box with wrong syntax is ignored, which would leave no Main at all, so this implementation lets a right border stand short of the top corner.
Further
Ideas it shows
See also
Stack-based
Write your own in Run Convert a program from Boxes
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: boxes.
Command line
shib run boxes -e '/- Main ----------------\
| print "Hello, World!" |
| exit |
\-----------------------/'shib manual boxesSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/boxes.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org