r/Compilers • u/General_Purple3060 • Aug 27 '26
AET: Adding an Explicit Semantic Layer to C for OO
I've been working on AET, a GCC-based extension of C.
It adds three things: object-oriented programming, generics, and heterogeneous computing.
I've already written about Delayed Specialization (generics) and Execution Domain (heterogeneous). This post is about how I actually implemented OO.
The core idea is simple:
Don't try to force new language semantics through ordinary AST nodes and symbol tables.
Give them explicit semantic entities inside the compiler.
In AET the mapping looks like this:
class$ → ClassInfo
impl$ → ClassImpl
method → ClassFunc
call site → Funcall
These are not just AST nodes. They own data, support operations, and keep relationships with each other.
Example:
ClassInfo(Dog)
│
inherits
│
▼
ClassInfo(Animal)
│
└── ClassFunc(speak)
When the compiler sees `dog->speak()`, it resolves the class, inheritance, method and call through these entities first, then lowers the result into GCC's representation.
This makes complicated features much easier to keep under control. The compiler works with the language semantics directly instead of trying to encode everything into the AST.
The same pattern is used for the other two directions:
- Generics → `GenericBlock`, `GenericGraph`, `GenericCodes`
- Heterogeneous → execution-domain information attached to the entities
So the overall pipeline is roughly:
AET source
↓
semantic entities
↓
semantic analysis
↓
AST / GIMPLE / …
The important point is that the semantic entities exist **before** the program is lowered into the normal compiler IR.
I call this approach **semantic entity mapping**: mapping language concepts onto explicit compiler entities that can carry data, perform operations, and maintain relationships.
For me this has been a practical way to tame OO (and the other complex extensions) inside a C compiler.
I'm posting this because I think this kind of explicit semantic layer deserves more discussion. Curious how others structure the semantic side of their compilers.