编程与软件工程dev.stephendiehl.com
用 LLVM 为 Python 写一个特化器
Let's Write an LLVM Specializer for Python
2015 — 2019,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
Stephen Diehl 的这篇教程手把手演示如何为 Python 写一个「特化器」:解析 Python 源码、做类型推导,再把数组运算表达式编译成 LLVM IR 并即时执行,本质上是一个面向 NumPy 风格数值计算的小型 JIT。作者是在接触 Numba 项目期间学习 LLVM 与 llvmpy 的产物,文中还给出了进一步扩展的方向。
为什么经久不衰:它把「Python AST → 类型标注 → LLVM IR → 可执行代码」这条 JIT 主线讲得完整而具体,是理解 Numba 一类工具原理的经典入门材料,即使 llvmpy 已被 llvmlite 取代,思路仍不过时。
HN 评论精选
Numba 核心开发者确认这是第一代 Numba 相关的教学成果,并借此招揽贡献者。
这是一篇关于第一代 Numba 的优秀教程。作者在和我们几位开发者共事的过程中,对 LLVM 和 llvmpy 学到了很多。如果你对他文中「后续工作」部分感兴趣,欢迎加入 Numba 项目。
travisoliphant查看英文原文
This is a great tutorial about first-generation Numba. The author learned a lot about LLVM and llvmpy while working with several of our devs. If you are interested in the "Further work" in his article, come join the Numba project.
读者分享自己用 Python AST 做代码生成的实践,认为本文可作为转向 LLVM 的起点。
有意思。我目前用 Python 的 AST 把某些嵌套逻辑查询表达式(语法是我应用独有的)转成由专用 VM 执行的字节码——最初试过 V8 和 LuaJIT,但性能不理想,这个项目替换掉了一些旧的 Boost::Python C++ 代码。这篇文章应该能让人更容易上手尝试用 LLVM 替代。
Erwin查看英文原文
Interesting. I currently use Python's AST to convert some nested logical query expression (in a syntax unique to my application) into bytecode executed by a specialized VM (I originally tried using V8 and LuaJit for this but performance wise that was unsuccessful; the project replaced some old Boost::Python C++ code). This article should make it easy to get started attempting an LLVM replacement.
赞其详尽扎实、不是浮于表面的演示。
我很欣赏这篇博文的篇幅和细节。它是真正全面的,而不只是炫技。
jonstewart查看英文原文
I really appreciate the length and detail in this blog post. It's comprehensive, not just showing off.
提醒 llvmpy 已废弃,实践时应改用 llvmlite 并附上替代文档。
正如其他人所说,这篇文章有点过时了。llvmpy 的 GitHub 页面已建议改用 llvmlite。另可参考 llvmlite 用户指南,特别是 IR 示例和绑定示例两页。
gjvc查看英文原文
As others have noted, this is a somewhat dated article. Indeed, the github page for llvmpy (https://github.com/llvmpy/llvmpy) recommends to use llvmlite (https://github.com/numba/llvmlite) instead. See also http://llvmlite.pydata.org/en/latest/user-guide/index.html and in the context of the original article, in particular these two pages: http://llvmlite.pydata.org/en/latest/user-guide/ir/examples.html http://llvmlite.pydata.org/en/latest/user-guide/binding/examples.html Hope this helps! :-)
历次讨论
同类还值得读
开源应用架构
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编辑精选