esolang

Locksmith

A program is a long number. Every digit is a command, and some take the next digit along.

Conor O'Brien · Turing complete: unknown · ●●○ moderate

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

Locksmith is a numeric language by Conor O'Brien. Only the digits of a source file count, so a program can be written as a combination for a lock, with any other text around it. There is one stack of integers, and a pushed number is always a single digit. Bigger numbers are built with 71, which pops two values and pushes top + 10 * second.

The machine

DigitsDoes
0dPush the digit d
1 2 3 4Add; negate; multiply; divide, rounding towards 0
5 … 6A loop: 6 jumps back to its 5 while the top is not 0
8 9Push an input byte, -1 at the end; print a popped byte
70 71 72Duplicate; top + 10 * second; move the item n deep to the top
74 75 76Push the stack size; reverse the stack; pop n and push 0 to n-1
77 78 79Pop; sign; 1 if two popped values are equal

Popping an empty stack gives 0. The loop test leaves the top where it is.

Example

Spaces are only there to show the commands.
Expected: 54321
Expected: cat

Spaces are only there to show the commands. In the second program, 04 08 71 makes 48, the code of the digit 0, and 012 1 adds -1. The cat reads a byte and adds 1, so the end of the input, -1, becomes the 0 that stops the loop.

Further

Ideas it shows

Also in Turing tarpits

Write your own in Run Convert a program from Locksmith

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run locksmith -e '8 011 5 012 1 9 8 011 6' --input 'cat'
shib manual locksmith

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/locksmith.js

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