Tsept
Tsept (pronounced /t͡sɛpt/) is an esolang with 28 instructions and 28 syscalls. Its name means "Tetra Sept" (4*7) because of the quantity, as mentioned earlier, of instructions and syscalls.
Data structures
Tespt has multiple data structures used for storing different things:
name | purpose |
---|---|
Registers & stacks | For storing immediate and backup values |
Heap | For storing strings and arrays and spilling data when the registers and stacks are full. |
Registers
There are seven registers:
- The
A
register is the accumulator, the primary register used for arithmetic, I/O, popping and pushing things to and from the Stack, and storing the syscall number when the program makes a syscall. - The
B
register is the backup; it is used for storing the accumulator or secondary when they need to be overwritten, but you don't want to lose their value. - The
S
register is the secondary; it is used as just another register; it can act as a secondary backup or, as in the case of syscalls, as another numerical parameter. - The
C
register is the counter; it's mainly used in loops but can be used as just another register. - The
D
register is the address register; it's mainly used for addressing heap memory but can be used as just another register. - The
E
register is the address backup; it serves the same purpose as the main backup but is a backup for the address register instead of the accumulator. - The
X
register is the address secondary; as with the address backup, it serves the same purpose as its main correspondent but is secondary to the 'D' register.
Default Values
The accumulator will, by default, contain the TSEPT version.
By nature of the C programming language (used to program Tsept's interpreter), the other registers are set to unpredictable values by default.
Stacks
There are two stacks in Tsept, each 256 integers big, and they can be swapped using the 'W' instruction.
Heap
The heap is like a tape that can be accessed at any location and shrink or grow anytime; trying to access memory beyond the heap's bounds will raise Exception 4 and stop the program.
Exceptions
The Tsept interpreter has seven exceptions it can throw if a problem arises from the program:
- Exception 1: Raised when the program attempts to run an invalid instruction.
- Exception 2: Raised when a syscall fails for any reason.
- Exception 3: Raised when the interpreter can't allocate the program's heap memory.
- Exception 4: Raised when the program tries to access heap memory beyond its bounds.
- Exception 5: Raised when one of the stacks overflows.
- Exception 6: Raised when one of the stacks underflows.
- Exception 7: Raised when the program tries to execute a syscall which doesn't exist.
When the interpreter prints the exception test, it will also print the address at which the exception got raised in the program and the registers.
Instructions
Tsept has 28 instructions organized into five categories.
Arithmetic
A
: Pop and add to the accumulatorS
: Pop and subtract from the accumulatorI
: Increment the accumulatorD
: Decrement the accumulatorX
: Bitwise XOR the accumulator with popped valuea
: Bitwise AND the accumulator with popped value
Register Operations
B
: Swap accumulator and register 'B'w
: Swap registers 'D' and 'E'x
: Clear the accumulatorK
: Swap registers 'S' and 'B'b
: Swap registers 'X' and 'E'k
: Set accumulator to register 'C'
Stack and Heap Operations
P
: Push accumulatorp
: Pop accumulatorW
: Swap stacksC
: Pop register 'C'd
: Pop register 'D'H
: Push heap memory at register 'D'h
: Pop heap memory at register 'D'R
: Push register 'D'c
: Push register 'S'l
: Pop register 'S'
Control Flow
J
: Pop and relative jump to the popped valuei
: Pop and relative jump to the popped value if the accumulator is not zeroL
: If register 'C' is higher than zero, decrement it and jump to one character after the last location it was modified
I/O
!
: Output accumulator to stdout?
: Input accumulator from stdin
Note: the s
instruction executes a syscall.
In Tsept, you can specify comments by enclosing the comment in slashes:
/This text won't get interpreted!/
Syscalls
Tsept has 28 syscalls that get forwarded to Linux syscalls by the interpreter:
syscall name | Accumulator | Register 'S' | Register 'D' | Register 'X' | Popped from stack |
---|---|---|---|---|---|
read | 0 | file descriptor | buffer | count | - |
write | 1 | file descriptor | buffer | count | - |
open | 2 | file descriptor (output) | filename | - | - |
close | 3 | file descriptor | - | - | - |
create | 4 | - | filename | - | - |
link | 5 | - | oldname | newname | - |
delete | 6 | - | filename | - | - |
fork | 7 | child PID (output to parent) | - | - | - |
getpid | 8 | own PID (output) | - | - | - |
getppid | 9 | parent PID (output) | - | - | - |
exec | 10 | argument count | filename | - | argument list |
chmod | 11 | mode | filename | - | - |
signal/kill | 12 | pid | signal (int) | - | - |
rename | 13 | - | oldname | newname | - |
mkdir | 14 | - | path | - | - |
rmdir | 15 | - | path | - | - |
time | 16 | unix epoch (output) | - | - | - |
truncate | 17 | fd | size (int) | - | - |
socket | 18 | fd (output) | - | - | - |
bind | 19 | fd | port | - | - |
listen | 20 | fd | - | - | - |
accept | 21 | fd | - | - | client fd (output) |
connect | 22 | fd | IP address | port | server fd (output) |
output hex | 23 | no. bytes to print | data | - | - |
output decimal | 24 | number | - | - | - |
resize heap | 25 | size | - | - | - |
heap size | 26 | size (output) | - | - | - |
wait | 28 | pid | - | - | - |
exit | 28 | error code | - | - | - |
Interpreter
The 'tseptc' interpreter is available in this Codeberg repository.
Examples
Truth Machine
?PBKpPxIIPAPAPAPPAABpBPBSPBxDDDDDDDDDPBKB!BKBPBi