iovxw

将 Chez Scheme 程序编译为单文件

但是仍然依赖解释器

通过使用 make-boot-file 可以将 Chez Scheme 程序编译为单文件

文档如下:

procedure: (make-boot-file output-filename base-boot-list input-filename ...)
returns: unspecified
libraries: (chezscheme)

output-filename, input-filename, and the elements of base-boot-list must be strings.

make-boot-file writes a boot header to the file named by output-filename, followed by the object code for each input-filename in turn. If an input file is not already compiled, make-boot-file compiles the file as it proceeds.

The boot header identifies the elements of base-boot-list as alternative boot files upon which the new boot file depends. If the list of strings naming base boot files is empty, the first named input file should be a base boot file, i.e., petite.boot or some boot file derived from petite.boot.

Boot files are loaded explicitly via the --boot or -b command-line options or implicitly based on the name of the executable (Section 2.9).

See Section 2.8 for more information on boot files and the use of make-boot-file.


例子:

;; lib/b.ss
(library (lib b)
  (export y)
  (import (rnrs))
  (define y "Hello!\n"))
;; lib/a.ss
(library (lib a)
  (export x)
  (import (rnrs)
          (lib b))
  (define x y))
;; main.ss
(import (rnrs)
        (lib a))

(display x)

编译:

echo $'(make-boot-file "main.boot" \'("scheme" "petite") "lib/b.ss" "lib/a.ss" "main.ss")' | scheme -q

需要注意的是,input-filename 的顺序要和 import 的顺序一样,不然会无法找到

然后是关于 base-boot-list

In most cases, you can construct your application so it does not depend upon features of Chez Scheme (specifically, the compiler) by specifying only "petite" in the call to make-boot-file. If your application calls eval, however, and you wish to allow users to be able to take advantage of the faster execution speed of compiled code, then specifying both "scheme" and "petite" is appropriate.

运行:

$ scheme --program main.boot
Hello!

但是这样编译以后仍然依赖 Chez Scheme, 或者是 Petite Chez Scheme

具体依赖要看你 base-boot-list 是怎么写的了