face
Every variable is a C pointer, NULL at the start, and the program allocates its own memory. The name stands for "fairly awful c-based esolang".
Keyboard Fire, 2017 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Keyboard Fire made face in 2017. The README gives the reason in one line, the wish for an esolang that makes you allocate your own memory. Each command is one character followed by the one-character names of the variables it works on, so +abc means *a = *b + *c. There are 128 variables, one for each ASCII character, and every one of them starts as a NULL pointer. Writing a number before allocating crashes the program, as it would in C.
Read the story
The reference interpreter is written in C and hands most of the work to the C library, to malloc, fread, fwrite, sprintf and sscanf. It uses libffi to give sprintf as many arguments as the program asks for.
The esolangs.org page called Face describes a different language, made of emoticons. This implementation follows Keyboard Fire's interpreter, which Try It Online runs.
The machine
Numbers live behind the pointers, and the current mode says how to read them. ,c ,s ,i ,l ,m set char, short, int, long and long long (lower case unsigned, upper case signed), ,f ,d ,e set float, double and long double, and ,p sets pointers. The mode at the start is signed int.
| Command | Does |
|---|---|
+ - * / % & \| ^ < = > | *a = *b op *c; the comparisons give 1 or 0 |
!ab ~ab | Logical and bitwise not |
5a | Any digit: *a = 5 |
mab cab | a = malloc (or realloc) or calloc of *b elements |
$ab | a takes b's pointer |
'a `a "ab | Move a one element on, one back, *b elements on | |
{a _a }ab | Mark a's pointer as its original, go back to the original, *a = how far b has moved |
\ab | a points at the program's own bytes, b at the instruction pointer |
i o e then a name | Standard input, output, error |
rabcd wabcd | *a = fread or fwrite of *c bytes at b on stream d |
p s | sprintf and sscanf, with type and variable pairs after them |
:x .x ?ax | A label, a jump, a jump when *a is not 0 |
(...) q | A comment, quit |
A jump searches forward for : and its label and wraps around at the end, so a jump to a missing label hangs. Before the program runs, @ becomes a NUL byte, which ends a C string, and # escapes the next byte: #J is a newline. Since \ gives a pointer to the program itself, text in a comment is data the program can print, and a program can rewrite its own code.
The Hello World is a comment holding the text and then code that prints it. \$* points $ at the program and * at the instruction pointer. m%* allocates some ints for %; 7% and +%%% make the first one 14. ,c'$ moves $ one byte on, past the (. Then oo sets o to standard output and w%$%o writes 14 bytes from $.
Example
The second program multiplies 9 by 4 and formats it with %d, a format string kept in the comment.
The second program multiplies 9 by 4 and formats it with %d, a format string kept in the comment. The third writes the first 5 bytes of itself, then 4, 3, 2 and 1. The last reads a number with sscanf, adds one and prints it with sprintf.
Patterns it teaches
- Hostile design: manual memory, pointer arithmetic and crashes, on purpose.
- Code as data: strings and format strings sit in comments and the program reads them through a pointer to itself.
- Self-modifying code: the same pointer can write over the program while it runs.
Try this
- Print
Hifrom a comment. - Print the numbers 1 to 5 with a loop and
sprintf. - Hard: read a line and print it backwards.
Further
- The reference interpreter, in C, with tests and examples
See also
Unknown year
Write your own in Run Convert a program from face
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: face.
Command line
shib run face -e '\$*mi*m1*115io>:_wi$i>-ii1?i_'shib manual faceSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/face.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org