Stackfuck

From Esolang
Jump to navigation Jump to search

Stackfuck is a stack-based esoteric language inspired by brainfuck. It is converted to pseudo-code at runtime to speed up the interpreter.

List of instructions

	P - Push character onto stack (xxx - Number, xC - Character)
	T - Set variable to top of stack (xxxxx)
	V - Push variable value to top of stack (xxxxx)
	C - Create new buffer
	S - Select buffer (xxxxx)
	O - Print current buffer
	I - Read line and set to buffer
	G - Goto xxxxx if top is non-zero
	g - Relative goto
	N - Goto xxxxx if top is zero
	n - Relative goto
	L - Goto label xxxxx if top is non-zero
	l - Goto label xxxxx if top is zero
	K - Unconditionally goto label xxxxx
	X - Exit with signal xxxxx
	x - Exit with signal s
	$ - Create label here xxxxx
	A - Concatenate buffer with xxxxx
	a - Put buffer onto stack
	? - Copy buffer xxxxx to current
	) - Clear stack
	( - Pop one from stack
	; - Move stack into selected buffer
	: - Move stack into selected buffer, reversed
	+ - Add s-1 and s
	- - Subtract s from s-1
	/ - Divide s-1 by s
	* - Multiply s-1 by s
	^ - Xor s-1 with s
	| - BOr s-1 with s
	& - BAnd s-1 with s
	\ - LOr s-1 with s
	7 - LAnd s-1 with s
	Z - Copy s-xxxxx to the top
	< - GT s-1 with s
	> - LT s-1 with s
	. - GE s-1 with s
	, - LE s-1 with s
	= - == s-1 with s
	! - != s-1 with s
	E - Checks if selected buffer is equal to xxxxx

Standard buffers

These are recommended buffers to use

  • Buffer 0: stdout - Standard buffer for copying to, then printing out
  • Buffer 1: stdin - Standard buffer for reading user input
  • Buffer 2: stdcheck - Standard buffer for checking user input

Examples

This is the hello world application

CS00000PxHPxePxlPxlPxoPx PxwPxoPxrPxlPxdPx!P010;O

Here is a program with input

# Buffer 0 - Output
# Buffer 1 - Input
# Buffer 2 - Check
CCCS00000

$00000
# Select an option:
#
# 1. Example
# 2. Exit
PxCPxhPxoPxoPxsPxePx PxaPxnPx PxoPxpPxtPxiPxoPxnPx:P010P010
Px1Px.Px PxEPxxPxaPxmPxpPxlPxeP010
Px2Px.Px PxEPxxPxiPxtP010P010Px>Px ;O

# Select input buffer
S00001I

# Add line
S00000P010;O

# Select check buffer
S00002

# 1
)Px1;E00001l00001
PxHPxePxlPxlPxoPx,Px PxwPxoPxrPxlPxdPx!P010P010;O
K00000
$00001

# 2
)Px2;E00001l00000
X00000

Here is a more advanced one that takes the name and age, then summarises it

# buffer 0 - stdout
# buffer 1 - stdin
# buffer 2 - stdcheck
# buffer 3 - name
# buffer 4 - age
# buffer 5 - tempoary buffer
CCCCCC

$00000

S00000

# Choose an option:
PxCPxhPxoPxoPxsPxePx PxaPxnPx PxoPxpPxtPxiPxoPxnPx:P010P010;O

Px1Px.Px PxTPxePxlPxlPx PxnPxaPxmPxeP010
Px2Px.Px PxTPxePxlPxlPx PxaPxgPxeP010
Px3Px.Px PxSPxuPxmPxmPxaPxrPxyP010
Px4Px.Px PxEPxxPxiPxtP010P010
Px>Px 
;O

# Read input
S00001IS00000P010;O

S00002

# Name
)Px1;E00001l00001
S00000
PxNPxaPxmPxePx:Px ;O
S00003I
O

K00000

$00001

# Age
)Px2;E00001l00002
S00000
PxAPxgPxePx:Px ;O
S00004I

K00000

$00002

# Summary
)Px3;E00001l00003
S00000}
PxNPxaPxmPxePx:Px a00003P010
PxAPxgPxePx:Px a00004P010P010B
;O

K00000

$00003

# Exit
)Px4;E0000l00004
X00000

$00004

External resources

Stackfuck interpreter (source code)