Profile cover photo
Profile photo
Rob Thornton
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." - Albert Einstein
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." - Albert Einstein
About
Rob's posts

Post has attachment
The Accumulator Register
At all curious about the accumulator register? I was. Here's a little summation of what I discovered. Overview In modern, general purpose CPUs, the accumulator register has lost some of its meaning and much of its use has been relegated to convention rather...

Post has attachment
Compiler 3 Part 8 - Finale
This will end up being the longest, and final, post in the series. So let's tuck in! Testing and Everything Else The scanner and most of the infrastructure stayed exactly as it was. The parser and AST did see some changes. The parser, in particular, saw sev...

Post has attachment
I've completed a third, 8 part series, on learning how to write a compiler from scratch.

Post has attachment
Compiler 3 Part 7 - Code Generation
Here we are at the final step . As mentioned in the introduction, I cut out a massive amount of code by offloading much of the work on the IR. So here is what has changed. I introduced a small function to map Calc types to C types. This could probably exist...

Post has attachment
Compiler 3 Part 6 - Tagging
This step is crucial to Calc’s code generator but may not exist at all in other compilers. Regardless, it makes code generation for Calc dead simple. Before I can get into the process, you do need a little background information. In the introduction I menti...

Post has attachment
Love this language! 

Post has attachment
Compiler 3 Part 5 - Constant Folding
The only optimization included in series 2 was constant folding . Unlike in the previous series, we’re now much better equipped to handle this optimization. I feel that I should point out that most C compilers do this step, too. I was somewhat reluctant to ...

Post has attachment
Compiler 3 Part 4 - Type Checking
Whether you chose to produce assembly or an intermediate language, the job of the IR is to take us ever closer to generating actual output. We need to do the crucial step of type checking . Since Calc’s type system is strong and static it is necessary to en...

Post has attachment
Compiler 3 Part 3 - Intermediate Representation
After presenting Calc2 I came to discover that many parts of the compiler were quite fragile. The type checking was particularly bad, occasionally reporting type errors (false positives) when run over the  exact same source code  multiple times.  That’s a s...

Post has attachment
Compiler 3 Part 2 - C Runtime and Code Generation
Before diving into the real meat and potatoes of the changes that led to the runtime being (temporarily) removed, I thought I should discuss the motivations. The runtime irked me greatly because I felt that I did not leverage the power of C nor the C compil...
Wait while more posts are being loaded