Headache

WORK IN PROGRESS

Commands
Headache is a double stack based language with only a few commands. It has no other way to store data than its two stacks. Both stacks start empty. You can only work with one stack at a time.

It is called headache because of the amount of switching, restacking, moving, and shuffling needed to get anything done.

A peek from an empty stack produces 1. A pop from an empty stack produces 0.

<   Pushes a pop from Stack B onto Stack A (top value of b is moved to a) >    Pushes a peek from Stack A onto Stack B (copies top of a onto b) ^    Discards the top value of Stack A. (pop if it matters) v   Swaps the top values of Stack A and Stack B. (pop both) +   a = a + b (adds top of b to the top of a) (peek only) -   a = a - b (subtracts top of b from the top of a) (peek only) .   Pop value from Stack A to output ,   Push value from input to Stack A

@   Switch Stacks (a is now b, and b is now a)

{   if a == b, Jump to after corresponding } (peek) }   if a != b, Jump to after corresponding { (peek)

LAME COMMANDS: !   Places a 1 on the top of stack A.
 * 1)    Places a number with the size of each stack on top of the corresponding stack.

The stacks usually hold 32 bit integers. If there is no corresponding { or }, ignore it.

Adding from an empty stack, produces a 1. Since it is peeking. If say, top of Stack A is 4, and Stack B is empty, a + will produce 5. If both are empty, a + will push 1 to Stack A.

Hello World (Branchless)
There is likely a more optimal way +>+>+>+@^@+>@^^@v<@+++++++v<++>@<.+++v@<><.+++++++>>><<<..+++><.<>+< v@<@+++><.>++<.+++..-.@^^+.

GNU Cat
+vv{,.}

Multiply Program
Takes the numbers on the top of both the stacks and multiplies them. Places the multiplied number on top of Stack A. Consumes both numbers. !>-><<@<<<{@<<@v^v< Faster @<@><@

Invert N
Invert top 3 values @<v<v@<v<

Invert top 4 values @<v<v<v@<v<v@<v@<<

Invert top 5 values @<v<v<v<v@<v<v<v@<v<v@<v<<

Invert top 6 values @<v<v<v<v<v@         < <          >^ +          !>^+<^ -          !>^-<^ [          !>-<^>^{<^ ]          !>-<^>^}<^ .          ><.,          ^,

Links
MindGrind - Headache Editor (Java Jar, with source)

See also - Another Headache Language