Writing A Compiler In Go
Thorsten Ball
- 出版商: Thorsten Ball
- 出版日期: 2018-08-10
- 售價: $1,800
- 貴賓價: 9.8 折 $1,764
- 語言: 英文
- 頁數: 353
- 裝訂: Paperback
- ISBN: 398201610X
- ISBN-13: 9783982016108
-
相關分類:
Go 程式語言、Compiler
-
相關翻譯:
用 Go語言自製編譯器 (簡中版)
立即出貨(限量) (庫存=1)
買這商品的人也買了...
-
$1,800$1,764 -
$1,176Julia 1.0 Programming - Second Edition: Quick start to your Data Science projects
-
$2,200$2,090 -
$1,390$1,362 -
$560$442 -
$1,840Terraform: Up and Running: Writing Infrastructure as Code, 3/e (Paperback)
相關主題
商品描述
Writing A Compiler In Go - Version 1.2 - Find out more at https://compilerbook.com
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 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
商品描述(中文翻譯)
在Go語言中編寫編譯器 - 版本1.2 - 更多資訊請參閱https://compilerbook.com
這是《在Go語言中編寫解釋器》的續集。我們將從上次停下的地方繼續,為Monkey編寫一個編譯器和虛擬機。
可運行且經過測試的代碼是重點,從頭開始逐步構建 - 就像之前一樣。但這一次,我們將定義字節碼,編譯Monkey並在我們自己的虛擬機中執行它。這是Monkey演進的下一步。這是……一個編程語言的續集。
《在Go語言中編寫編譯器》是《在Go語言中編寫解釋器》的續集。它從第一本書停下的地方開始,手上有一個完全工作且經過全面測試的Monkey解釋器,無縫地連接兩本書,準備為Monkey構建一個編譯器和虛擬機。在本書中,我們使用第一部分的代碼庫(包含在書中!)並對其進行擴展。我們使用詞法分析器、解析器、AST、REPL和對象系統來構建Monkey的新的、更快的實現,與我們在第一本書中構建的遍歷樹求值器並列。
方法也沒有改變。工作、經過測試的代碼是重點,我們從頭開始構建一切,逐步進行,先寫測試,不使用第三方庫,並了解所有組件如何配合。這是散文和代碼的延續。在閱讀本書之前,您需要閱讀第一部分嗎?如果您可以將第一本書中的代碼視為黑盒,那麼不需要。但這不是這些書的目的;它們的目的是打開黑盒,看看裡面並照亮它。如果您知道我們從哪裡開始,您對本書的目標會有最好的理解。
學習如何編寫編譯器和虛擬機
本書的主要目標是發展Monkey。我們改變了它的架構,將其轉變為字節碼編譯器和虛擬機。我們將使用我們在第一本書中編寫的詞法分析器、解析器、AST和對象系統來構建我們自己的Monkey編譯器和虛擬機……從頭開始!我們將並行構建它們,以便我們始終擁有一個可以穩定發展的運行系統。最終,我們得到的不僅更接近我們每天使用的編程語言,更能更好地理解它們的工作原理,而且速度提高了3倍,而且這還不是明確追求性能的結果。
以下是我們將要做的事情:
- 我們定義自己的字節碼指令,指定它們的操作數和編碼方式。在此過程中,我們還為它們構建了一個迷你反組譯器。
- 我們編寫一個編譯器,它接收Monkey AST並通過發出指令將其轉換為字節碼。
- 同時,我們構建一個基於堆棧的虛擬機,在其主循環中執行字節碼。
我們將學到很多關於計算機的知識,了解它們的工作原理,機器碼和操作碼是什麼,堆棧是什麼,以及如何使用堆棧指針和幀指針,定義調用約定的含義,等等。
我們還會:
- 構建符號表和常量池
- 做堆棧算術
- 生成跳轉指令
- 在我們的虛擬機中構建幀,以執行具有本地綁定和參數的函數!
- 在虛擬機中添加內置函數
- 讓真正的閉包在虛擬機中工作,並了解為什麼閉包編譯如此棘手。
作者簡介
Thorsten Ball
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.
作者簡介(中文翻譯)
Thorsten Ball
Thorsten Ball是一位專業的軟體開發者和作家。
他的寫作是他對所謂的「娛樂性編程」的熱愛的結果,他深入研究各種主題,希望能夠更好地理解我們在編程時所做的事情。在過去幾年中,他最關注的兩個主題是系統編程和編程語言。
他還對從事專業軟體開發的另一面感興趣:團隊中的軟體工程、通過代碼進行溝通、團隊和公司文化以及如何一起編寫優秀的代碼。
對編程和開發軟體的意義的著迷,讓他寫了兩本書,並發表了各種博客文章、播客節目和演講。