AlphaStack
Only the 26 lower case letters count, and each one is a value, an instruction and a register.
Glax, 2026 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 26 known programs · Test method
Run it
The idea
Glax made AlphaStack in 2026. As a value a letter is a number, a is 0 and z is 25, and all arithmetic wraps at 26. As an instruction it does one thing to a value stack or to a procedure stack. And every letter names a register, and some of these change how their own instruction works. The p register picks how p prints, and the a register picks what a computes.
Read the story
A run starts in literal mode, where every letter is pushed. l switches to instructions and back, so l itself can never be pushed. Programs make one with arithmetic instead, kb and then a, which adds 10 and 1.
There is no syntax for a procedure. d pops the letters between two marks off the value stack and pushes them on the procedure stack, in the order they come off. That is why the specification writes its procedures backwards.
The machine
| Letter | Does |
|---|---|
a | Pop two numbers and add them; the a register can make it subtract, multiply, divide, take the modulo or compare |
b | Break out of the loop |
c | Copy the item n places down |
d | Pop a mark and every letter down to the next mark into a procedure |
e | Run the procedure that the e register counts from the bottom |
f | Flip the top n items |
g s | Get or set a register |
h | Halt |
i | Pop a value and a procedure, and run it when the value is not a |
k | Copy the top procedure |
l | Switch between literal and instruction mode |
m | Push the m register |
n | Push the number of items on the stack |
o | Replace one letter with another, down to a mark |
p | Print a letter, as lower case, upper case, digits, punctuation or control codes |
r | Pop a count and a procedure and run it that many times, or for ever on a |
t | Read a character |
u | Pop down to a mark |
w | Rotate the top n items |
x | Run the top procedure |
y | End the current procedure |
j, q, v and z do nothing, and every character that is not a lower case letter is a comment. With the i register set to n, i becomes a chain of n conditions and n + 1 procedures. With the n register set, the numbers that a, i and n work on take more than one letter each.
Example
c is 2 and d is 3, so a leaves f.
c is 2 and d is 3, so a leaves f.
The Hello World pushes its letters, prints H in upper case mode, turns every j into an l and then switches print modes for the space, the W and the !. In digit mode w prints a space.
A loop that prints the stack until it reaches z. The procedure compares a copy of the top with z, and on a match it runs h.
t reads a character as a letter. a is false, so the procedure that pushes a does not run and the z under it is printed.
A 99 bottles of beer program counts down from 99 to no more bottles.
Patterns it teaches
- Stack machines, with two stacks, one for values and one for procedures.
- Code as data, as a procedure is made from letters that were data a moment before.
Further
See also
Stack-based
Write your own in Run Convert a program from AlphaStack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: alphastack.
Command line
shib run alphastack -e 'cdlap'shib manual alphastackSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/alphastack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org