Part II · Brainfuck Compilation

Acus: A Typed C++ Compiler Backend for Generating Brainfuck

Acus provides the abstractions needed to translate higher-level programs into Brainfuck: types, variables, arrays, structs, pointers, functions, stack frames, control flow, and optimization.

Backend model

01

Structured input

Typed expressions, declarations, functions, and explicit control flow.

02

Tape model

Frames, slots, macro-cells, indirect access paths, and materialization.

03

Brainfuck output

Optimized primitive sequences collapsed into canonical BF commands.

Contents of this part

Brainfuck Compilation

Each chapter is presented as a standalone, linkable page with its own local table of contents and previous/next navigation.

View complete contents
01

Introduction to Acus

Acus 4 is not a BF compiler: it is a C++ library for the development of such compilers. This chapter is not a guide on how to use Acus. For examples and extensive API details, please visit the GitHub repository at [10] .…

3 min read
02

Acus Program Model

In the Acus model, a program consists of a series of basic blocks, sequences of code that are always executed in order, and jumps between those blocks. Each basic block ( B i ) is compiled into its corresponding BF…

6 min read
03

Tape Abstractions

The data-tape is considered a stack, where each function owns a stack frame. Each frame is composed of slots: a return-slot (if the function returns a value), argument-slots (if the function takes arguments) and local…

19 min read
04

Memory Management

Whenever a variable is declared in Acus, the allocator will look for available space in the current stack-frame. From the allocator’s point of view, named locals, compiler temporaries and cache slots are all typed slots inside…

3 min read
05

Code Generation

Before discussing larger compiler structures such as caching and dynamic access, it is useful to look at the small Brainfuck idioms from which Acus builds its generated code. Many of the algorithms in this chapter are simple…

18 min read
06

Caching

Slot proxies (Section Slot Proxies and Materialization ) allow expressions to remain abstract until their value is needed. However, repeatedly materializing the same proxy can duplicate work. For example, accessing the same…

6 min read
07

Other Optimizations

The caching system is one of the optimizations used by Acus to try to somewhat limit the number of generated BF instructions, which tends to grow very fast for complex programs. Even though it was never a goal to produce…

6 min read