Settings

Theme

Compiling a small Scala subset into x86-64 asm

mykolav.github.io

1 points by _f5ah 4 years ago · 1 comment

Reader

_f5ahOP 4 years ago

Hi HN!

I wrote a toy compiler.

Here I tried to describe it in detail: https://mykolav.github.io/coollang-2020-fs/

And the repo is here: https://github.com/mykolav/coollang-2020-fs

The project was purely for fun and to other people it's, honestly, just another toy compiler. But there are a couple things that should set it apart.

1) It compiles down to x86-64 assembly. Then invokes GNU as and ld to produce a native executable. To me personally, this is much more rewarding than emitting MIPS asm and using an emulator to run it. I also prefer emitting asm to emitting, for example, C -- at the very least, it forces the developer to figure out converting expressions into asm. That really drives home the point how much work high level langs do for us.

2) The lang is simple but not too simple. A lot of mini-compilers have languages with functions, primitive values and pretty much nothing else. Whereas this project's lang has classes, inheritance, virtual dispatch, and even a very simple form of pattern matching.

3) The write-up describing the project. Final sections contain a number of links to awesome compiler-learning resources. Every major topics is covered only by one or two links. Obviously, I had to make these sections opinionated, but give it a chance, it might click for you too.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection