Marbelous

Marbelous is a two-dimensional esoteric programming language based on numbered marbles falling down a Rube-Goldberg-like board full of devices that move and manipulate the marbles.

History
Creation of this language was inspired by conversation in the Programming Puzzles & Code Golf Stack Exchange chat room, forked to a dedicated chat room later.

Credit for the original idea goes to cjfaure. Additional language design input from Martin Büttner, Nathan Merrill, overactor, sparr, githubphagocyte, es1024, VisualMelon.

Etymology
Marbelous is a portmanteu of "marble" and "marvelous".

Language overview
A Marbelous program consists of one or more two-dimensional "boards". Each board represents a function that can be called during execution, and the first board is called when the program is starte.

Boards may begin with some pre-defined marbles in specific locations, as well as marbles based on parameters passed to the function. There is also a provision for producing a marble containing the value of a byte from stdin. During execution, marbles will fall down a board and interact with the devices that they encounter, sometimes moving in directions other than downwards, sometimes having their value changed.

Instructions
Marbelous has the following devices:

Any device whose defined name ends with "n" actually has 36 variations, from _0 to _Z With the exception of ^n, which has 8 variations, form ^0 to ^7.

Computational class
It is believed that Marbelous is not currently Turing Complete, despite allowing recursion. It is probably a Linear bounded automaton.

Interpretation
The marbelous.py interpreter will run a .mbl program taken from a file. Parameters to the main board may be provided as decimal integers in additional command line arguments. The interpreter also handles stdin and stdout for the program.

Examples
48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21
 * 1) prints out "Hello, world!"

}0 .. }1 \\ {0 //
 * 1) {0 = }0 + }1

.. }1 }1 }1 }1 }1 }1 }1 }1 00 ^7 ^6 ^5 ^4 ^3 ^2 ^1 ^0 .. =1 =1 =1 =1 =1 =1 =1 =1 .. &7 &6 &5 &4 &3 &2 &1 &0 .. }0 .. .. .. .. .. .. .. .. &7 }0 .. .. .. .. .. .. .. << &6 }0 .. .. .. .. .. .. << << &5 }0 .. .. .. .. .. << << << &4 }0 .. .. .. .. << << << << &3 }0 .. .. .. << << << << << &2 }0 .. .. << << << << << << &1 }0 .. << << << << << << << &0 {0 // // // // // // // //
 * 1) {0 = }0 * }1
 * 2) masks out bits of }1
 * 3) shifts copies of }0 left that many times
 * 4) sums shifted copies


 * 1) calculates the nth fibonacci number, recursively.
 * Fb

}0 }0 }0 .. # three copies of }0, call them A B C -- &0 >1 {0 # decrement A, hold B for sync, return C if it's <2 &0 -- >4 -- # hold A for sync, decrement B, divert and decrement C if it's <5 -- Fb &0 {0 # decrement A, recurse with B, release sync or return C-1 Fb .. \/ .. # recurse with A, do nothing with B, trash C \\ {0 .. .. # add A to B and return it
 * 1) pseudocode equivalent:
 * 2) fib(x):
 * 3)   A=B=C=x
 * 4)   A--
 * 5)   if C<2:
 * 6)     return C
 * 7)   B--
 * 8)   if C<5:
 * 9)     C--
 * 10)     return C
 * 11)   A--
 * 12)   B=fib(B)
 * 13)   A=fib(A)
 * 14)   return A+B