在 Clozure Cl 中处理图像

发布于 2024-11-15 06:00:46 字数 195 浏览 2 评论 0原文

1)在ccl中制作图像的正确方法是什么? 之间的确切区别是什么:

或者: (compile-file "foo.lisp")(progn (load "foo.lisp") (save-application "foo")) 代码>?

2)是否有可能加载多个图像(首选命令行)?

1) What is the proper method to make an image in ccl? Or what is the exact difference between:

(compile-file "foo.lisp") and (progn (load "foo.lisp") (save-application "foo"))?

2) Is there any possibility to load multiple images (command line prefered)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬シ愛 2024-11-22 06:00:46

Common Lisp 系统中的文件编译器以某种机器语言(取决于目标处理器)或某些虚拟机(例如在 CLISP 中)创建原始源的表示。然后可以使用 LOAD 函数将这个编译后的文件加载到正在运行的 Lisp 系统中,并创建源的定义(函数、类、变量……)并执行文件中的其他代码。

可以直接加载源文件(也可以使用 LOAD 函数)。如果 Lisp 使用编译器甚至加载表单,则文件编译器的优点是:

  • 加载已编译的代码应该稍快一些
  • 在编译时进行一些错误检查
  • 可能在运行时使用更快的代码进行更积极的编译 代码
  • 可能更小(取决于

)图像是独立的。该图像是正在运行的 Lisp 的内存转储。但通常不是每个状态都可以转储,具体取决于 Lisp 系统。无法转储到映像的候选内容:文件连接、网络连接、打开的窗口……因此,启动映像时可能需要重新打开这些内容。

如果要启动 Lisp 应用程序,有多种选择:

  • 在启动时加载所有源代码
  • 在启动时加载所有已编译的代码
  • 加载包含所有代码的图像

后者可能是最快的。对于许多目的来说,现在在启动时加载已编译的代码也足够快,特别是如果启动只是偶尔发生一次。

让我们再看看你的问题。

(compile-file "foo.lisp")

上面只是将单个文件编译为已编译文件(FASL 文件,“快速加载”)。编译的效果也是Lisp系统中已经记录了一些信息,但是文件的定义不可用。然后您需要加载编译后的文件。

(progn (load "foo.lisp") (save-application "foo"))

上面首先加载文件。请注意,具有增量编译器的 Lisp 可能会编译该文件中的部分或全部语句(CCL 和 SBCL 正在这样做)。 SAVE-APPLICATION 是一个 CCL 特定函数,它转储完整的 Lisp 状态(减去文件连接,...)并创建一个可以启动的应用程序。

如果您想创建像其他应用程序一样启动的 Lisp 应用程序,SAVE-APPLICATION 就是您的最佳选择。

是否可以加载多个图像取决于系统。在 CCL 中你不能。在 Lisp 机器上,我们可以加载一个基本镜像,然后加载多个增量镜像。

The file compiler in Common Lisp systems creates a representation of the original source in some kind of machine language (depending on the target processor) or for some virtual machine (for example in CLISP). This compiled file then can be loaded into a running Lisp system with the LOAD function and creates the definitions of the source (functions, classes, variables, ...) and executes other code in the file.

One can load source files directly (also using the function LOAD). If the Lisp uses a compiler even for loading forms, the advantage of the file compiler is:

  • loading compiled code should be slightly faster
  • some error checking at compile time
  • possibly more aggressive compilation with faster code at runtime
  • code may be smaller (depends)

Saving an image is independent. The image is a memory dump of a running Lisp. But generally not every state can be dumped depending on the Lisp system. Candidates of things that cannot be dumped to an image: file connections, network connections, open windows, ... So, these things may need to be reopened when an image is started.

If you want to start a Lisp application one has several options:

  • load all source code on startup
  • load all compiled code at startup
  • load an image with all code included

The latter is likely the fastest. For many purposes now loading compiled code at startup is also fast enough, especially if starting only happens once in a while.

Let's look at your question again.

(compile-file "foo.lisp")

Above just compiles a single file to a compiled file (FASL file, 'fast load'). The effect of the compilation is also that some information has been recorded in the Lisp system, but the definitions of the file are not available. You need to load the compiled file then.

(progn (load "foo.lisp") (save-application "foo"))

Above first loads the file. Note that a Lisp with an incremental compiler may compile some or all statements in that file (CCL and SBCL are doing that). SAVE-APPLICATION is a CCL specific function, which dumps the complete Lisp state (minus file connections, ...) and creates an application which then can be started.

If you want to create Lisp applications that start like other applications, SAVE-APPLICATION is the way to go.

If multiple images can be loaded is system dependent. In CCL you can't. On a Lisp Machine one could load a base image and then multiple incremental images on top of that.

音栖息无 2024-11-22 06:00:46

compile-file 正如它所说的那样:它将源文件编译为本机代码并将结果存储在另一个文件中。使用compile-file编译的文件可以使用load函数加载。编译只是一种优化,所以效果和直接加载源文件非常相似。

相比之下,核心映像存储 Lisp 环境的完整状态,包括 Lisp 堆(包含所有加载的代码和数据)以及执行状态,这就是为什么尝试加载多个将核心图像放入单个 Lisp 实例中没有任何意义。正如手册中所述,您可以保存核心映像 通过使用 (ccl:save-application "image_name") ,其中 image_name 是您要创建的图像文件的名称。核心映像只能通过启动新的 Clozure CL 实例并使用 -I 命令行选项提供映像文件来加载。

一般来说,如果您正在编写一个由多个源文件组成的软件,您通常真的不想手动编译和加载东西。相反,请考虑创建系统定义文件并使用 ASDF 加载您的软件。

compile-file does what it says it does: It compiles a source file into native code and stores the result in another file. Files compiled with compile-file can be loaded with the load function. Compilation is merely an optimization, so the effect is very similar to loading the source file directly.

In contrast, a core image stores the complete state of the Lisp environment, including the Lisp heap (with all loaded code and data) as well as the state of the execution, which is why trying to load multiple core images into a single Lisp instance doesn't make any sense. As is described in the manual, you can save a core image by using (ccl:save-application "image_name") where image_name is the name of the image file you want to create. A core image can only be loaded by starting a new Clozure CL instance and supplying the image file with the -I command-line option.

Generally, if you are writing a piece of software consisting of multiple source files, you usually really don't want to compile and load stuff manually. Instead, consider creating a system definition file and loading your software with ASDF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文