License: MIT-License
Source repository: https://github.com/rolando2424/trivial-dump-core
For more information read the README.org file.
Installation
trivial-dump-core is available via Quicklisp: (ql:quickload "trivial-dump-core")
dump-image
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 ?
save-executable
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 <http://www.sbcl.org/>. * (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:~$
SBCL and Slime
When running SBCL connected to Slime, you can't dump an image or save a executable due to the fact that SBCL is running several threads.
The obvious solution is not to start Slime when you want to make an executable in SBCL. If you don't like obvious solutions, read on:
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!")))