esolang

Glass

Object orientation in postfix, juggled on one stack.

Gregor Richards, 2005 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello World!

The idea

Gregor Richards developed Glass in 2005. It has classes, objects, constructors and methods, but every step is a one-character postfix command on a single main stack. To call a method you push the name of an object and the name of a function, look the function up with . and run it with ?. Even printing needs an object of the built-in class O first. The specification says no other language is implemented like this, because it would be idiotic.

The machine

A program is a list of classes, {Name[fname commands]...}, and it starts by making an M and calling its m.

CommandDoes
a (name)Push a name
0 (12)Copy the item that many places down
"text" <3.5>Push a string or a number
, ^Pop; return
=Assign the top value to the name under it
!Make an instance of a class into a name
. ?Look up a function of an object; run a function
* $Push a variable's value; store the current object
/(name) ... \Loop while the variable is true

Names in capitals are global, names that start with _ belong to the call, and other names belong to the current object. Only a number other than 0 and a string other than empty are true. The built in classes are A for arithmetic, S for strings, O for output, I for input and V for fresh global names.

Example

The cat keeps I, O and A objects in the fields a, b and c and loops while I.e, the end of input test, is…
Expected: cat
Expected: 42

The cat keeps I, O and A objects in the fields a, b and c and loops while I.e, the end of input test, is not 1. The specification also has a recursive Fibonacci, a quine, the 99 bottles of beer and a brainfuck interpreter, all of which run.

Further

Ideas it shows

Object-oriented paradigm

Stack-based

Write your own in Run Convert a program from Glass

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run glass -e '{M[m(_o)O!"Hello World!"(_o)o.?]}'
shib manual glass

Source

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

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

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