esolang

SMITHb

The program and the stack are one list, eaten at the front and grown at the back.

Zzo38 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello World!

The idea

Zzo38 made SMITHb, or SMITH flat, with no jumps and no loops. A program is a list of whole numbers and nulls, written *. Each step takes the first two elements, deletes them and runs the command their signs pick. The end of the same list is the stack. So a program can only go forward, and a loop copies its own code onto the end, where the front will reach it again.

The machine

The first element is X and the second is Y. Each is null, zero, negative or positive, which makes sixteen commands.

X YDoes
* *Stop
0 * * 0Print the top as a character; read one and push it
0 0Flip the top, positive and negative, null and zero
- -Copy stack elements X to Y onto the top
- +Push element X divided by Y
+ -Swap program element X with stack element Y
+ +Run the command made by program elements X and Y
+ 0 - 0Delete X elements from the top; delete element X
+ * - *Sum the top X elements; swap element X with the top
0 + 0 -Copy the top Y times; reverse everything if element Y is zero or null
* + * -Delete the next Y program elements; reverse from element Y to the top

Stack element -1 is the top and -2 the one below it. Program element 1 is the first one after the command. Before the run name(value) defines a macro, 12(...) repeats, "H" is the number of a character and ; starts a comment.

Example

Hello World is twelve prints, a stop, and the characters with the first one on top.
Expected: HiHi

Hello World is twelve prints, a stop, and the characters with the first one on top. In the second program -2 -1 copies the top two elements, so four prints find H and i twice.

The cat is two copies of six elements. The first copy reads a character, prints it, and with -6 -1 copies the last six elements onto the end, which are the second copy. The specification leaves open what happens at the end of the input, and it ends the program.

Expected: cat

Patterns it teaches

Further

Self-modifying

Stack-based

Write your own in Run Convert a program from SMITHb

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run smithb -e '2(* 0 0 * -6 -1)' --input 'cat'
shib manual smithb

Source

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

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

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