编程与软件工程pvk.ca
SBCL:终极汇编代码面包板
SBCL: The Ultimate Assembly Code Breadboard
2014 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章介绍如何把 SBCL(一个 Common Lisp 实现)当作“汇编代码面包板”来用:借助其编译器和 REPL,可以快速实验、生成和测试 x86 汇编代码片段。作者展示了 Lisp 环境在底层代码探索和运行时代码生成方面的独特能力。
为什么经久不衰:它把 Lisp 编译器当作交互式汇编实验台这一视角在十年后依然新鲜,对关心 JIT、运行时代码生成和编译器底层的人仍有启发。
HN 评论精选
Lisp 的独特优势是“编译型语言 + REPL”的组合,而非宏
人们总爱谈论宏的强大,但对我来说,Lisp 真正与众不同之处在于它是一门带 REPL 的编译型语言。还有其他可用的带 REPL 的编译型语言吗?
jgalt212查看英文原文
People love to go on and on about the power of macros, but for me, what separates Lisp from the crowd is that it's a compiled language with a REPL. Are they any other usable compiled languages with a REPL?
纠正文中关于 x87 FXCH 指令“免费”的说法,并指出相关硬件权衡已过时
唯一想指出的是,“免费”的 FXCH 并不免费。它在处理器内部有不少开销,是设计者有意支持的功能(可对比 Pentium 与 AMD K5)。硬件支持寄存器而非栈是有充分理由的;不过就当时的 x86 而言,硬件设计者承担这些代价是为了让软件受益。这些权衡如今已不再成立。
bsder查看英文原文
The only thing I would point out is that "free" FXCH isn't free. It has quite a lot of baggage inside the microprocessor and was something that designers made a conscious decision to support (see Pentium vs. AMD K5). There are good reasons why hardware supports registers instead of a stack. However, given where x86 was at the time, the hardware designers of the time took the penalties because the gains to the software folks justified it. Those choices no longer hold.
SBCL 社区响应迅速,实际项目体验很好
SBCL 是个了不起的项目。我在一些个人项目中使用它;而 SBCL 社区真正闪光的地方,是我几年前参与的一个医疗记录 AI 项目——我们遇到的几个 SBCL 问题都很快被修复了,体验很好。
mark_l_watson查看英文原文
SBCL is an amazing project. I use it for some personal projects, but where the SBCL community really shined, in my experience, was on an AI for medical records project I worked on several years ago. We had some issues with SBCL that were fixed very quickly. A nice experience.
对比现代工具 dynasm-rs 与文中 Lisp 方案,认为 Lisp 宏在易用性上仍占优
结尾提到 LuaJIT 的 DynASM 很有趣,我读到那里才注意到标题里的 (2014)。作者当时称其为进行中的工作。我最近在项目里用 dynasm-rs 做动态汇编器,体验也很好。我认为 Lisp 在易用性上可能仍占优势,因为可以对汇编 DSL 做各种宏操作;但如果你只想做运行时代码生成,dynasm-rs 也很棒。
chc4查看英文原文
It namedropping LuaJIT's Dynasm at the end was funny, especially since by the time I got to it I had forgotten there was a (2014) in the title. Pleasant surprise seeing the author call it a work-in-progress :) I recently tried using the dynasm-rs crate as a dynamic assembler for a project, and it's also really nice to use. I think something like Lisp still probably wins in terms of usability, since you can do the fancy macro abuse over your assembly DSL, but dynasm-rs was great if you just want runtime code generation without parameterize over stack offsets or something else insane like the OP.
历次讨论
同类还值得读
开源应用架构
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编辑精选