Complode

From Esolang
Jump to: navigation, search

Complode is a stack-based language with not very many commands.

Command Description
numbers Push a number to stack. It can be any integer.
/ Do a calculation (read the instructions below).
(code) Create a code-block and push to stack.
.name(code) Define a macro. Each name macro can be defined only once.
,name Use a macro.
 ; Comment until end of line.
_I Input one byte, push to stack
_O Pop from stack and output one byte

The calculation is:

  1. Pop A
  2. Pop B
  3. Pop C
  4. Pop E
  5. Pop F
  6. Pop Z
  7. If A>0 Then Let G=var(A) Else Pop G
  8. If B>0 Then Let H=var(B) Else Let H=G
  9. If C>0 Then Let var(C)=E
  10. If B>0 Then Let var(B)=F*G
  11. If Z>0 Then Push H+F+E
  12. If Z<0 And A<0 And B<0 Then it will push a list of all variables -A to -B and their values (as a single entry) to a stashing stack
  13. If Z<0 And A=0 And B=0 Then it will pop one entry from the stashing stack and restore all of the values of those variables
  14. If Z=0 And A<0 Then Push F*E

If a code-block is popped during this calculation, it is looped, at the beginning of the loop it pops a value from the stack and if it is zero it stops the loop, and pops again the value it was trying before, and if is also a code-block it does again with this code-block, until it is a number; the exception is "Pop G" which does not loop and keeps the code-block as is, and then if it is part of an addition or multiplication the numbers in that calculation are ignored and the result is just the code-block. Popping an empty stack returns zero.

Examples

Some useful macros:

.dup(
 0 -1 0 0 0 -1 -1 /
 0 1 0 0 1 0 /
 1 0 0 0 0 1 /
 1 0 0 0 0 1 /
 0 -1 0 0 0 0 0 /
)
.discard( 0 0 0 0 0 0 / )
.swap(
 0 -1 0 0 0 -2 -1 / ; stash var(1) and var(2)
 0 1 0 0 1 0 / ; store to var(1)
 0 1 0 0 2 0 / ; store to var(2)
 1 0 0 0 0 1 / ; get from var(1)
 1 0 0 0 0 2 / ; get from var(2)
 0 -1 0 0 0 0 0 / ; unstash var(1) and var(2)
)
.setvar(
 0 -1 0 0 0 -1 -1 / 0 1 0 0 1 0 /
 0 1 0 0 1 0 0 0 0 1 / 0 0 -1 0 0 0 0 0 / /
)