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
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.
| Instruction | Does |
|---|---|
x i | Run the queue; run the next instruction now |
w r : | Swap, rotate or copy queued instructions |
s3 t3 | Switch to stack 3; move the top to stack 3 |
~12~ "text" | Push a number; push the characters |
g u l | Read a character, a number, a line |
p n e | Write a character, a number, the whole stack |
c m d ! | Copy, add 1, subtract 1, bitwise NOT |
+ - * / \ \| & ^ < > = | Top op the one under it |
k f | If the popped value is 0, skip the next instruction outside or inside the queue |
{ } # | Jump back or forward to the matching # |
q o z | Quit, 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.
Fibonacci numbers, kept in two registers. It stops after the first one above a million, which it prints without a line break.
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
- Stack machines: sixteen stacks, half of them sticky.
- Self-modifying code:
w,rand:rearrange the code that is waiting to run.
Further
See also
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 nqublSource
- 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