trivial-dump-core

trivial-dump-core is a small, MIT-licensed, wrapper that provides a common interface between lisp implementations for the creation of lisp cores and executables.

It exports two functions: dump-image and save-executable.

Installation

First install quicklisp.

Then type:

* (ql:quickload 'trivial-dump-core)

dump-image usage

In this example, we'll create a CCL image that has a user defined function evaluated.

rolando@rolando-desktop:~$ ccl
Welcome to Clozure Common Lisp Version 1.7-r14925M  (LinuxX8632)!
? (ql:quickload 'trivial-dump-core)
To load "trivial-dump-core":
  Load 1 ASDF system:
    trivial-dump-core
; Loading "trivial-dump-core"
[package trivial-dump-core]
(TRIVIAL-DUMP-CORE)
? (defun hello-world ()
    (format t "Hello, World!"))
HELLO-WORLD
? (trivial-dump-core:dump-image "my-core.ccl")
To run the image, use the following command in the terminal:
ccl -I my-core.ccl
rolando@rolando-desktop:~$

Now you have a my-core.ccl file in your folder. Notice that trivial-dump-core gave you the command you need to use to start CCL with this code.

If we do that, we'll get a CCL prompt where you still have access to the hello-world function.

rolando@rolando-desktop:~$ ccl -I my-core.ccl 
Welcome to Clozure Common Lisp Version 1.7-r14925M  (LinuxX8632)!
? (hello-world)
Hello, World!
NIL
? 

Currently dump-image works for SBCL, CCL and CLISP. Keep in mind that you can only load images into the same lisp implementation that created them, ie. you can't create a CLISP image and then load it into SBCL.

save-executable usage

In this example we'll create a SBCL executable that can be delivered and ran on a computer without SBCL installed.

rolando@rolando-desktop:~$ sbcl
This is SBCL 1.0.55, an implementation of ANSI Common Lisp.
More information about SBCL is available at .

SBCL is free software, provided as is, with absolutely no warranty. It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. * (ql:quickload 'trivial-dump-core) To load "trivial-dump-core": Load 1 ASDF system: trivial-dump-core ; Loading "trivial-dump-core" [package trivial-dump-core] (TRIVIAL-DUMP-CORE) * (defun hello-world () (format t "Hello, World!~%"))

HELLO-WORLD * (trivial-dump-core:save-executable "sbcl-hello-world" #'hello-world) [undoing binding stack and other enclosing state... done] [saving current Lisp image into sbcl-hello-world: writing 3512 bytes from the read-only space at 0x01000000 writing 2224 bytes from the static space at 0x01100000 writing 32231424 bytes from the dynamic space at 0x09000000 done] rolando@rolando-desktop:~$

Now we have an executable file on the folder called "sbcl-hello-world". If you run it, the following happens:

rolando@rolando-desktop:~$ ./sbcl-hello-world 
Hello, World!
rolando@rolando-desktop:~$

The function save-executable also takes a keyword EXIT-REPL. This keyword, if NIL, allows you to return to the lisp prompt after your initial function has ran.

Here's an example of using the EXIT-REPL keyword.

rolando@rolando-desktop:~$ sbcl
This is SBCL 1.0.55, an implementation of ANSI Common Lisp.
More information about SBCL is available at .

SBCL is free software, provided as is, with absolutely no warranty. It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. * (ql:quickload 'trivial-dump-core) To load "trivial-dump-core": Load 1 ASDF system: trivial-dump-core ; Loading "trivial-dump-core"

(TRIVIAL-DUMP-CORE) * (trivial-dump-core:save-executable "sbcl-hello-world-repl" #'(lambda () (format t "Hello, World!~%")) :exit-repl nil) [undoing binding stack and other enclosing state... done] [saving current Lisp image into sbcl-hello-world-repl: writing 3512 bytes from the read-only space at 0x01000000 writing 2224 bytes from the static space at 0x01100000 writing 32231424 bytes from the dynamic space at 0x09000000 done] rolando@rolando-desktop:~$

If you run the "sbcl-hello-world-repl" executable, instead of dropping to the command-line when the function returns, you go to the SBCL prompt.

rolando@rolando-desktop:~$ ./sbcl-hello-world-repl 
Hello, World!
* (+ 1 1)

2 *

SBCL and Slime

When running SBCL inside Slime, you can't dump an image or save a executable due to the fact that SBCL is running a couple of threads inside of it.

So when you try to dump an image inside Slime, this happens.

CL-USER> (trivial-dump-core:dump-image "sbcl-slime")
Cannot dump an sbcl image from inside Slime.

Please go to the *inferior-lisp* buffer in emacs and run the following code:

(trivial-dump-core::sbcl-dump-image-slime "sbcl-slime") NIL CL-USER>

So, to dump the current sbcl image, you need to go to the *inferior-lisp* buffer (in Emacs) and type the following:

(trivial-dump-core::sbcl-dump-image-slime "sbcl-slime")

The same happens when using the save-executable function.

   CL-USER> (trivial-dump-core:save-executable "sbcl-exec-slime" #'(lambda () (format t "Hello, World!")))
   Cannot run save an sbcl image from inside Slime.
   
   Please go to the *inferior-lisp* buffer in emacs and run the following code:
   
   (trivial-dump-core::sbcl-save-slime-and-die "sbcl-exec-slime" #'(LAMBDA ()
                                                                     (FORMAT
                                                                      T
                                                                      "Hello, World!")))
   NIL
   CL-USER>

Once again, just go to the *inferior-lisp* buffer and type:

(trivial-dump-core::sbcl-save-slime-and-die "sbcl-exec-slime" #'(LAMBDA ()
                                                                  (FORMAT
                                                                   T
                                                                   "Hello, World!")))

License: MIT?

Source repository: https://github.com/rolando2424/trivial-dump-core

For more information read the README.org file.


system programming

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively