Starry

From Esolang
Jump to navigation Jump to search

Starry, designed by Yutaka Hara in 2008 for his book, Rubyで作る奇妙なプログラミング言語, is a stack-based esoteric programming language. The book discusses the implementation of esolangs in Ruby; Starry is used as an example language.

Syntax

The only meaningful characters are space and +*.,`' -- all other characters are ignored. Each sequence of spaces followed by non-space character represents a single instruction.

Instructions

Spaces Final Description
0 + Invalid opcode.
1 + Duplicate top of stack.
2 + Swap top 2 stack elements.
3 + Rotate top 3 stack elements.
4 + Pop top of stack.
n ≥ 5 + Push n − 5 to stack.
0 mod 5 * Pop y, pop x, push x + y.
1 mod 5 * Pop y, pop x, push x − y.
2 mod 5 * Pop y, pop x, push x * y.
3 mod 5 * Pop y, pop x, push x / y.
4 mod 5 * Pop y, pop x, push x mod y.
0 mod 2 . Pop a value and print it as a number.
1 mod 2 . Pop a value and print it as an ASCII character.
0 mod 2 , Read a number from input.
1 mod 2 , Read an ASCII value from input.
n ` Mark label n.
n ' Pop a value; if non-zero, jump to label n.

Computational class

Stack values are unbounded; using the swap, add, subtract, label, and "branch if non-zero" instructions, conversion from a 2-register Minsky machine is trivial. Therefore, Starry is Turing complete.

Examples

Hello, world!

            +               +  *       +    
 * + .        +              +  *       +   
  *     * + .            +     * + . + .    
    +     * + .              +            + 
 *         +     * * + .                 + *
 + .              + +  *           +     *  
   * + .             + * + .        +     * 
+ .           + * + .             + * + .   
           +            +  *         +     *
 * + .

Fibonacci numbers

     +      + ` +   +     * +
  .               + . + '

Disassembled:

[[:push, 0],
 [:push, 1],
 [:label, 1],
 [:dup],
 [:rotate],
 [:+],
 [:dup],
 [:num_out],
 [:push, 10],
 [:char_out],
 [:dup],
 [:jump, 1]]

See also

External resources