esolang

Nqubl

Instructions do not run when they are read. They wait in a queue until an x runs them all.

David.werecat, 2012 · Turing complete: unknown · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, world!

The idea

David.werecat made Nqubl in 2012. Reading an instruction only puts it in a queue. x runs everything queued, in order, and an i in front of an instruction runs it at once. A few instructions are always immediate, namely the jumps, x itself, and w, r and :, which swap, rotate and copy the queued instructions.

Read the story

The result is code that reads in one order and runs in another. A test written inside the queue can skip the next instruction outside it, so a program decides where to jump only after the queue has run.

The machine

Eight stacks (0 1 A-F) and eight registers (2-9) of integers. A register is a stack whose top stays when it is popped. Popping anything empty gives 0, and true is -1.

InstructionDoes
x iRun the queue; run the next instruction now
w r :Swap, rotate or copy queued instructions
s3 t3Switch to stack 3; move the top to stack 3
~12~ "text"Push a number; push the characters
g u lRead a character, a number, a line
p n eWrite a character, a number, the whole stack
c m d !Copy, add 1, subtract 1, bitwise NOT
+ - * / \ \| & ^ < > =Top op the one under it
k fIf the popped value is 0, skip the next instruction outside or inside the queue
{ } #Jump back or forward to the matching #
q o zQuit, push the stack size, push the queue size

Example

Hello World pushes the text backwards, so e writes it top first.

Hello World pushes the text backwards, so e writes it top first.

The cat queues a test and runs it with x. The k inside the queue skips the } after it unless the byte was -1, the end of input. Then ip prints the byte at once and { goes back.

Expected: cat

Fibonacci numbers, kept in two registers. It stops after the first one above a million, which it prints without a line break.

Expected: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269

The specification also has a Deadfish interpreter in 13 lines. It reads one command per line, and given i, i, s, o it prints its prompt four times and then 4.

Patterns it teaches

Further

Queue-based

Stack-based

Write your own in Run Convert a program from Nqubl

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run nqubl -e '#igc~-1~=kx}ip{#' --input 'cat'
shib manual nqubl

Source

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

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

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