Writing A Compiler In Go


Writing An Interpreter In Go
By 作者:Thorsten Ball
pages 页数: 352 pages
Publisher Finelybook 出版社: Thorsten Ball (August 10, 2018)
Language 语言: English
ISBN-10 书号:398201610X
ISBN-13 书号:9783982016108
Book Description to Finelybook sorting
This is the sequel to Writing An Interpreter In Go. We’re picking up right where we left off and write a compiler and a virtual machine for Monkey.
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 By 作者:tecode, 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 By 作者:tecode 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 By 作者:tecode 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 By 作者:tecode By 作者:emitting instructions
At the same time we build a stack-based virtual machine that executes the By 作者:tecode 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


下载地址

Writing A Compiler In Go 9783982016108.zip

赞(0) 捐助
未经允许不得转载:finelybook » Writing A Compiler In Go
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏