Building a Virtual Machine for Programming Language

所在平台: Udemy

课程主页: https://www.udemy.com/course/virtual-machine/

课程评论:没有评论

第一个写评论        关注课程

课程简介

课程名称:构建编程语言的虚拟机 课程概述: 在本课程中,我们将探讨编程语言的底层工作原理,包括编译器与解释器的区别、虚拟机和JIT编译器的概念,以及函数式编程与命令式编程的差异。现有的“编译器课程”往往被视为“复杂的火箭科学”,仅适合高级工程师,而传统编译器教材从最基础的词法分析开始,逐步深入理论,导致学生在实现第一个词法分析器模块时失去兴趣。通过本课程,我们旨在在4到6小时内理解和构建完整的编程语言语义,内容直接切入要点,通过双人编程的实时编码示范,生动易懂。 在《构建虚拟机》课程中,我们专注于运行时语义,构建类似于JavaScript或Python的基于栈的虚拟机。通过深入字节码级别,您将理解现代生产虚拟机中的底层解释如何工作。同时,实现一门编程语言将提升您在其他编程语言中的实践能力。 课程先决条件: 本课程需要预先参加《从零开始构建解释器》课程,学习如何从AST级别构建完整的编程语言。此外,由于我们将深入低级(字节码)层级,因此需要具备基本的C++经验,但课程内容不以C++为主,主要使用基本构造,这些构造可以转移到其他语言。 适合人群: 本课程适合任何好奇的工程师,尤其是对构建复杂系统感兴趣的人。如果您尤其对编译器、字节码解释器、虚拟机和源代码转换感兴趣,您同样会发现本课程有价值。 实现工具: 低级虚拟机通常使用C或C++等低级语言实现,我们同样运用基本的C++功能,以确保代码容易转换到其他语言,如Rust或JavaScript。我们鼓励学生主动实现虚拟机的每一个细节,而不是仅仅复制最终解决方案,项目代码库中包含需要解决的“/* Implement here */”作业。 课程特色: 1. 简洁明了:每节课内容直接相关,不偏离主题。 2. 动画演示结合实时编辑笔记:有助于理解主题。 3. 端到端实时编码环节与作业:完整源代码从头到尾在视频讲座中展示。 课程结构: 课程分为五个部分,共29节课,涵盖多个小主题。 第一部分:虚拟机基本操作 描述编译与解释管道,开始构建语言,讨论栈和寄存器虚拟机、堆分配对象以及字节码的编译。 第二部分:控制流与变量 实现控制流结构,如if表达式和while循环,讨论全局对象及变量、嵌套块和局部变量,并实现反汇编器。 第三部分.1:函数与调用栈 实现函数抽象与调用,描述调用栈、原生和用户定义函数以及即时调用的lambda表达式(IILEs)。 第三部分.2:闭包实现 重点讲解闭包的实现,讨论作用域分析、捕获自由变量及为闭包添加运行时支持。 第四部分:垃圾收集 致力于自动内存管理的垃圾收集,讨论跟踪堆并实现标记-清扫垃圾收集器。 第五部分:面向对象编程 最后一部分支持面向对象编程,构建类和实例,并完成最终虚拟机的可执行文件。

课程评论(0条)

课程详情

Course overviewHow programming languages work under the hood? What's the difference between compiler and interpreter? What is a virtual machine, and JIT-compiler? And what about the difference between functional and imperative programming?There are so many questions when it comes to implementing a programming language!The problem with "compiler classes" in school is such classes are usually presented as some "hardcore rocket science" which is only for advanced engineers.Moreover, classic compiler books start from the least significant topic, such as Lexical analysis, going straight down to the theoretical aspects of formal grammars. And by the time of implementing the first Tokenizer module, students simply lose an interest to the topic, not having a chance to actually start implementing a programing language itself. And all this is spread to a whole semester of messing with tokenizers and BNF grammars, without understanding an actual semantics of programming languages.I believe we should be able to build and understand a full programming language semantics, end-to-end, in 4-6 hours - with a content going straight to the point, showed in live coding sessions as pair-programming and described in a comprehensible way.In the Building a Virtual Machine class we focus specifically on runtime semantics, and build a stack-based VM for a programming language very similar to JavaScript or Python. Working closely with the bytecode level you will understand how lower-level interpretation works in production VMs today.Implementing a programing language would also make your practical level in other programming languages more professional.PrerequisitesThere are two prerequisites for this class.The Building a Virtual Machine course is a natural extension for the previous class - Building an Interpreter from scratch (aka Essentials of Interpretation), where we build also a full programming language, but at a higher, AST-level. Unless you already have understanding of how programming languages work at this level, i.e. what eval, a closure, a scope chain, environments, and other constructs are - you have to take the interpreters class as a prerequisite.Also, going to lower (bytecode) level where production VMs live, we need to have basic C++ experience. This class however is not about C++, so we use just very basic (and transferrable) to other languages constructs.Watch the introduction video for the details.Who this class is for?This class is for any curious engineer, who would like to gain skills of building complex systems (and building a programming language is an advanced engineering task!), and obtain a transferable knowledge for building such systems.If you are interested specifically in compilers, bytecode interpreters, virtual machines, and source code transformation, then this class is also for you.What is used for implementation?Since lower-level VMs are about performance, they are usually implemented in a low-level language such as C or C++. This is exactly what we use as well, however mainly basic features from C++, not distracting to C++ specifics. The code should be easily convertible and portable to any other language, e.g. to Rust or even higher-level languages such as JavaScript - leveraging typed arrays to mimic memory concept. Using C++ also makes it easier implementing further JIT-compiler.Note: we want our students to actually follow, understand and implement every detail of the VM themselves, instead of just copy-pasting from final solution. Even though the full source code for the language is presented in the video lectures, the code repository for the project contains /* Implement here */ assignments, which students have to solve.What's specific in this class?The main features of these lectures are:Concise and straight to the point. Each lecture is self-sufficient, concise, and describes information directly related to the topic, not distracting on unrelated materials or talks.Animated presentation combined with live-editing notes. This makes understanding of the topics easier, and shows how the object structures are connected. Static slides simply don't work for a complex content.Live coding session end-to-end with assignments. The full source code, starting from scratch, and up to the very end is presented in the video lecturesWhat is in the course?The course is divided into five parts, in total of 29 lectures, and many sub-topics in each lecture. Below is the table of contents and curriculum.PART 1: VM BASIC OPERATIONSIn this part we describe compilation and interpretation pipeline, starting building our language. Topics of Stack and Register VMs, heap-allocated objects and compilation of the bytecode are discussed.PART 2: CONTROL FLOW AND VARIABLESIn this part we implement control flow structures such as if expressions and while loops, talk about Global object and global variables, nested blocks and local variables, and also implement a disassembler.PART 3.1: FUNCTIONS AND CALL STACKIn this part we start talking and implementing function abstraction and function calls. We describe concept of the Call stack, native and user-defined functions, and IILEs (Immediately-invoked lambda expressions).PART 3.2: CLOSURES IMPLEMENTATIONIn this part we focus on closures implementation, talking about scope and escape analysis, capturing free variables, and adding runtime support for closures.PART 4: GARBAGE COLLECTIONThis part is devoted to the automatic memory management known as Garbage collection. We discuss a tracing heap and implement Mark-Sweep garbage collector.PART 5: OBJECT-ORIENTED PROGRAMMINGIn the final part we add support for Object-oriented programming, implementing classes and instances. In addition we build the final VM executable.

课程标签

0人关注该课程

主题相关的课程