Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Binaries with Clozure Common Lisp

Tags:

Given a simple program such as the following, how would you:

  1. compile it as a seperate image file to be loaded by the implementation, and what command line arguments would you use to load it?

  2. Compile it as a standalone binary that can be loaded and run as is.

    Note: I tried adding ":prepend-kernel t" when saving the application only to have the follow error thrown.

    Error: value NIL is not of the expected type REAL. While executing:  CCL::<-2, in process Initial(0). 
  3. How would you supress the welcome message?

    The Program

    (defun main ()   (format t "This is the program.")0) 

Edit

Hate to answer part of my own question, but I found it none the less.

After the function has been loaded type the following to compile it:

(ccl:save-application "app") 

This creates an image file. To load it by passing it to the implementation type (note: the 'ccl' binary is in my system path);

ccl -I app 

To run a top level function pass it as a parameter

ccl -I app --eval (main) 
like image 204
BlueBadger Avatar asked May 07 '09 07:05

BlueBadger


1 Answers

See the Clozure Common Lisp documentation under Saving Applications

Compiling and Loading Lisp files

You can compile a file named /foo/bar.lisp by calling

 (compile-file "/foo/bar.lisp") 

This will create a fasl (FASt Load) file, which contains native code.

You can load the compiled file, the fasl file, with the function LOAD. LOAD and COMPILE-FILE are standard Common Lisp functions.

Creating applications

A few definitions:

  • CCL kernel: the part of CCL which provides low-level runtimes services like memory management.
  • Image: a saved dump of the Lisp heap
  • Application: CCL kernel + image. This can be in one file.

You can save an application by calling a CCL specific function:

(save-application "/foo/bar-image" :toplevel-function #'main) 

This will save an image, that you can run using the CCL kernel from a command shell:

ccl -I /foo/bar-image 

To save an executable that includes the kernel use this from Lisp:

(save-application "/foo/bar-app"                   :toplevel-function #'main                   :prepend-kernel t) 

You can call this executable as usual with /foo/bar-app from a command shell.

In Clozure Common Lisp you can check

*command-line-argument-list* 

for the list of provided command line arguments.

like image 60
Rainer Joswig Avatar answered Sep 17 '22 22:09

Rainer Joswig