编程与软件工程stephendiehl.com编辑精选
用 Haskell 与 LLVM 实现一门 JIT 编译语言
Implementing a JIT Compiled Language with Haskell and LLVM
2014 — 2015,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Stephen Diehl 撰写的教程,讲解如何用 Haskell 和 LLVM 实现一门带 JIT 编译的语言(移植 LLVM 官方 Kaleidoscope 教程)。文章覆盖解析、AST、代码生成到 JIT 执行的完整流程,是学习编译器与 LLVM 的经典入门材料。
为什么经久不衰:它把 LLVM 官方 C++ 教程移植到 Haskell,代码简洁易读,多年来一直是初学者上手编译器和 LLVM 的首选参考。
HN 评论精选
推荐文中所用的 llvm-general 库,认为它是最好的 LLVM 高层接口。
llvm-general 是个很棒的库,可以说是目前世界上最好的 LLVM 高层 API。非常感谢 Stephen Diehl 花时间把 Kaleidoscope 教程移植到 llvm-general。
carterschonwald查看英文原文
llvm-general is a great library, it is seriously the best high level api for LLVM usage currently on the planet. I'm very very grateful that Stephen Diehl took the time to port the Kaleidoscope tutorial to LLVM-General
对比 Java 实现,认为 Haskell 更适合写编译器。
我曾用 Java 按 LLVM 官网教程实现过这个玩具编译器(去掉 JIT 部分)。看了这份 Haskell 代码后,我惊讶地发现静态类型函数式语言比 Java 这类命令式语言更适合写编译器:代码更简洁,更重要的是可读性更好。
jpetitto查看英文原文
I've implemented this toy compiler (minus JIT) in Java, following the tutorial on the LLVM website (which uses C). After browsing through the Haskell code, it is incredible how much more suitable a statically-typed, functional language is for compiler development when compared to an imperative language like Java. The code is much more terse and most importantly, readable.
文章对初学者帮助很大,但缺少异常、GC、闭包等进阶主题。
上学期的编译器课程要求实现 Go 子集的编译器,我选了 Haskell + LLVM,这篇文章在写代码生成时帮了大忙,因为那是我第一个真正的 Haskell 项目。不过它省略了一些有趣且重要的话题,比如异常、线程、导入、垃圾回收、闭包等,希望有讨论更现代特性的进阶版本。
the_french查看英文原文
Last semester for a compiler course I was taking we had to implement a compiler for a subset of Go (called GoLite), with free reign over language choices. I chose to implement a compiler[0] using Haskell and LLVM, this article helped a _lot_ when I was writing codegen, especially since it was my first real Haskell project. However, some of the most interesting and important issues are left out of it. Some examples are implementing exceptions, threading, imports, garbage collection, closures , etc.. I would love a more advanced version of this article that discusses how to implement a more advanced compiler with more modern features (specifically in LLVM). [0] github.com/xldenis/mgc
顺带推荐作者另一篇 Haskell 学习指南。
这对很多人来说是常识,但作者的《What I Wish I Knew When Learning Haskell》一文也非常棒。
jdreaver查看英文原文
This is common knowledge for a lot of people, but I have found the author's "What I Wish I Knew When Learning Haskell" article is awesome too: http://dev.stephendiehl.com/hask/
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选