esolang

FFM/FFB

A program is a table of states. Each state does one thing, looks at one byte and picks the next state.

Enoua5, 2017 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 10 known programs · Test method

Run it

Expected: cat

The idea

Enoua5 made FFM/FFB in 2017. FFM, Foxrabbit's Finite-state Map, is the text form, and FFB, Foxrabbit's Finite-state Binary, is what it compiles to. There is no list of instructions and no jump. Every line is a state with one command, a bar and two states to go to next.

Read the story

esolangs.org files it as a finite-state automaton and says it is not Turing complete. But the machine sits on a tape that is endless both ways, and the specification's own port of the brainfuck Hello World turns each brainfuck command into one state and each loop into a test against the bar 1. Every brainfuck program translates that way.

The machine

A state is written name;command;bar;fail:pass. Entering it runs the command. Then the cell under the head is compared with the bar. If the cell is at least the bar the machine enters the pass state, otherwise the fail state. The first state in the file is entered first.

FFMFFBDoes
lft rgt0 1Move the head
inc dec2 3Add or subtract 1, wrapping at 255 and 0
inp4Read a byte into the cell, -1 at the end of the input
out5Write the cell, 0 for -1
nop6Nothing
hlt7Halt

A cell holding -1 fails every test. FFB starts with a byte that says how many bytes an address takes, then gives each state as a command byte, a bar byte and two big-endian addresses. This implementation reads FFB as base64, the way the specification prints it.

Example

The cat reads a byte.

The cat reads a byte. A real byte is at least 0 and passes to out. The end of the input leaves -1, which fails to hlt.

The same cat compiled to FFB with one byte per address, 13 bytes in all.

Expected: cat

The reverse cat walks right while it reads, then walks back and prints until it meets the 0 left of the first byte.

Expected: desserts

The Hello, world! counts each cell up to its letter with a state that loops on itself while the cell is below the bar. Its last counting state moves on after one step either way, so the program ends with a byte 1 where a line feed was meant. The compiled FFB on the specification does the same.

Patterns it teaches

Further

Declarative paradigm

Cell-based

Write your own in Run Convert a program from FFM/FFB

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: ffm-ffb.

Command line

shib run ffm-ffb -e 'AQQAAgEFAAAABwACAg==' --input 'cat'
shib manual ffm-ffb

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/ffm-ffb.js

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

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