Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

How to Write a Self-Hosted Go Compiler from Scratch

Gopher Academy via YouTube

Overview

Explore the process of creating a self-hosted Go compiler from scratch in this 31-minute conference talk from Gophercon 2020. Learn how Daisuke Kashiwagi, initially inexperienced in Go and compiler design, successfully developed two Go compilers without referencing the original. Discover the architecture of these compilers, including 'minigo' and 'babygo', and compare them to the official Go compiler. Gain insights into the challenges faced during implementation, such as handling maps, interfaces, and debugging. Follow Kashiwagi's journey from learning C and Go simultaneously to submitting patches to the official Go compiler. Understand the step-by-step approach to building a compiler, including the use of a stack machine and handwritten syscalls. This talk aims to demystify compiler construction and inspire you to embark on your own compiler-writing adventure.

Syllabus

Intro
Today's Goal
Architecture of my compilers
Architecture of the official Go compiler
minigo & babygo
Encounter with 8cc
Learn C and Go at the same time
Tried writing a Go compiler
Writing a Go compiler in Go: the hard parts
minigo: Struggles in the last half
Implementation of "map"
Implementation of "interface"
Funny bug: break
Tried reading the official Go compiler
Official compiler: size of slice
Official compiler: variable names for slice
Tried submitting a patch
Started writing another Go compiler
babygo: First commit
Stack machine (chibicc style)
babygo: stack machine (chibicc-like)
babygo: Handwritten syscall
babygo: Order of implementation
Conclusion

Taught by

Gopher Academy

Reviews

Start your review of How to Write a Self-Hosted Go Compiler from Scratch

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.