Each chapter is presented as a standalone, linkable page with its own local table of contents and previous/next navigation.
View complete contentsPart 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
Structured input
Typed expressions, declarations, functions, and explicit control flow.
Tape model
Frames, slots, macro-cells, indirect access paths, and materialization.
Brainfuck output
Optimized primitive sequences collapsed into canonical BF commands.
Contents of this part
Brainfuck Compilation
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] .…
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…
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…
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…
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…
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…
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…