Kindle Price: | $20.00 |
Sold by: | Amazon.com Services LLC |
Your Memberships & Subscriptions
![Kindle app logo image](https://cdn.statically.io/img/m.media-amazon.com/images/G/01/kindle/app/kindle-app-logo._CB668847749_.png)
Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required.
Read instantly on your browser with Kindle for Web.
Using your mobile phone camera - scan the code below and download the Kindle app.
Writing A Compiler In Go Kindle Edition
Runnable and tested code front and center, built from the ground up, step by step — just like before.
But this time, we're going to define bytecode, compile Monkey and execute it in our very own virtual machine. It's the next step in Monkey's evolution.
It's the sequel to … a programming language
Writing A Compiler In Go is the sequel to Writing An Interpreter In Go. It starts right where the first one stopped, with a fully-working, fully-tested Monkey interpreter in hand, connecting both books seamlessly, ready to build a compiler and a virtual machine for Monkey.
In this book, we use the codebase (included in the book!) from the first part and extend it. We take the lexer, the parser, the AST, the REPL and the object system and use them to build a new, faster implementation of Monkey, right next to the tree-walking evaluator we built in the first book.
The approach is unchanged, too. Working, tested code is the focus, we build everything from scratch, do baby steps, write tests firsts, use no 3rd-party-libraries and see and understand how all the pieces fit together.
It's a continuation in prose and in code.
Do you need to read the first part before this one? If you're okay with treating the code from the first book as black box, then no. But that's not what these books are about; they're about opening up black boxes, looking inside and shining a light. You'll have the best understanding of where we're going in this book, if you know where we started.
Learn how to write a compiler and a virtual machine
Our main goal in in this book is to evolve Monkey. We change its architecture and turn it into a bytecode compiler and virtual machine.
We'll take the lexer, the parser, the AST and the object system we wrote in the first book and use them to build our own Monkey compiler and virtual machine … from scratch! We'll build them side-by-side so that we'll always have a running system we can steadily evolve.
What we end up with is not only much closer to the programming languages we use every day, giving us a better understanding of how they work, but also 3x faster. And that's without explicitly aiming for performance.
Here's what we'll do:
- We define our own bytecode instructions, specifying their operands and their encoding. Along the way, we also build a mini-disassembler for them.
- We write a compiler that takes in a Monkey AST and turns it into bytecode by emitting instructions
- At the same time we build a stack-based virtual machine that executes the bytecode in its main loop
We'll learn a lot about computers, how they work, what machine code and opcodes are, what the stack is and how to work with stack pointers and frame pointers, what it means to define a calling convention, and much more.
We also
- build a symbol table and a constant pool
- do stack arithmetic
- generate jump instructions
- build frames into our VM to execute functions with local bindings and arguments!
- add built-in functions to the VM
- get real closures working in the virtual machine and learn why closure-compilation is so tricky
- LanguageEnglish
- Publication dateJuly 29, 2018
- File size3275 KB
Customers who read this book also read
Product details
- ASIN : B07FZWWVQT
- Publication date : July 29, 2018
- Language : English
- File size : 3275 KB
- Simultaneous device usage : Unlimited
- Text-to-Speech : Enabled
- Screen Reader : Supported
- Enhanced typesetting : Enabled
- X-Ray : Not Enabled
- Word Wise : Not Enabled
- Sticky notes : On Kindle Scribe
- Print length : 354 pages
- Best Sellers Rank: #211,913 in Kindle Store (See Top 100 in Kindle Store)
- #168 in Programing Languages & Tools
- #232 in Microsoft Programming (Books)
- #586 in Programming Languages (Books)
- Customer Reviews:
About the author
![Thorsten Ball](https://cdn.statically.io/img/m.media-amazon.com/images/S/amzn-author-media-prod/hlno83llg16qcef45j4h4e6chh._SY600_.jpg)
Thorsten Ball is a professional software developer and writer.
His writing is a result of his love for what he calls "recreational programming", where he digs deep into various topics, hoping to come out the other end with a better understanding of what it is that we do when we program. For the last few years, the two topics that kept his attention the most are systems programming and programming languages.
He's also interested in the other side of doing professional software development: software engineering in a team, communicating through code, team and company culture and how to write great code together.
This fascination with programming and what it means to develop software, turned into his two books and various blog posts, podcast appearances and talks.
Customer reviews
Customer Reviews, including Product Star Ratings help customers to learn more about the product and decide whether it is the right product for them.
To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.
Learn more how customers reviews work on AmazonReviews with images
![Great coverage of the fundamentals of bytecode generation and execution](https://cdn.statically.io/img/images-na.ssl-images-amazon.com/images/G/01/x-locale/common/transparent-pixel._V192234675_.gif)
-
Top reviews
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
My only problem is with the Kindle edition, as that it appears to have lost some stack diagrams that were supposed to further illustrate the material discussed. I'm attaching a screenshot from the online reader where there's clearly a picture missing from the page. There are a few of such places - not many, maybe 3-4 or so.
![Customer image](https://cdn.statically.io/img/images-na.ssl-images-amazon.com/images/G/01/x-locale/common/transparent-pixel._V192234675_.gif)
Reviewed in the United States on September 29, 2020
My only problem is with the Kindle edition, as that it appears to have lost some stack diagrams that were supposed to further illustrate the material discussed. I'm attaching a screenshot from the online reader where there's clearly a picture missing from the page. There are a few of such places - not many, maybe 3-4 or so.
![Customer image](https://cdn.statically.io/img/images-na.ssl-images-amazon.com/images/I/71KbZ3E+lrL._SY88.jpg)
The compiler book went much faster because the basics are the same as the interpreter book. Instead of tree-walk to eval, the compiler emits instructions for the vm to execute. Since early in my career I was an assembly language programmer. The vm's stack architecture is quite natural to me so the vm portion, though new, was easy for me to follow as well.
Both books are wonderfully written. Code in both book work as advertised. I enjoyed reading and following the code immensely.
Ever since I left school I wanted to someday write a compiler. I did it! :-) . I am thinking about re-implementing the programs in Python. That should be quite fun, I would think.
It's super easy to read and not weighed down by theory. It's like the practical, up-to-date version of the Dragon book. If I was trapped on an island and forced to build a programming language (hint hint!), this is the only book I would take.
What’s very unique about both books is that they make complex, intimidating problems approachable. Better still, they’re not doing that by pretending it’s a simple topic or by denying or hiding its complexity.
Rather than a steep learning curve, the author makes it feel like a walk in the park by slicing it in tiny (digestible) chunks and presenting them in the order that makes the most logical sense. At the end, you will gain the same knowledge as the one you would have gained from more demanding books except that it will be a far more enjoyable experience.
So whether you are an experienced programmer or just curious about those things, you will be a better programmer (and possibly writer/teacher) after reading the book.
I would be as bold as to say that even if you don’t really know/appreciate Go (which would be a shame) you could learn a lot even if you were to end-up implementing the code in the language of your choice.
I’m very much looking forward to volumes 3 and 4 : “Writing a micro-processor in VHDL” and “Writing an operating system in Monkey”.
Top reviews from other countries
![](https://images-eu.ssl-images-amazon.com/images/S/amazon-avatars-global/default._CR0,0,1024,1024_SX48_.png)
1. You are already a programmer
2. You code along in Go (no previous Go knowledge needed)
3. You have some interest in compilers
It is very hands on, and you need to work from beginning to end of the book, which is not how technical books on computers usually work. I found it rewarding getting feedback when the code I had copied actually worked as I went along.
It is not a comprehensive book about all the various ways a compiler can be written.
![](https://images-eu.ssl-images-amazon.com/images/S/amazon-avatars-global/default._CR0,0,1024,1024_SX48_.png)
![](https://images-na.ssl-images-amazon.com/images/S/amazon-avatars-global/default._CR0,0,1024,1024_SX48_.png)
Comme pour le premier opus, le cheminement est extrêmement progressif (sans pour autant prendre de raccourcis) et le style très agréable.
A la fin du livre vous aurez réellement écris 100% d’un compilateur (byte code et machine virtuelle) sans utiliser aucun outil externe et aucune librairie autre qu’une toute petite portion de la librairie standard Go.
Même si vous ne pratiquez pas ou n’aimez pas Go (ce qui serait vraiment dommage), vous pouvez faire abstraction du langage utilisé, ce livre reste un des rares ouvrages accessible sur le sujet et rien ne vous empêche de porter le code dans votre langage préféré (quelqu’un la fait pour Rust sur le premier volume).
J’ai vraiment hâte de découvrir ce que sera son prochain livre. Suggestions (improbables) : « Writing a micro-processor in VHDL » ?!? « Writing an operating system in Monkey » ?!?