Factory
A claw in a byte factory carries ones and zeros from room to room, one bit at a time.
Enoua5, 2016 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Enoua5 made Factory in 2016. A program steers a claw over nine rooms in a row. Bits come out of production, wait in storage, get flipped in the inverter or combined in the and machine, and leave through shipping as bytes. Input arrives in supply as a pile of bits.
Read the story
The claw holds one bit at most and has one bit of RAM, which is all a loop can test. So the Hello World makes 104 trips from production to shipping, one line for each bit, and then ships them with O. A 1 goes straight there. A 0 goes through the inverter on the way.
The machine
| Room | What it does with bits |
|---|---|
| production | Hands out bits of one kind, 1 at the start; a bit dropped here sets the kind |
| storage 1, 2 and 3 | A stack each |
| garbage | Destroys what is dropped there |
| shipping | A stack; O prints it as bytes, bottom first, and empties it |
| supply | A stack; I fills it with a line of input, the first bit on top |
| inverter | Keeps one bit, flipped |
| and | Keeps one bit; a second one dropped there is ANDed into it |
| Command | Does |
|---|---|
< > | Move one room left or right |
v | Pick up the top bit, or drop the one held |
^ | Copy the held bit to RAM, or flip RAM when holding nothing |
O I | Ship; ask for input |
loop { } | Repeat while RAM is 1 |
eloop { } | After a loop, repeat until RAM is 1 |
DEF_name ... END | Define a function, called by its name on a line of its own |
q | Leave the function |
/ starts a comment, and spaces and tabs do not count. The specification leaves open whether an eloop also runs after its loop has run. In this implementation it does not, so a loop and its eloop work as an if and an else. That choice does not change the cat.
Example
One character, !, which is 00100001 in binary.
One character, !, which is 00100001 in binary. Each line takes a 1 from production. A 0 goes on to the inverter, two rooms past shipping, and comes back flipped.
The cat, without its comments. The function checkHeld leaves RAM at 1 when the claw holds a bit and at 0 when it does not. The main code fills supply with a line of input and moves its bits one at a time onto shipping until supply is empty. Supply has the first bit on top and shipping is read from the bottom, so the bytes come out in their order.
Further
Ideas it shows
See also
Stack-based
Write your own in Run Convert a program from Factory
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: factory.
Command line
shib run factory program.txt --input 'Hi'The program is long; save it as program.txt first.
shib manual factorySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/factory.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org