News for hackers. Stuff that matters.
Re:Compilers: Incrementally and Extensibly by tester756 on Saturday April 05, 2025 @02:39PM (#43595652)
>supporting multiple codegen architectures

Shouldnt it be a result of modular software design?

>exposing the compiler as an API for external tooling

Isn't it just generating libraries instead of executables?

Re:Compilers: Incrementally and Extensibly by tiu on Saturday April 05, 2025 @03:23PM (#43596118)
I wrote 'multiple codegen architectures' instead of 'multiple architectures for codegen'.

As far as I have done in the toy compilers and seen the things in actual production ready compilers, the codegen is still very much tied to the one thing or the other rest llvm.

Re:Compilers: Incrementally and Extensibly by elcritch on Sunday April 06, 2025 @02:47AM (#43599433)
Nim has multiple backends and is relatively mature. It’s fairly readable as compilers go.

There’s also a new experimental rewrite of the Nim compiler called Nimony which targets a new intermediate called NIFC. That is intended to the be transformed to C, LLVM, JavaScript, etc.

Re:Compilers: Incrementally and Extensibly by tester756 on Sunday April 06, 2025 @04:37PM (#43604777)
>I wrote 'multiple codegen architectures' instead of 'multiple architectures for codegen'.

You want to generate e.g x86 + ARM + RISCV, yea?, and shouldnt it be a result of modular architecture?

like your various codegens just take your AST and generate output

Re:Compilers: Incrementally and Extensibly by remexre on Saturday April 05, 2025 @02:59PM (#43595906)
Making the _compiler itself_ provide an API enables things like LSP, which don't want to generate machine code at all. A traditional single-pass compiler usually can't accommodate this without re-plumbing.
Re:Compilers: Incrementally and Extensibly by halffullbrain on Saturday April 05, 2025 @04:13PM (#43596467)
The Eclipse Compiler for Java [1] is a notable exception, architected around incremental compilation, an API for “live” AST manipulation, and a layered non-batch approach to when to invoke various analysis steps.

The LSP for Java [2] used in eg. VSCode’s Java plugins, builds on this API.

But, no, I haven’t seen a generalized approach to this architecture discussed in literature.

1: https://github.com/eclipse-jdt/eclipse.jdt.core 2: https://github.com/eclipse-jdtls/eclipse.jdt.ls

Re:Compilers: Incrementally and Extensibly by tester756 on Sunday April 06, 2025 @05:31PM (#43605124)
I'm aware, I've used C#/.NET Compiler ecosystem and their Compiler as a Service approach

But it seems like you're just creating libs that everyone and embedd / use and that's it

e.g `auto ast = Compiler.GenerateAST(code);`