Blockfunge
Befunge cut into boxes. Each box is a function, and an arrow points at it from its name.
CraftSpider, 2019 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
CraftSpider made Blockfunge in 2019, after Befunge. A program is a drawing of ASCII blocks, /--\ over | | over \--/. A block gets its name from an arrow pointing at its border with the name at the other end, so main over v over a block names it main. add[2] names a block that takes two arguments.
Read the story
Inside a block an instruction pointer runs as in Befunge. The new part is the token register. Letters and digits are gathered into it, and any other character pushes it onto the stack. Digits alone go on as a number, anything else as a token, a variable name that is looked up only when something uses it. Calling ( runs the block named on top, and the function returns when its pointer leaves the block.
Blockfunge has no output at all. The specification gives each result as the stack that main halts with, so this implementation prints that stack, bottom first, one item a line. The specification is still a draft. Types and externs have no rules yet, and its own Python interpreter does not run them either; they are read but cannot be called.
The machine
| Char | Does |
|---|---|
^ v < > | Point the pointer; v is why no token can hold a v |
: ; | Reverse; skip the next cell |
[ ] | Let the pointer through if the top is true, or false; else reverse |
? | Skip the next cell if the top is false |
( | Call the block named on top |
+ - * / % | Arithmetic on A, the top, and B, the value under it |
! & \| ~ # | Not, and, or, xor, equal |
= | Set the token A to the value B |
" | Read a string up to the next " |
` , | Push the stack size; drop the top | |
' \ | Make the top a string; make it a token |
@ $ | Get or set a character of the current block |
The specification says which of A and B is the top only for = and ., and there A is the top. This implementation reads every operator that way, so 5 3 - gives -2.
Example
The first example sets a variable and reads it back.
The first example sets a variable and reads it back.
The second leaves the token on the stack, because nothing used it.
A call. Main pushes 1 and 2, turns down at v and right at >, gathers add and calls it with (. add[2] starts with both numbers on its stack and adds them.
Patterns it teaches
- Two-dimensional control flow: with the plane cut into named functions.
- Self-modifying code:
@and$read and write the block's own characters.
Further
See also
Object-oriented paradigm
Functional paradigm
Write your own in Run Convert a program from Blockfunge
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: blockfunge.
Command line
shib run blockfunge -e 'main
v
/---------------\
| 1 VAR = VAR |
\---------------/'shib manual blockfungeSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/blockfunge.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org