esolang

Shark

Four registers, a memory map and a stack of return points, driven by one letter at a time.

Madk, 2019 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello world!

The idea

Madk made Shark in May 2019. It is a small register machine. Registers A, B, C and D, every memory address and every value in memory are integers with no upper bound, and all of them start at 0. Nearly all arithmetic happens in A, and the other registers are reached by swapping.

Read the story

There is no jump to a label. A loop pushes its own place with ^, and & jumps back to just after it. Conditions are a skip of the next instruction, ? when A is 0 and ! when it is not.

The machine

CharDoes
i d l r q - 0A plus 1, minus 1, times 2, halved, squared, negated, zeroed
+ * %A becomes A+B, A*B, or the remainder of A by B
@ ' " $Swap A and B, swap A and C, swap B and D, copy A into B
> < wStore B at address A, load it into B, swap the two
? !Skip the next instruction if A is 0, or if it is not
^ & ~ xPush this place, jump after the top one, pop and jump, just pop
{Jump back 3 instructions
: ; nPrint A as a number, A as a character, a line feed
. ,Read a line as a number, read a character

A run ends past either end of the program, on a remainder by 0, or on ~, x or & with an empty control stack. # starts a comment, and every other character is ignored and takes no slot.

Example

Hello world builds each letter from the one before.

Hello world builds each letter from the one before. iiilql makes 72 for H. rrriqi halves that three times to 9, adds 1, squares and adds 1 again for 101, an e.

The cat keeps 10 in B, then loops on reading and printing a character. It adds 10 to the negated character, so the sum is 0 just after a line feed and the skip leaves the loop.

Expected: hello

The Collatz program prints a prompt, reads its number and keeps a comma at address 0. Each turn it stores n/2 at address 2 and 3n+1 at address 3, and picks one with n%2+2.

Expected: >6,3,10,5,16,8,4,2,1

The specification also has a Fibonacci program that prints the first 128 numbers. The last is 155,576,970,220,531,065,681,649,693, which needs the unbounded integers.

Further

Ideas it shows

Also in Turing tarpits

Write your own in Run Convert a program from Shark

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run shark -e '# Echoes input up to the first newline '\''\n'\''
iilil@^,;-+?&x' --input 'hello
world'
shib manual shark

Source

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

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

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