We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

ONLY STACK mini

From Esolang
Jump to navigation Jump to search
ONLY_STACK mini
Designed by User:Jan Pilavik
Appeared in 2026
Dimensions 1
Computational class Turing-complete
Reference implementation Unimplemented

ONLY_STACK mini is an esoteric programming language centered around a single stack and pure immutability.

Overview

  • Stack: The language utilizes a single stack.
  • Stack Representation: Suggested notation for visualizing the stack state is ←[1st from top, 2nd from top, ...].
  • Values: The stack can hold any computable numbers (including complex numbers) that can be generated at the stack top within a finite number of steps.
  • Immutability: All values are strictly immutable. Values cannot be modified in-place; computations always read existing values, generate a new value, and push it onto the top.
  • Fraction Reduction: Fractions are automatically reduced to their simplest form (e.g., 2/4 is automatically stored as 1/2).
  • Comments: Any character sequence that does not form a valid instruction is ignored as a comment.

Syntax and Delimiters

  • Instructions and values must be separated by whitespace (\u0020, \u3000, and so on).
  • If the stack contains insufficient elements when an instruction is executed, the program triggers a stack underflow and crashes (forced termination).

Computational Class

ONLY_STACK mini is Turing-complete. Although it features only a single stack, the stack can store unbounded computable numbers, allowing data encoding (such as Godel numbering). By leveraging the ^ (goto) instruction—which falls through to the next instruction if the specified index is a negative integer or out of bounds—it is capable of implementing fully functional conditional branching (if-else statements) and arbitrary loops.

Instructions

Instruction Description Translation to Forth (example)
#<integer> Pushes the specified integer onto the stack. (Note: Raw numbers without # are treated as comments). <integer>
+ Reads the top two values (m as 1st, n as 2nd from top). Calculates n + m and pushes the result. The original values are preserved. OVER OVER +
- Reads the top two values (m as 1st, n as 2nd from top). Calculates n - m and pushes the result. The original values are preserved. OVER OVER -
* Reads the top two values (m as 1st, n as 2nd from top). Calculates n × m and pushes the result. The original values are preserved. OVER OVER *
/ Reads the top two values (m as 1st, n as 2nd from top). Calculates n / m and pushes the result. If m = 0, the program crashes immediately. The original values are preserved regardless. OVER OVER /
POW Reads the top three values (l as 1st, m as 2nd, n as 3rd). Calculates and pushes the result. If n = 0, the result is always 0 regardless of the exponent. TBD
; Pops the top element from the stack. DROP
: Duplicates the top element of the stack. DUP
\ Swaps the top two elements of the stack. SWAP
^ Reads (references) the top element and performs a goto to the instruction at that 0-based index (ignoring comments). The top element is not consumed. If the value is a negative integer or the index is out of bounds, it simply falls through to the next instruction. No direct equivalent (Simulated via Jump Table & EXECUTE)
. Reads the top value, casts to integer, outputs as a Unicode character (UTF-32), and pops. XEMIT
(or UTF-8 encoding subroutine)
, Reads a character, converts it to its Unicode code point (UTF-32), and pushes it. Pushes 0 on EOF. XKEY
(or UTF-8 decoding subroutine)
_ Reads the top value and pushes its complex conjugate without consuming the original value. TBD
! Terminates the program cleanly. BYE
W Halts execution for the number of seconds specified by the top element, then pops that element. 1000 * MS
{ comment } Block comment. Everything inside the braces (including valid instructions) is ignored. ( comment )

Implementation example

Implementations in any programming language(python, js, jsfuck, C, C++, C#, bf, Piet, Whitespace, and so on.) are welcome!

Please post using Talk:ONLY_STACK mini.

Examples

Hello, World!

#72 . #101 . #108 . #108 . #111 . #44 . #32 . #87 . #111 . #114 . #108 . #100 . #33 . !

Cat program (by Jan Pilavik)

An infinite loop Cat program that reads characters and outputs them continuously. Upon reaching EOF, it continuously outputs null characters, which is semantically equivalent to terminating the string output:

#1 ; , . #1 ^

sgn code (only n+0i) (by Jan Pilavik)

{命令番号は0から}
#43 ^
; : #2 #1 POW \ #2 POW \ ; \ ; \ ; \ ; \ #0 #1 POW - \ ; \ ; \ ; \ ; + \ ; \ ; / \ ; \ ; \ ^ {sgnサブルーチン終了}

; #48 #100 #2 {←[サブルーチンの命令番号,引数,戻ってくる命令番号]と書く} ^ ; {←ここが48番号目の命令}

mod(剰余) code (only n+0i) (by Jan Pilavik)

{
構想:
0:mをabs(m)にする
↓
1:nをmで引く(これを次のnとする)
↓
2:n≥0なら1へ
↓
3:nにmを足す(これを次のnとする)
↓
4:n<0なら3へ
}
#152 ^

{sgn(n)}
; : #2 #1 POW \ #2 POW \ ; \ ; \ ; \ ; \ #0 #1 POW - \ ; \ ; \ ; \ ; + \ ; \ ; / \ ; \ ; \ ^ {sgnサブルーチン終了}

{0番:初期化(目標STACK:←[n,abs(m)])}
;
#2 #1 POW \ ; \ ; \ ; #1 #2 POW \ ; \ ; \ ; \

{1番:引き算機構}
#0 ; {ループしてくる場所}
- \ ;

{2番:比較、ループ機構}
: #74 \ #2 ^ ; {sgnサブルーチン起動!} {input=←[2,n-m,74],output=←[74,sgn(n-m)]}
#1 + \ ; \ ; #85 \ #2 ^ ; {sgnサブルーチン起動!} {input=←[2,sgn(n-m)+1,85],output=←[85,sgn(sgn(n-m)+1)]}
#2 * \ ; \ ; #1 - \ ; \ ; #69 * \ ; \ ; ^ ; {(2*sgn(sgn(n-m)+1)-1)*69にジャンプ(2*sgn(sgn(n-m)+1)-1=-1(if (n-m)<0)OR1(if (n-m)≥0))}

{3番:足し算機構}
#0 ; {ループしてくる場所}
+ \ ;

{4番:比較、ループ機構}
: #116 \ #2 ^ ; {sgnサブルーチン起動!} {input=←[2,n+m,116],output=←[116,sgn(n+m)]}
#1 - \ ; \ ; #127 \ #2 ^ ; {sgnサブルーチン起動!} {input=←[2,sgn(n+m)-1,127],output=←[127,sgn(sgn(n+m)-1)]}
#-2 * \ ; \ ; #1 + \ ; \ ; #111 * \ ; \ ; ^ ; {(-2*sgn(sgn(n-m)+1)+1)*111にジャンプ(-2*sgn(sgn(n-m)+1)+1=1(if (n-m)<0)OR-1(if (n-m)≥0))}

\ ; \ ^ {modサブルーチン終了}

; #158 #152 #3 #43 {←[サブルーチンの命令番号(ここではmod),引数n,引数n-1,...,引数2,引数1,戻ってくる命令番号]と書く} ^ ; {←ここが158番号目の命令}

Many example links

jan Pilavik Drive

External links