[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiled MCL across launches

At 23:41 11/25/92 +0100, oddmund@idt.unit.no wrote:
>  I am using MCL to implement a group hierarchy for my thesis. It is 
>  meant to work much the same way as HyperCard: 
>    When a message is sent to a target (a node in the group hierarchy),
>    the path from the target to the root is searched for the first
>    applicable message handler. 
>  My message handlers will be regular MCL functions.
>  For performance reasons my group hierarchy should store compiled MCL 
>  functions to file when I quit MCL, and then restore them and start 
>  using them again (without recompilation) the next time I launch MCL. 
>  Otherwise, the system will take an hour to boot.
>  For each message handler, I plan to dump the bytes returned by 
>  symbol-function to file before quitting, and then restore the same 
>  bytes from file to use the function again. The functions will always 
>  be used in a package of the same name.
>  Can my suggested approach be made to work, or is it doomed? In other 
>  words, do MCL compiled functions contain pointers/constants etc. 
>  which may become invalid in another launch of MCL?
>  The file compiler is not a solution for me because there are no files 
>  to compile, because there will be a large number of different but 
>  identically named functions etc. 

I'm not sure what you mean by "the bytes returned by symbol-function".
symbol-function returns a function. Though there are undocumented
internal functions in MCL for viewing a function as a vector of 16-bit
words, you cannot simply save these integers, as some of them represent
relocateable Lisp objects. These objects are usually symbols or strings,
but, depending on your code, can be any Lisp object.

My Wood database knows how to save and restore functions. You might look
at the file "split-lfun.lisp", which is part of Wood. It knows how to
split a function up into five vectors containing Lisp objects which can
be used to create a copy of the function. These vectors are amenable
to being printed in a readable form (assuming all of the Lisp objects coded
into your function are readably printable). Wood version 0.5 is on the
anonymous FTP server at cambridge.apple.com in the file

Another, more portable and probably easier, approach is to use MCL's file
compiler to save your functions. The general approach is to have a file
named "*saved-object*.lisp" containing the following:


; *saved-object*.lisp
; Compiling this file will make a FASL that will initialize the
; variable *saved-object* to its value when the file was compiled:

(setq *saved-object* '#.*saved-object*)


Then you can use the following code to save any object, including
a compiled function, to a fasl file:

(defvar *saved-object* nil)

(defun save-object (object file)
  (let ((*saved-object* object))
    (compile-file "*saved-object*" :output-file file)))

(defun restore-object (file)
  (let ((*saved-object* nil))
    (load file)

You can either keep a directory of files with one file for each function,
or copy the bytes from the fasl file into a database and recreate the fasl
file (remember to (set-mac-file-type <file> "FASL")) when you want to
load the function.