SMATIMU

From Esolang
Jump to: navigation, search

SMATIMU, or the Self-Modifying Application That Is Mildly Useful, is an extension to the SMATINY language with the intention of making it slightly more useful for programming in. It was created in 2017 by User:Scoppini.

Overall

SMATIMU files are made up of a series of steps, separated by newlines. Each step must be preceded by a unique number, and followed by an instruction ended with a period. All step numbers must be greater than zero, but are not required to be in any specific order. Not all steps used in the program need to be defined; if a step is used that hasn't been defined, it will be considered to be a NOP command. SMATIMU is case-insensitive.

Execution begins with the lowest numbered step, and continues sequentially until the program has finished executing the highest numbered step. If a step changes position while it is being executed, then execution continues from its new position. For instance, in the following program, when step 1 is swapped with step 3, step 4 is the next step executed, instead of step 2.

1. Swap 1 with 3.
2. Do nothing.
3. Do nothing.
4. Do nothing.

Commands

There are five different instructions in SMATIMU.

Swap

The swap command swaps the position of two instructions. It is written as:

A. Swap B with C.

In addition, there is an alternate form, which allows multiple steps to be swapped at once. This is written in the form of:

A. Swap B through C with D through E. 

In this form, the ranges of B through C and D through E must be exactly the same number of steps long, and may not overlap. If the ranges overlap, or are different lengths, the instruction is considered invalid and is not executed.

Replace

The replace command replaces one step's instruction with a different instruction. It is written as:

A. Replace B with <instruction>.

A step is allowed to replace itself, but the new replaced step is not executed until execution reaches the step again.

100. Replace 100 with Swap 10 with 100.

Set

The set command allows the setting of a variable. It is written in the form of:

A. Set <variable name> to <step value>.

A variable name can be any token that has at least one non-digit. After a variable is defined, it may be used in the place of a step number in any instruction, such as in this simple program that creates an infinite loop:

1. Set swap_step to 2.
2. Swap swap_step with 2.
3. Set swap_step to 4.
4. Swap swap_step with 2.

If a variable name is used in an instruction before it is defined, that instruction is considered invalid and is not executed.

Output

Output is achieved with the following instruction:

X. Output this block's position.

When this step is encountered, the current position of the step is printed as a unicode code point. For instance, if step 48 was an output instruction, '0' would be printed out.

NOP

Any step which is not in the form of the above instructions, or is otherwise considered invalid, and nothing will happen when they are encountered. As such, any instruction that is not valid may be used as a comment, so long as the step number is unique.

100. This is a comment.
101. This is also a comment.
102. These instructions do nothing.

Relative Addressing

In addition to adding instructions to SMATINY, SMATIMU also adds a new feature to SMATIMU known as "relative addressing".

Any step label preceded by a + or - will be interpreted as a relative address. A relative address gets a step number by adding the position of the instruction with the relative address. An example of this is:

100. Swap -50 with +100.

The above program swaps steps 50 (100 - 50) and 200 (100 + 100). If an instruction moves later, the relative address is based on the step's current position instead of its old position. For instance, in the following program, the second swap instruction swaps 90 and 110 instead of 40 and 60.

1. Swap 50 with 100.
50. Swap -10 with +10.

In addition, variables may also be used as relative addresses, such as in the following program:

1. Set offset to 10.
100. Swap +offset with -offset.

Also, although all the previous examples use instructions without mixed static and relative addresses, they may be mixed arbitrarily, such as:

100. Swap 10 with +10.

No matter where 100 is moved in the program, it will always swap step 10 with whatever step is ten steps after its current position.

Examples

Yes command

1. An implementation of the "yes" unix command.
2. Outputs 'y' followed by a newline forever.
9. Swap +0 with 9.
10. Replace +0 with Output this block's position.
121. Output this block's position.
122. Swap +0 with 9.

Unary Counter

1. Counts upward in unary.
2. Never stops; must be terminated by the user.
3. Swap +0 with 99.

8. Swap 8 with 11.
10. Output this block's position.
11. Swap 8 with 11.

47. Swap 47 with 50.
49. Output this block's position.
50. Swap 47 with 50.

100. Set N to +1.
101. Swap N with 48.

102. Set N to +1.
103. Swap N with 9.

104. Swap -2 through +3 with +4 through +9.
105. Replace -5 with Set N to +1.
106. Replace -5 with Swap N with 48.
107. Swap +0 with 99.

Turing Completeness

The Turing completeness of SMATIMU can be demonstrated by the use of this converter from brainfuck to SMATIMU, written in python. Since all brainfuck programs can be converted to SMATIMU, and brainfuck is Turing complete, then SMATIMU is also Turing complete. The converter does not handle the "," command, since SMATIMU programs are unable to handle input, but handling input is not needed for Turing completeness.

External Resources