Tsept
Twenty-eight one-character instructions on seven registers and two stacks of 256 numbers.
Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
The name Tsept means Tetra Sept, 4 times 7, for its 28 instructions and 28 syscalls. Every instruction is one character and works on the accumulator A, the registers around it, or one of two stacks of 256 numbers. There are no literals. A number is built in A with I, D and additions, and pushed when it is needed.
Read the story
With s a program makes a syscall. The interpreter forwards it to Linux, to read and write files, fork, open sockets or print a number in decimal. This implementation leaves the syscalls out.
The machine
| Instruction | Does |
|---|---|
A S | Pop a number and add it to A, or take it from A |
I D | Add 1 to A, or take 1 from A |
X a | Pop a number and XOR or AND it into A |
x k | Clear A; copy C into A |
B K w b | Swap A and B, S and B, D and E, X and E |
P p | Push A; pop into A |
C d l | Pop into C, D or S |
R c | Push D or S |
W | Swap the two stacks |
H h | Push or pop the heap cell at D |
J i | Pop n and jump n characters; i only when A is not 0 |
L | If C is above 0, take 1 from C and go back to just after the last C |
! ? | Print A as a byte; read a byte into A |
s | A syscall, not implemented |
Text between two slashes is a comment. The specification names seven exceptions. This implementation stops on an invalid instruction, a stack that overflows or underflows, and a heap address out of bounds. Every register starts at 0, as the specification does not say which version number A holds at the start. The specification gives the heap no starting size, so this implementation starts it empty, and without the syscall that resizes it H and h always stop the run.
Example
The truth machine.
The truth machine. It reads a byte, doubles 2 up to 16 with PA, adds two more 16s and takes the 48 from the byte. It prints the byte, and i pops the -9 that nine D built and jumps back while the difference is not 0. On 0 it prints 0 once. On 1 it prints 1 forever, which works only when the run goes on at the character after the one jumped to.
PA pushes A and adds it back, which doubles it. So 65 is built from its bits, 1000001 in binary.
A loop with the counter. The program builds 42, the code of *, and parks it in B. It clears A, because the old B it got back may hold anything, and pushes a 4. Then it takes the 42 back and pops the 4 into C. L goes back to the ! after C four times.
Patterns it teaches
- Stack machines: an accumulator with two stacks of 256 beside it.
Further
See also
Concurrent programming
Cell-based
Write your own in Run Convert a program from Tsept
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: tsept.
Command line
shib run tsept -e '/This text won'\''t get interpreted!/'shib manual tseptSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/tsept.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org