esolang

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

Expected: Hello, World!

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

InstructionDoes
open B openwith BGo into box B; openwith hands it the current value
close returnGo back to the box that opened this one; return hands the value back
if a is b open BOpen B if the test holds; the tests are is, not, greater and less
else open BOpen B if the last if failed
assign vSet the box's value
increase v decrease vAdd or subtract
multiply v divide v modulo vMultiply, divide or take the remainder
toint tostrTurn the value into a number or a string
numinput inputRead a number or a line
print v println vPrint a value; println adds a line feed
push v pop getPush a value, drop one, or pop one into the box
duplicate swap reverseWork the stack
exitEnd 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.

Expected: 0

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.

Expected: 75

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

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 boxes

Source

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