23

(大卫詹姆斯都写了问题和答案。我将对其进行编辑以符合 Stackoverflow 标准。)

使用 SBCL,您可以将 Lisp 代码编译为机器代码。

像 Java、.net、C++ 甚至 C 一样,您将需要运行时。所以有两种方法可以编译 Common Lisp 代码。

首先是制作巨大的二进制文件,SBCL 文档中对此进行了解释。目标机器上不需要 SBCL。

另一种方式是更灵活的方式,即以 fasl(FASt Load)格式创建机器码。目标机器上需要 SBCL 运行时。

第二种方式在类 Unix 操作系统下如何工作?

4

2 回答 2

27

(大卫詹姆斯的回答:)

我们将在我们的系统中创建两个命令:一个用于批量编译 Lisp 代码,另一个用于轻松运行 Lisp 代码:

使用您喜欢的编辑器,打开一个名为sbcl.compile. 内容应该是:

    #!/bin/bash
    sbcl --noinform --eval "(compile-file \"$1\")" --eval "(quit)" > /dev/null

现在编译 Lisp 文件使用:

    # sbcl.compile hello.lisp

这将创建一个hello.fasl文件。

现在为了轻松运行这些文件,我们创建了一个新命令。使用您喜欢的编辑器打开一个名为sbcl.run. 内容应该是:

    #!/bin/bash
    sbcl --noinform --load "$1" --quit --end-toplevel-options "$@"

现在您可以调用sbcl.run hello.fasl来运行本机代码。

    # sbcl.run hello.fasl

SBCL 手册中描述了详细信息:启动 SBCL

于 2012-01-29T19:22:31.410 回答
4

Another option is to add to the runtime all packages/functions/frameworks that you commonly use, and then save this state as a new core file, and use this as your default core while continuing development. I usually find fasls more trouble than they are worth, especially since lisp has the ability to save state in a VM-style core file. I just incrementally update the core as development moves along. And rebuild/update the core using GNU Make.

于 2012-01-30T03:57:59.553 回答