esolang

GASOIL

The program is a stack too. Every instruction is popped off it and gone, so a loop has to put itself back.

Morex, 2009 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 9 known programs · Test method

Run it

Expected: Hello World!

The idea

Morex made GASOIL in 2009, after the HP-41C and HP-28S calculators. The name stands for General Application Stack Oriented Imperative Language. It has two stacks. The data stack holds numbers, strings and blocks of code in parentheses. The program stack holds the code still to run.

Read the story

There is no instruction pointer. Each step pops one element off the program stack, so the program shrinks as it runs. A loop is a call that pushes a block back on top, and an endless loop never runs out of room, because nothing waits to return. Even WHILE and FOR are postfix, so their blocks go on the data stack first.

The machine

ElementDoes
2 -4 3.1416 "text" (a; b)Push onto the data stack
CALL CCALLPut a named block on the program stack, CCALL only on a true condition
PARSEPut a block from the data stack on the program stack
ITE WHILE UNTIL FORIf, loops and a counted loop over a memory cell
+ - * / MOD SQRT INT RNDArithmetic
= != < <= > >= NOT AND OR XORComparison and logic, giving 1 or 0
DUP DROP SWAP12 and kinStack work, counting from #1 at the top
STO RCLStore #2 at address #1; recall
READ WRITERead a line; print a value
& STRLEN SUBSTR INSTR REPLACE ASCII CHRStrings
NOP commentNothing, so it writes comments

A program is a list of blocks, each under the name it is called by. The specification shows the data stack as the output, so this implementation prints whatever is left on it at the end, one value a line.

Example

The second adds 1 to 20.
Expected: 210

The second adds 1 to 20. FOR counts memory cell 0 from 1 to 20 and runs (0;RCL;+) each time, which adds the cell to the sum below it.

The Fibonacci numbers call suma again as long as the newest number is below 100. Each call adds the top two and leaves them all on the stack.

Expected: 1 1 2 3 5 8 13 21 34 55 89 144

The specification also has a prime finder, the whole of 99 bottles of beer built as one string, and a brainfuck interpreter with a block for each of the eight commands. It reads the brainfuck program as its first line of input and calls the block named after each character. All of them run.

Patterns it teaches

  • Stack machines: one stack for data, one for the program itself.
  • Code as data: blocks sit on the data stack until a loop or PARSE runs them.
  • Self-modifying code: the program is used up as it runs, and PARSE turns a string built at run time into code.

Further

Self-modifying

Stack-based

Write your own in Run Convert a program from GASOIL

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: gasoil.

Command line

shib run gasoil -e 'main
("Hello World!"; WRITE)'
shib manual gasoil

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/gasoil.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org