OIL

From Esolang
Jump to: navigation, search

OIL is an esoteric programming language made by MDFL L3viathan that stands for Overly Introspective Language. It is turing-machine-like, but with random access and a couple of high-level quirks.

Language description

OIL has an infinite array of values that is initially read from an OIL source file, one value per line. It also has a read-write head with jumping abilities that starts at position 0 (the first line). There's no seperation between code and memory.

"Syntax"

The code consists of a newline-separated series of values. Values are either unicode strings or integers, and will freely convert between eachother when needed: A string that is handled numerically (e.g. incremented) is seen as 0, an integer that is used as a string behaves as a string representation of itself. The read-write head moves in one direction, usually forwards and reads commands, which may then instruct it to read additional values. Whenever a value is to be read from an unassigned cell, the value is 0, but if the head is to read a command from an unassigned cell, the program execution is aborted. An unassigned cell can be written to without issues, it is an assigned cell afterwards. Any cell that corresponds to a line in the script file starts as assigned, any other cell as unassigned. Once a cell is assigned, it can never become unassigned.

Commands

Most commands (all except any kind of jump and reversing) will advance the head by one position after they are done reading all of their arguments, which is ommitted in the following list.

Number Command
0 Nop. Since a string also maps to 0, any string also nops.
1 Read the next two values (v1, v2). Copy the value from cell v1 to cell v2.
2 Reverse the direction the head moves in, i.e. if it was moving forwards, it will now move backwards and vice versa.
3 Exit the interpreter.
4 Read the next value (v1) and output the value of cell v1 to stdout.
5 Read the next value (v1) and read a value from stdin (until a newline, which is stripped) (v2). Put v2 into the cell v1.
6 Read the next value (v1), then jump to cell v1.
7 Read the next value (v1), then jump v1 cells ahead.
8 Read the next value (v1) and increment the value in cell v1.
9 Read the next value (v1) and decrement the value in cell v1.
10 Read the next four values (v1, v2, v3, v4). If the value in cell v1 is equal to the value in cell v2, jump to cell v3, otherwise to cell v4.
11 Print a newline character to stdout.
12 Explode: Read the next two values (v1, v2). Transform the value in cell v1 into a string (s), put the length of the string in cell v2, and then every character of s into a cell after cell v2.
13 Implode: Read the next three values (v1, v2, v3). Starting from cell v1, join the next v2 cells into a single value with string concatenation and put the resulting value in cell v3.
14 Read the next three values (v1, v2, v3). Run a sub-interpreter of OIL with v1 as the script filename, with the following special case: Instead of printing (4), values will be written to cells starting at cell v2 (in this interpreter), and instead of reading from stdin (5) values will be read from cells starting at cell v3.
15 Read the next two values (v1, v2). Fill cell v1 with a pseudorandom number between 0 and that v2. If v2 is negative, this is a nop instead.
16 Read the next two values (v1, v2). Convert the value from cell v1 into a string. Put its length in cell v2, and each of the numeric values of the unicode codepoints of its characters seperately into cells after v2.
17 Read the next three values (v1, v2, v3). Put the codepoint sequence that starts at cell v1 and is v2 cells long into cell v3, converted into the characters of that codepoint. An invalid codepoint maps to U+FFFD.

Implementations

An official implementation as well as a more in-depth description of the language can be found here. There's also an implementation written in Rust.

Examples

Hello world

Hello World
4

Quine

0
0
1
1
1
4
1
11
4
1
11
1
2
2
1
12
18
10
18
1
32
22
1
18
26
4
26
8
18
11
6
17