esolang

Beebles

A two-stack language whose interpreter hates its job and may quit if you do not flatter it.

2012 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hi

The idea

Beebles is a stack language from 2012, and Beebles is also the name of its interpreter. The specification says the interpreter really hates its job. It gets angry at code without comments, at two commands on one line, at more than 30 numbers on a stack, at swearing and at nop. It gets happier when you push primes, use loops and write I love Beebles in a comment. Angry enough, it ends the program with one line, Beebles got angry and crashed the program.

Read the story

The specification gives no rule for the moods, only chances. This implementation leaves them out, so Beebles never quits on its own. The specification counts the language as bounded because of the limit of 30 numbers; this implementation has no limit.

The machine

Every command ends in a semicolon. There are two stacks of bytes, and one of them is current.

CommandDoes
push nPush n
popPop the top
outc outiPrint the top as a character or as a number
getcRead a character and push it
add nPush the top plus n, keeping the top below it
flipMake the other stack current
kickMove the top to the other stack
label n goto nMark a place; jump there if the top is not 0
killEnd the program
rem text nopA comment; nothing

Numbers wrap at 256, so add 255 takes one away. There is no other way to subtract.

Example

A string goes on the stack backwards behind a 0.

A string goes on the stack backwards behind a 0. The loop prints and pops until the 0 is on top.

Expected: 6

A cat. goto 1 jumps forward past kill while the character read is not 0, and getc pushes 0 at the end of the input.

Expected: cat

The Hello World program pushes the primes from 2 to 17 on the second stack to please Beebles. Its last loop prints them too, as 7 control characters after Hello, World! and a line feed. The 99 bottles of beer program prints all 100 verses. It counts down with add 255 and kicks each new number to the other stack.

Patterns it teaches

  • Stack machines: two stacks, and kick moves a value between them.
  • Hostile design: an interpreter with moods, which this implementation leaves out.

Further

Stack-based

Write your own in Run Convert a program from Beebles

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: beebles.

Command line

shib run beebles program.txt

The program is long; save it as program.txt first.

shib manual beebles

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/beebles.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org