Starfish

*><> (pronounced as "starfish") is a stack-based, reflective, two-dimensional esoteric programming language based directly off of ><>. It was created by redstarcoder in 2016.

Concepts
* ><> is a two-dimensional language, meaning the code is not necessarily executed in a linear manner. Using various instructions, the direction the code is read can be changed to either up, down, left or right. It is also a stack-based language, so all operations are performed on a stack. You can also store and retrieve values in the codebox, so making a proper compiler is very hard, if not impossible.

The goal of *><> is to make ><> more useful, while still keeping the language in the spirit of ><>. Currently *><> adds file i/o, the ability to keep track of time, and a new dive/rise concept. If feasible, some sort of graphical output may be within the scope too.

See ><>#Concepts for more information.

Code execution
See ><>#Code Execution for more information.

Functions (call/ret)
Functions in *><> work similar to call and ret in asm. To use them, put the codebox coordinate for where you want to jump to on the stack (See  usage for details), and call. This will cause the IP to jump to the desired location, saving the previous location on the stack below the current one. So you could actually jump back using, but you'd lose the current register:

<;o&C10&a .{{]

Results in:

< ;  o *&* C  1  0  &  a   .  {  {  ] Stack: [] something smells fishy...

or "ret", solves this problem by simply jumping to the coordinates on the stack below the current one, then moving the current stack down:

<;o&C10&a R

And this code results in a newline being outputted ( ==   ==  ), instead of an error. See "Functions" for a complete example.

Dive / rise
Dive and rise are special instructions which manipulate the IP's ability to execute most instructions, they are  and , respectively. Dive causes the IP to ignore all instructions except movement and mirror instructions. Rise causes the IP to behave normally again.

Fisherman
The fisherman instruction is the backtick. The first time any fisherman instruction is executed while the IP is moving horizontally, the IP is instructed to move down, the next time, the IP is is instructed to move up. When the IP executes the instruction moving vertically, it is instructed to move in the last horizontal direction it moved in. This allows a swap in the flow of logic, allowing you to more easily do work on a lower line, and have the IP continue back on the line it was originally. Here's a basic program demonstrating that concept to output "Hi" without using the fisherman instruction:

"Hi"rv>; lo<^!?

You can see that to output "Hi" and still execute  to exit on the same line uses four instructions. One to instruct the IP in moving each direction (Down, left, up, then right). With the fisherman instruction, this becomes two:

"Hi"r`; l?!`o

The IP here, using just two fisherman instructions, still moves in 4 directions (Down, right, up, then right again).

Stacks
See ><>#Stacks for more information.

Input/output
* ><> has three input/output instructions:  for input and  /  for output. The  instruction simply reads a character from stdin or a file opened with. If no more input is available,  pushes. Note that there is no instruction to input a number, you will have to parse the characters yourself.

While parsing numbers is not very hard, it makes for slow and possibly glitchy programs. Most programs requiring number input reads it from the stack at program start. This is done with an interpreter that supports pre-populating the stack with values. Doing so with the starfish interpreter looks like this:

$ starfish -i 10 -code "2*n;" 20

Output is a bit easier, as you have two instructions:  and. They will pop a value and output it as a character and a number, respectively. The output is naturally written to stdout.

Errors
The following events will cause an error in *><>:


 * Division by zero
 * Reaching an invalid instruction
 * Trying to pop or modify on the stack when it is empty or has too few values
 * If the interpreter does not support arbitrary-precision numbers, an overflow results in an error

Although there are multiple reasons an error may occur, there is only one error message: something smells fishy...

Instructions
The following is merely a draft of the instructions in *><>, and is subject to change. Instructions are case-sensitive.

Input/output
See Input/output.

Reflection/miscellaneous
The space character is simply a NOP and is allowed anywhere.

Examples
All the examples are executed using the go-starfish interpreter.

Hello, world!
"Hello, world!"r>Ool?u!|;

$ starfish helloworld.sf Hello, world!

File i/o
Opens "hello.txt", outputs its contents, and clears it. "hello.txt"lF\ v!?+1:i< ~      r  ov!?l< F0<;

$ starfish fileio.sf Hello *><>!

Digital clock
>s":"m":"hnonon"  "ooo1S\ \                ;?+1iod/

$ starfish clock.sf 16:34:33

Functions
Calls the function at, and exits. <;C10 v"It works!" l?!;

$ starfish stackselect.sf Hello World

See a more in-depth example here.

See the ><> page for more examples.

go-starfish
The "official" interpreter, or the one written by the author. The latest release is available here. For usage information, run it with the -h switch.

*><>
An online interpreter written by the author. It's currently hosted here (mirror (outdated)).