Tetrastack

From Esolang
Jump to navigation Jump to search
Tetrastack
Paradigm(s) Stack-based
Designed by User:GUAqwq
Appeared in 2023
Computational class Turing complete
Major implementations Implemented
File extension(s) .ts_

Tetrastack is a stack-based esoteric programming language. Each stack has its own pop behavior. It's the 1st esolang of TS Series by User:GUAqwq

Overview

There are four stacks of integers. Stacks are referenced by numbers from 0 to 3.

Source code consists of hexadecimal digits. Each digit represents an instruction. The two upper bits represent the stack which an element will be popped from, while the two lower bits represent the stack which the element will be pushed to.

For example, BD7A corresponds to 23 31 13 22, which in interpreted as

  • Pop from stack 2 and push to stack 3
  • Pop from stack 3 and push to stack 1
  • Pop from stack 1 and push to stack 3
  • Pop from stack 2 and push to stack 2

Popping from stack 0 increments the value of the popped number (before pushing to the new stack). Popping from stack 1 decrements the value. Popping from stacks 2 or 3 does not change the value.

If you ever try to pop from a empty stack, it will crash down immediately.

Special cases

Instruction F (pop from 3; push to 3) is special. It pushes number 0 to stack 2.

A loop starts with an instruction that pops from stack 3 (and pushes to any stack except 3), and ends with instruction A (pop from 2; push to 2). When a number is popped from stack 3, if it is 0 then jump past the matching instruction A (the end of the loop). Otherwise execute the loop. When A is reached, jump to the matching loop start. Loops can be nested.

In summary, special instructions are A and all instructions that pop from stack 3.

I/O

The inputs/outputs correspond its ASCII. The end of the inputs is the top of stack0. (the end of the stack0 is a extra -1 The top of stack3 is the start of outputs.

Computational class

Tetrastack is Turing complete because any brainfuck program can be translated to Tetrastack using the following conversions:

Start of the program: F97F963D63AF94F95F8F803DF803DF803DF803DF803DF803DF803D007A7A7A7A7A7A7A16F833DD
                      7A4FBFBAD7F94F8BFD7082AF8A

End of the program: F9FC3FBAEC3FBAABDBA43D743A

< → 21595F833DD7A4FBFBAD7F94F8BFD7082AF8A
> → 40F833ED7A4094FBFBAD7F95F8BFD7082AF8A
+ → F832157CD7A8FBFBAD78F8A
- → F8317ED7A094FBFBAD71F8054A
, → BF8383DD7A6FBFBAD7F96FA3D7A3D7AEFBAF8BFD7082AF88B16D7F832157CD7A8FBFBAD78F8AA
. → 3F8FD7082A15497
[ → 17C
] → 17AF8

Examples

Cat program

3D73A

Hello, World!

FFBF9F9F9F9F9F9F9F9F9F9F9F9F9F9F9F940140140140140140140140143D4040140140140143D404014014040140140140
4014014014040115151515543AF94040140401405404040143D1543AF915543AF94040FF843D508243A1540555FF843D5082
43A15B401401401401401401401FF843D508243A15BFF843D508243A15B401401401FF843D508243A154040FF843D508243A
15B155FF843D508243A1515FF843D508243A15B401401401FF843D508243A15B555555FF843D508243A15B55555555FF843D
508243A154040401FF843D508243A15B40401401F8CABDBAF17E17AB111744BBB117B400000000003443BBB3

Interpreters