OIL
The Overly Introspective Language. Every line is a cell, and the program reads its commands from the same cells it writes.
L3viathan, 2016 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
L3viathan made OIL in 2016. A program is a list of values, one per line, and that list is also the whole memory. A head starts on the first line, reads a number as a command and then reads the command's arguments from the lines after it. Nothing marks which lines are code and which are data, so a program can change its own commands as it runs.
Read the story
A value is a whole number or text. Text used as a number is 0, so a line of text is a command that does nothing, and a number used as text is its digits.
The machine
| Command | Does |
|---|---|
0 | Nothing |
1 a b | Copy cell a to cell b |
2 | Reverse the head |
3 | End the run |
4 a 11 | Print cell a; print a line feed |
5 a | Read a line of input into cell a |
6 a 7 n | Jump to cell a; jump n cells on |
8 a 9 a | Add 1 to cell a; take 1 |
10 a b c d | Jump to c if cells a and b are equal, else to d |
12 a b 16 a b | Put the length of cell a in b and its characters or code points after it |
13 a n b 17 a n b | Join n cells from a into text, or n code points, and put it in b |
15 a n | Put a random number from 0 to n in cell a |
Reading a cell that was never written gives 0. Reading a command from one ends the run. Command 14 runs another script file in a sub-interpreter, and since there are no files it stops the run with an error.
Example
The Hello world on the specification is two lines.
The Hello world on the specification is two lines. The text in cell 0 does nothing. The 4 takes its argument from cell 2, which was never written and so reads as 0, and prints cell 0. Cell 3 is empty, so the run ends.
A count to 5. Cell 11 is the counter and cell 12 holds the 5. The 11 in cell 4 is a command and the same number in cell 1 is an address.
The quine in the specification prints its cells one by one with a counter it keeps in cell 18. When the count reaches 18 that cell holds 18, and the same for cell 26, so they print what the source had there.
Input comes a line at a time.
Patterns it teaches
- Self-modifying code, commands and data share the cells.
- Code as data, the quine reads its own lines as values.
- Quine, 32 lines that print themselves.
Further
See also
Cell-based
Write your own in Run Convert a program from OIL
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: oil.
Command line
shib run oil -e 'Hello World
4'shib manual oilSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/oil.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org