Writing A Compiler In Go
暫譯: 用 Go 語言編寫編譯器

Thorsten Ball

  • 出版商: Thorsten Ball
  • 出版日期: 2018-08-10
  • 售價: $1,800
  • 貴賓價: 9.9$1,782
  • 語言: 英文
  • 頁數: 353
  • 裝訂: Paperback
  • ISBN: 398201610X
  • ISBN-13: 9783982016108
  • 相關分類: Go 程式語言Compiler
  • 相關翻譯: 用 Go語言自製編譯器 (簡中版)
  • 立即出貨(限量) (庫存=1)

買這商品的人也買了...

相關主題

商品描述

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 編譯器和虛擬機器!我們將並行構建它們,以便始終擁有一個可以穩定演變的運行系統。我們最終得到的,不僅更接近我們每天使用的程式語言,讓我們更好地理解它們的運作方式,還快了三倍。而這是在沒有明確追求性能的情況下實現的。

以下是我們將要做的事情:

- 我們定義自己的位元組碼指令,指定其操作數和編碼。在此過程中,我們還為它們構建一個迷你反組譯器。
- 我們撰寫一個編譯器,接受 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 是一位專業的軟體開發者和作家。

他的寫作源於他對所謂的「休閒程式設計」的熱愛,在這個過程中,他深入探討各種主題,希望能更好地理解我們在程式設計時所做的事情。在過去幾年中,最吸引他注意的兩個主題是系統程式設計和程式語言。

他也對專業軟體開發的另一面感興趣:團隊中的軟體工程、透過程式碼進行溝通、團隊和公司文化,以及如何共同撰寫優秀的程式碼。

對程式設計及其意義的著迷,促使他撰寫了兩本書以及各種部落格文章、播客出現和演講。