SFIN
SFIN, which stands for “Simple Four-Instruction Nand”, is a very minimalistic language which only contains four commands. This language is inspired by [Brainfuck] and the process of NAND logic.
Language Overview
SFIN operates on four bits at the start of the program which are all initialised to 0. However, this can be increased using syscalls by doubling (8, 16, 32…). There is also one bit of memory which is used for storage of command outputs which is initialised to 0. The standard commands are:
Command | Description |
---|---|
> | Moves the pointer one bit right with overflow. |
? | Saves the bit at the pointer to memory |
v | Nands the current cell with the bit and memory and sets the cell to the result |
| | Sets a pointer in the program |
d | (ONLY IN THE DEBUGGER) Prints debug info about the program. Implementation can vary from interpreter to interpreter |
However, by using multiple of some of these commands, you get new commands to use:
Command | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
??... | Calls a syscall for every question mark together - 1 (so 2 question marks will make 1 syscall) following this table:
| ||||||||||||
||... | If the current value in memory is equal to 0, jump to the Xth pointer in the program, with X being the amount of vertical bars - 1 |
Examples
Due to the simplicity of SFIN, many common tasks in programming languages become much more difficult. This simple program stores the value of Bit 1 in Bit 2
? Stores the value of Bit 1 > Sets the pointer to Bit 2 v Bit 2 = Bit 1 NAND Bit 2 v Bit 2 is NANDed by Bit 1 again. This sequence sets Bit 2 to the inverse of Bit 1 ?v Gets the value of Bit 2 and NANDs it with itself. (X NAND X = NOT X)
This program takes two bits as inputs and outputs the XOR of the two without using any loops. It seems likely that this could be improved using loops.
v??>v?? Sets b[1] (the first bit) and b[2] to inputs >>>?>>vv?v Stores b[1] in b[3] >>>?>v Sets b[3] to b[1] NAND b[2] ?>>v>v b[1] = b[1] NAND b[3], b[2] = b[2] NAND b[3] ?>>>v b[1] = b[1] NAND b[2] >>>v? Sets b[4] to 1 for printing and saves it to memory >?? Outputs b[1]
A simple program using loops to simulate an increment (this program assumes 4 bits of memory
The program should start at the highest bit of the number
| Sets a pointer for the program >>> Moves back one (change this if the memory is larger) ?v Inverts the current cell ? Saves the current cell || Jumps back if it is zero
A truth machine written in SFIN.
v?? Sets b[1] to input >>>>?>vv>v Sets b[2] to !b[1] and b[3] to 1 | Start of a loop ? Stores b[3] >>?? Prints b[1] >? Saves b[2] > Moves back to b[3] || Jumps to loop if zero
Binary Representation
SFIN can be compiled to binary by using the official Python interpreter. Each instruction is taken up by two bits following this structure:
> | 00 |
? | 01 |
v | 10 |
| | 11 |
Computational Class
There has been no formal proof that SFIN is turing-complete. However, it seems very possible to implement Boolfuck in SFIN, thus proving its turing-completeness.