Radiant Log #011

Radiance Intermediate Language

After finishing the semantic analyzer I started working on the Radiance Intermediate Language (RIL). This took longer than expected, as this intermediate language is fairly low level, which means that most of the logic for compiling the high level syntax tree to machine instructions is contained within this compiler phase.

fn w32 $fib(w32 %0) {
  @entry
    br.slt w32 1 %0 @merge @done;
  @done
    ret %0;
  @merge
    sub  w32 %1 %0 1;
    call w32 %2 $fib(%1);
    sub  w32 %3 %0 2;
    call w32 %4 $fib(%3);
    add  w32 %5 %2 %4;
    ret  %5;
}
The fibonacci function in RIL.

The good news is that it makes the next and final phase (machine code emission) simpler, as it’s only a matter of allocating physical registers and selecting the right RISC-V instructions.

For this module, as an experiment, I decided to try asking an AI agent1 to generate the initial code. It took about a day to produce the module2 this way, but three weeks to review and finalize the code. Whether or not I saved time is not clear, I would have estimated about a month’s work had I written it by hand.

Since this is Radiance code we’re talking about, the results are not perfect: there is no Radiance code in the wild to train on, so the agent has to do in-context learning. Still, it managed to write working code in the end, but it was of fairly poor quality. I had to rewrite a lot of it, and this is what took so long. In the end, I managed to trim about 20% of the initial code size by factoring out shared functionality.

I’m happy with the results, though I may try a different approach next time. I think a more hands-on approach in the initial code generation is much more effective.

Check out the new Radiance Intermediate Language page for all the details.


  1. I used Claude Code with Opus 4.5 for this. 

  2. The module it produced was around 5K lines of code, which I managed to bring down to around 4K lines through careful auditing.