воскресенье, 3 февраля 2008 г.

create executable file from lisp source (sbcl)

This is a very simple lisp file:

(print "Hello. World!")

At first, need compile this file:

:~$ sbcl --noinform
* (compile-file "helloworld.lisp" :output-file "helloworld")

; compiling file "/home/asimakov/helloworld.lisp" (written 04 FEB 2008 12:44:58 AM):
; compiling (PRINT "Hello. World!")

; /home/asimakov/helloworld.fasl written
; compilation finished in 0:00:00
#P"/home/asimakov/helloworld.fasl"
NIL
NIL
*

Next, load module binfmt_misc and mount binfmt_misc filesystem:

:~$ sudo modprobe binfmt_misc
:~$ sudo mount -t binfmt_misc none /proc/sys/fs/binfmt_misc

At last, register fasl filetype (from root of course) by the specyfing a byte pattern:

:~$ echo ":lisp:M::\x23\x20FASL::/usr/lib/sbcl/sbcl-run:" > /proc/sys/fs/binfmt_misc/register

or by extension:

:~$ echo ':lisp:E::fasl::/usr/lib/sbcl/sbcl-run:' > /proc/sys/fs/binfmt_misc/register

That's all, you can execute fasl from command line:

:~$ chmod +x helloworld.fasl ; ./helloworld.fasl
"Hello. World!"


See also:
Documentation for binfmt_misc: http://www.kernel.org/doc/Documentation/binfmt_misc.txt