Working through ‘Writing A C Compiler’ – Introduction

The introduction covers a lot of important stuff about implementing the compiler.

Platforms

The book is setup to work on Linux and Mac. I am a primarily Windows dev (ex MSFT employee), I do a fair amount of contributions to rust projects and so do stuff on all three platforms, but Windows is where I do the heavy lifting (except when I am on the road, when I use my awesome first gen M1 mac book air, only 8gb but it never breaks a sweat, plus all day battery life, a true engineering marvel)

The book suggests using WSL if you are on Windows. I use WSL a lot but prefer to run natively on Windows.

I thought “how hard can it be to make it work on windows?”. I will go into details in chapter 1.

The back end of the compiler targets the x64 instruction set. This is fine. I note that my end intent is to at least try to target the hack cpu in nand2tetris.

Implementation language

I love rust and it seems like a good match, Nora mentions it as a possible language because it has pattern matching. I concur.

IDE

I use Visual Studio Code. I also use (I paid for it although I think a limited version is now free) github copilot. I have found that this tool is particulary good for writing things like emulators and compilers where there is repeated code like this

                '(' => Token::LeftParen,
                ')' => Token::RightParen,
                '{' => Token::LeftBrace,
                '}' => Token::RightBrace,
                ';' => Token::SemiColon,

Once it has seen what you are doing it correctly works out what you are doing and is very good at extending it.

I also use Visual Studio. It has an excellent assembler level debugger. It needs to be installed in order to get rust working, plus this book needs a c preprocessor, assembler and linker (some tests need a c compiler too). Visual Studio Community Edition is free for hobbyist use.


Now on to chapter 1


Comments

2 responses to “Working through ‘Writing A C Compiler’ – Introduction”

  1. cs6505wp Avatar
    cs6505wp

    Excellent post. I just bought WACC last night and was wondering the same thing – all my PC’s are Windows. I have a Chromebook with a Linux container and managed to get VS Code running on it.

    Anyways – looking forward to your “chapter 1” post.

    Thanks!

    Liked by 1 person

    1. Welcome to the WACC journey. It’s a fun ride. I just completed chapter 14, working on a very long post for that.

      Like

Leave a comment