8f4e

8f4e is a stack-oriented programming language designed for real-time audio synthesis, with a visual code editor built for live coding and experimentation.

I started it as a recreational programming project during the COVID-19 lockdown to perform generative music at algorave events.

Its primary target is the WebAssembly virtual machine, as I wanted an efficient yet portable tool for real-time audio signal generation and processing.

Stack-Oriented Execution Model

Stack-oriented programming means that instead of using registers, instructions take their operands from a stack and push their results back onto the same stack for the next instruction to consume.

I chose this programming paradigm because the WebAssembly virtual machine is itself a stack machine.

Staying native to this execution model avoids costly abstractions and makes it possible to write faster programs compared to typical WebAssembly-targeting languages.

...
067 push 2
068 push 3
069 ; Pushing values 2 and 3
070 ; onto the stack.
071 add
072 ; After executing the
073 ; add instruction,
074 ; the stack will contain
075 ; the value 5
076 push 10
077 mul
078 ; Now the stack will
079 ; contain the value 50
080 push 10
081 div
082 ; Now 5 again
...

Memory Access and Pointers

Unlike in most programming languages, memory addresses in 8f4e are determined by the compiler and inlined at compile time.

This allows direct memory access with pointers, without requiring an additional indirection layer such as a heap or garbage collector.

...
003 int result
...
069 push &result
070 ; The variable name
071 ; prefixed with &
072 ; gives its memory address.
073 push 42
074 store
075 ; The store instruction
076 ; takes two values:
077 ; a memory address
078 ; and the value to store.
...

All memory items are laid out sequentially in memory, so variables declared one after another occupy adjacent memory locations.

They are aligned on a 32-bit grid, which means every memory item starts at an address that is a multiple of 4 bytes.

...
003 int   a 42
004 
005 float b 3.14
006 ; Memory address of b
007 ; is address of a + 4
008
009 int   c -5
010 ; Memory address of c
011 ; is address of b + 4
...

Dynamic memory allocation is not supported in 8f4e, but it has no place in the hot path of audio processing anyway.

Live Variable Editing

8f4e supports real-time editing of variable values while a program is running, without recompilation.

This is made possible by the deterministic allocation strategy: because memory addresses are fixed at compile time, the compiler can provide the exact address of every memory item, allowing the editor to locate and update any variable directly.

...
003 int foo 10
004 ; You can change these
005 ; values in the editor
006 ; while the program is running.
007 float bar 3.14
008 ; The editor will trace
009 ; them back in the memory
010 ; and update their values
011 ; without restarting
012 ; or recompiling the program.
...

Endless Execution Loop

Programs in 8f4e run in an endless loop. This reflects how real-time audio systems operate, where processing consists of continuously reading from and writing to audio buffers.

8f4e removes this control flow boilerplate and allows programs to focus purely on signal generation and transformation.

Modules and Execution Order

The code is organized into modules, each containing variable declarations and a sequence of commands.

The execution order of the code modules is determined by their dependencies. If a module's output is needed as input for others, it is executed first.

...
001 module foo
002
003 int  a 10
004 int  b 20
005 int  result
006
007 push &result
008 push a
009 push b
010 add
011 store
012
013 moduleEnd
...

All variables in 8f4e are inherently public, with no option to modify visibility.

8f4e is not memory-safe, pointers can point to anything within the memory space of the program, but the visual wires help developers to find where their pointers are pointing.

...
003 int* pointer
004
005 push &pointer
006 push pointer
007 push 4
008 push add
009 store
010 ; pointer will iterate through
011 ; memory in 4-byte steps.
...

What 8f4e is NOT

8f4e is not a general-purpose programming language. It is not designed for building applications, services, or user interfaces.

It doesn't mean that it would be impossible to build such things, but it would be impractical and inefficient to do so.

Nevertheless, I would love to see someone build a web server or a game engine in 8f4e, just to push the limits of the language.