Esolang: AGAIN
AGAIN is a pathologically structured, multistack assembly language. The only memory the machines has is a collection of indexible stacks. Possibly circular haven't decided on that. The language has one syntatic blocks: IF ... END. The only means of jumping to a new location is AGAIN, which only jumps to the start of the program. The core language is defined by the following primitive instructions:
PUSH ( value index [index] -- [index]:value )- Pushes a
valueto the provided stackindex. POP ( index [index]:value -- value [index] )- Pops a value from the provided stack
index. PEEK ( index [index]:value -- value [index]:value )- Reads a value from the top of the provided stack
index. PEEKAT ( index o [index@o]:value -- value [index@o]:value)- Reads a
valueat someoffsetfrom the top of the provided stackindex. DROP ( value -- )- Drops a vaue from the main stack.
DUP ( value -- value value )- Duplicates value on main stack.
AGAIN ( -- )- Jumps to the top of the program.
ADD ( x y -- x+y )- Adds
ytox SUB ( x y -- x-y )- Subtracts
yfromx MUL ( x y -- x*y )- Multiply
xbyy DIV ( x y -- x/y )- Divides
ybyx EQU ( x y -- x=y )- Takes two values on the main stack, returns if they are equal.
GTH ( x y -- x>y )- Takes two values on the main stack, returns if
x > y LTH ( x y -- x<y )- Takes two values on the main stack, returns if
x < y SHOW ( x -- )- Prints the number on the stack to the console
EMIT ( x -- )- Prints the number on the stack as its ASCII value to the console.
I don't really have any additional specs for this machine. Basically a rough sketch, don't even have an interpreter for it actually.
Example
This (probably) implements a factorial function. I don't have an interpreter so this is more an idea of it.
'main 1 PUSH
1 PEEK 'main EQUALS IF
1 POP DROP
10 1 PUSH 'factorial 1 PUSH 'run 1 PUSH
END
1 PEEK DUP 'run EQUAL IF
1 1 PEEKAT 'factorial IF
1 POP DROP
1 POP DROP
1 POP 2 PUSH
'values 1 PUSH 'factorial
END
END
1 PEEK 'factorial EQUAL IF
1 1 PEEKAT 'values EQUAL IF
2 PEEK 1 SUB 2 PUSH
2 PEEK 1 > IF
AGAIN
END
1 DROP 'product 1 PUSH
END
1 1 PEEKAT 'product EQUAL IF
2 POP 2 POP DUP IF
MUL 2 PUSH AGAIN
END
END
1 POP DROP
1 POP DROP
END
2 POP SHOW