AIFeed

Rune:面向 Emacs 的 Rust 虚拟机

Translation(model translation, not the source's own text)

仓库文件导航

题图
题图

Rune

R ust UN der E macs 视频介绍

本项目是一个用 Rust 编写的实验性 Emacs 核心。项目仍处于非常早期的阶段,但有以下目标:

  • 为 Emacs 带来多线程 elisp
  • 与现有 Emacs Lisp 包“bug 兼容”(一切仍应正常工作)
  • 借助 Rust 生态实现性能提升(包括更快的 GC、正则和 JSON)。

更多细节请参阅设计文档。

状态

本项目当前的目标是创建一个编辑器 MVP。我们已有基本的 elisp 运行时,正在为一个最小 GUI 添加基本编辑功能。这将包括:

  • 文本插入/删除
  • 自动换行
  • 显示表格

如果你想贡献或对要添加的功能有想法,请开一个 issue。

lisp

Lisp 文件目前拉取自

https://github.com/emacs-mirror/emacs/tree/emacs-29.1/lisp

任何为引导而做的修改都带有 RUNE-BOOTSTRAP 标签。

运行

MIRI

使用 MIRI 运行测试套件


        MIRIFLAGS='-Zmiri-strict-provenance' cargo +nightly miri test
      

探索本仓库

本项目由一个主包 rune 定义,它依赖于 crates 目录中包含的各个 crate。其中之一是 rune-macros crate,它定义了用于定义内置函数的 defun proc macro。其余代码位于 src/ 中。各模块描述如下。

贡献

有关 Rust Emacs 内部结构的更多信息,请参阅架构文档。

本项目通过尝试加载新的 elisp 文件并观察哪里出错来推进。最好的方式是使用 cargo run,它会加载当前已引导的文件。已引导的文件位于 main.rs 中,作为 load 函数的一部分。

通常需要做的是实现更多原始函数。这通过 defun 宏完成。例如,如果我们想实现 substring 函数,我们会先查看 lisp 签名。


        (substring STRING &optional FROM TO)
      

然后我们会把类型转换为对应的 Rust 类型。如果不知道正确的类型,我们可以使用 Object。在这个例子中,我们会这样编写 Rust 签名:


        #[defun]
fn substring(string: &str, from: Option<i64>, to: Option<i64>) -> String {...}
      

要加载新的 elisp 文件,运行 cargo run --release -- --load <file>。尚未引导的文件还未包含在本仓库中,但属于 Emacs 的一部分。一旦文件被引导,就可以添加到 lisp 目录中。

属性测试

Rune 包含 assert_elprop! 宏,它支持针对 GNU Emacs 进行属性测试。该宏的工作原理是将同一个 Lisp 形式同时发送给 Rune 和 Emacs,然后比较它们的结果。它也可以与 proptest crate 结合使用。

示例:


        #[test]
fn test_addition() {
    // Verify that (+ 40 2) evaluates to 42 for both Rune and Emacs
    assert_elprop!["(+ 40 2)"];
}

// Verify that make-vector works for any arbitrary byte
proptest! {
    #[test]
    fn test_make_vector_consistency(size in arb_byte()) {
        assert_elprop!["(make-vector {} ?A)", size];
    }
}
      

如何在 Linux 上用 Wine 运行 Windows 测试

  • 定义 WINEPREFIX:export WINEPREFIX=$PWD/.wine
  • 将 x86_64-pc-windows-gnu 添加到 rust 工具链:rustup target add x86_64-pc-windows-gnu
  • 设置 wineprefix:./scripts/setup-wineprefix。该脚本还会在前缀内安装 Emacs

现在你可以这样在 Windows 上运行测试:cargo test --target x86_64-pc-windows-gnu。如果你使用 Nix 环境,应跳过第 1 和第 2 点。

此外,你可以让 eglot 检查标记为 #[cfg(windows)] 的代码。只需将以下内容添加到 .dir-locals.el 并重启 eglot:


        ((nil
       . ((eglot-workspace-configuration
           . (:rust-analyzer (:cargo (:target "x86_64-pc-windows-gnu")))))))
      

博客文章

  • 多线程 Emacs 的构想 :: 关于如何为现有语言添加多线程的一些想法。

进一步探索

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗