SMATINY, the Self-Modifying Automaton application that's really TINY, is a minimalistic programming language by Ihope127, based on the swapping concept of SMETANA. The computational class is as yet unknown.
Each line featuring more than just a new-line is called a step. There can be any number of steps in a program. Each step has an unique number, and the step numbers have to be in increasing order. However, it isn't required that each line is a step -- there can be blank lines featuring only a new-line character -- or that each step used in the program is defined. If a step isn't defined, it is a "Do nothing." automatically. The following program (featuring a blank line) would be valid.
10. Swap 10 with 10. 100. Swap 100 with 200.
If the current step is greater than the greatest defined step, the program is terminated. In this example first on step 10 step 10 would be swapped with itself (step 10) and then a jump to step 11 (10 + 1 = 11) is performed. Later, on step 100, step 100 would be swapped with step 200 (step 200 is undefined and therefore "Do nothing.") and then a jump to step 201 (200 + 1 = 201) would be performed. 201 is greater than the greatest defined step, now 200 (the step 100 after moving) in this case, so the program is successfully terminated.
There are three instructions in SMATINY.
Note the lack of GOTOs or other jump commands. Jumping is a side-product of swapping the content of two steps. This is the swapping instruction:
X. Swap Y with Z.
If X = Y, this will jump to the step below step Z, in addition to performing the swap as normal. Similarly, if X = Z, Swap will jump below step Y. If the current step is not one of those swapped, no jump is performed. (Think of the instruction pointer as being part of the step itself.)
The following program
1. Swap 1 with 3.
would swap the content of step 1 with the content of step 3, and then jump to step 4 (3 + 1 = 4). As step 3 is now the greatest step defined, in this example, jumping to step 4 which is above the greatest defined step would end the program.
The following instruction performs a NOP:
X. Do nothing.
NOP steps are not required to be written, as every undefined step is a NOP by definition, but the instruction is available for the sake of clarity. However, knowing which steps act as NOPs is often required when writing a SMATINY program.
For an example demonstrating the importance of NOP in SMATINY, see the output example below.
Output is done with the following instruction:
X. Output this block's position.
The current step's number is printed out as a Unicode code point. If the step, say, 65 had output instruction in it, then 'A' would be printed out.
The following program should print "Hi!".
32. Swap 32 with 71. 33. Output this block's position. 34. Swap 34 with 200. 72. Output this block's position. 105. Output this block's position. 106. Swap 106 with 32.
First, note that every step but 32-34, 72, and 105-106 is a NOP by definition. After executing 31 NOPs, the first defined step, step 32, is reached. In step 32 step 32 is swapped with step 71, which is known to be a NOP. As a result a jump to step 72 is performed (71 + 1 = 72). This jump could've been performed anytime earlier, too. There the Unicode character 'H' is printed out. After that, a few more NOPs are executed and finally character 'i' is printed in step 105. Right in the next step (106) step 106 is swapped with 32. This is done so that a jump to 33 can be done (32 + 1 = 33). In step 33 the character '!' is output. Then, in step 34, step 34 is swapped with 200. This jump is made in order to end the program. It wouldn't matter if the structure of program got messed up, since it is going to be terminated right after this jump. A jump must be done also to prevent printing 'H' and 'i' again. This is done by jumping to a greater step than the greatest defined step -- in this case the second step must be 105 or higher (not 106, because that now happens to be a NOP). In this case number 200 is used. Done.
This language is output-only. There is currently no way to get input.
The control flow of SMATINY is reversible, that is, knowing the current list of steps of the program and the number of the current step allows one to backtrack all the way to the beginning.
As a result of the finite program size, the lack of input, and reversibility, it is impossible to write a non-terminating program, such as an infinite loop. However, SMATINY may be able to simulate any reversible finite automaton, such as a reversible computer architecture.
One can pretty much add whatever one wants to this language to make it more fun than it already is, or simply try to design programs that run as long as possible, or that actually do something.
Reversibility can be broken by adding an instruction such as this one:
X. Break reversibility by swapping this step with step Y.
An infinite loop using this instruction:
1. Break reversibility by swapping this step with step 1. 2. Break reversibility by swapping this step with step 1.
Another experimental instruction, which doesn't break reversibility if the input stream is considered available for backtracking:
X. Input a character, then swap Y with it.