esolang

Headache (lang that compiles to brainfuck)

C-like code in, brainfuck out.

Turing complete: yes · ●○○ easy · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello World

The idea

Headache is a language for writing brainfuck without writing brainfuck. It borrows most of its syntax from C, and its compiler, hac, turns a program into brainfuck that runs on any 8-bit brainfuck interpreter. It comes with its own brainfuck interpreter for debugging, and with an expander that turns 8-bit brainfuck into 16-bit or 32-bit brainfuck.

Read the story

The specification shows the brainfuck that hac makes from its Hello World. It is 394 commands long and never moves the pointer. One cell climbs to 72 for the H, prints it, and then moves up and down from letter to letter, 12 prints in all.

Because the target is 8-bit brainfuck, a byte is one cell. Arithmetic wraps at 256, and the specification says 0/0 gives 0.

The machine

This implementation runs the part of Headache that its wiki page shows, directly and without the brainfuck in between.

CodeDoes
void main() { ... }The program
byte a;Declare a variable, one cell that starts at 0
a = (10*6+3)/7;Assign; * and / bind before + and -
@"text\n";Print a string
@a;Print a byte in decimal
/* ... */A comment

The rest of the language is described only on its official wiki, so there are no loops, conditions, input or other functions.

Example

The arithmetic program.

The arithmetic program. Division rounds down and 0/0 gives 0, so c is 0 + 1 and d is 1 + 1 + 1.

Expected: a: 9 b: 5 c: 1 d: 3

A cell holds 0 to 255, so 200 and 100 make 44.

Expected: 44

Patterns it teaches

Further

Brainfuck

Write your own in Run Convert a program from Headache (lang that compiles to brainfuck)

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: headache-lang-that-compiles-to-brainfuck.

Command line

shib run headache-lang-that-compiles-to-brainfuck -e 'void main() {
    @"Hello World\n"; 
 }'
shib manual headache-lang-that-compiles-to-brainfuck

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/headache-lang-that-compiles-to-brainfuck.js

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

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