Leocode

From Esolang
Jump to navigation Jump to search

Leocode is a two dimensional programming language invented by me. It is inspired by Befunge, Branflakes and Calvinball, a game in the Calvin and Hobbes where the rules are made up as the game progresses.

Similar to the game mentioned, what each instruction does can be changed anywhere in the middle of the program with non-ASCII characters (each ASCII character is given an instruction).

Syntax and semantics

Each program can contain up to 23 instruction pointers or 'players', written with the Greek letters α, β... all the way up to ω. ο is skipped because it looks too much like the Latin letter o. Each player has their own stack of 64-bit floats. There is also a both-sides infinite tape of 64-bit floats, which can be modified by any of the instruction pointers.

A 'string' on a stack is 0 followed by the character codes in reverse order.

Enough said, here are the 100 basic instructions (popping and pushing are done on the corresponding player's stack):

   ← - start going left
   → - start going right
   ↑ - start going up
   ↓ - start going down
   ↔ - reverse direction
   ↕ - random direction
   space - NOP
   ! - skip next instruction
   " - start string mode. All ASCII characters between 32 and 126 inclusive push their charcodes until the next ".
   # - pop and print as decimal number
   $ - swap
   % - a, b -- a % b with the sign of a
   & - a, b -- a && b (logical AND)
   ' - next ASCII character will push its character code instead of executing the instruction
   ( - a -- a - 1
   ) - a -- a + 1
   * - a, b -- a * b
   + - a, b -- a + b
   , - input single char and push its value
   - - a, b -- a - b
   . - pop and print as Unicode character
   / - a, b -- a / b
   0 - push 0
   1 - push 1
   2 - push 2
   3 - push 3
   4 - push 4
   5 - push 5
   6 - push 6
   7 - push 7
   8 - push 8
   9 - push 9
   : - dup
   ; - pop and discard
   < - a, b -- a<b ? 1 : 0
   = - a, b -- a==b ? 1 : 0 
   > - a, b -- a<b ? 1 : 0
   ? - pop a, skip next instruction if a == 0
   @ - input single decimal number and push
   A - push 10
   B - push 11
   C - push 12
   D - push 13
   E - push 14
   F - push 15
   G - pop a, b, set tape[b] to a
   H - toggle hyperbolic for trigonometric functions (starts off)
   I - toggle inverse for trigonometric functions (starts off)
   J - pop strings a[] then b[], push a[] concatenated with b[]
   K - pop string a[] then value b, push a[b] (zero indexed)
   L - pop string, push length
   M - pop strings a[] then b[], push initial index of first position of b[] in a[] (zero indexed, -1 if not found)
   N - pop strings a[], b[] then c[], push a[] with all b[] replaced by c[]
   O - modified over. Pop a, duplicate stack item a (zero indexed)
   P - pop a, push tape[a] (or 0)
   Q - quine. Push the source code as a string.
   R - pop string, then all input reads from that .txt file
   S - a, b -- a & b (bitwise AND)
   T - a, b -- a | b (bitwise OR)
   U - a -- ~a (bitwise NOT)
   V - a, b -- a ^ b (bitwise XOR)
   W - pop string, then all output writes into that .txt file
   X - close all previously opened .txt files
   Y - pop string a[] then values b then c, push substring of a[] from b to c (inclusive, zero indexed)
   Z - pop a, sleep for a seconds
   [ - a -- floor(a)
   \ - a -- int(a) (remove decimal part)
   ] - a -- ceil(a)
   ^ - a, b -- a ** b
   _ - a, b -- log_b(a)
   ` - start number mode. All characters between this and the next ` is pushed as a decimal number, NaN if invalid number.
   a - empty the stack
   b - bye. End the program early.
   c - a -- cos(a)
   d - dive or rise. All instructions except ←, →, ↑, ↓, ↔, ↕ and d will be ignored until another d is encountered.
   e - push Euler's number
   f - pop a, then push index of first occurrence of a in stack (except this one, zero indexed starting from top, -1 if not found)
   g - shuffle the stack.
   h - pop a, set maximum stack size to a (NOP when trying to push when stack is at its max, infinity means no bound)
   i - push infinity
   j - rot. a b c -- b c a
   k - rotcc. a b c -- c a b
   l - push length of stack
   m - a -- -a
   n - push NaN
   o - a b c == a ? b : c, all values except 0 and NaN are truthy.
   p - push pi
   q - turn the stack into a queue, another q turns it back into a stack.
   r - reverse stack
   s - a -- sin(a)
   t - a -- tan(a)
   u - toggle stack popping mode (start on, if off, does not pop values from the stack)
   v - pop string, convert into number and push. NaN if invalid number.
   w - pop a, push a as string
   x - toggle arithmetic shifts to logical, and remainder to modulo (starts off)
   y - pop a, run Unicode character a as instruction
   z - kicks a player out of the program, when all players are kicked out, the program ends
   { - a, b -- a << b (arithmetic left shift)
   | - a, b -- a || b (logical OR)
   } - a, b -- a >> b (arithmetic right shift)
   ~ - a -- !a (logical NOT)