Lisp HUG Maillist Archive

fasl loader usage in a delivered image

I have an application that writes out CLOS instances into a source
code file which is subsequently compiled.  This is to allow the
instances to be reloaded quickly using the standard LOAD function (of
course you have to define MAKE-LOAD-FORM methods for this to work).

Unfortunately, I don't think that I can get this idiom to work using a
delivered lispworks image because the file compiler has been removed.
It works fine with LWL 4.2.7 when I am running out of the IDE.

Is there any work around so that I can get the desired functionality?
As of right now, I'm using LWL 4.2.7, but I don't think that this is
version specific.

Here is some example code that shows that idiom:

(defun load-web-data (&key (dir *web-dir*)
                           (name "web-data"))
  (load (compile-file-pathname
   (make-pathname :defaults dir
                            :name name)))
  (setf *web-id*
        (max *web-id*
             (1+ (loop for instance in *web-instances*
                       maximize (web-id instance))))))

(defun dump-web-data (&key (dir *web-dir*)
                           (name "web-data"))
  (let ((cf (make-pathname :defaults dir
                           :name name
                           :type "lisp")))
    (with-open-file (s cf
                       :direction :output
                       :if-exists :supersede
                       :if-does-not-exist :create)
      (dolist (var '(*web-instances*))
      (format s "(SETF ~S '#.~S)" var var)))
    (compile-file cf :output-file
                  (compile-file-pathname
                   (make-pathname :defaults cf :type nil)))))

And here is the contents of one of the files that gets compiled and
then loaded:

(SETF ORG.CL-USER::*WEB-INSTANCES* '#.ORG.CL-USER::*WEB-INSTANCES*)

-russ


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


Re: fasl loader usage in a delivered image

hey,

Though I havn't tried it, you can try making the COMPILE a part of your load
form, e.g.:

 (compile nil #'(lambda () (defclass my-class () ...)))

or

 (compile nil #'(lambda () (make-instance 'my-class ...)))

This should adapt to just about any given load form.

LispWorks doesn't include the file compiler, but they do include the COMPILE
function.  As far as the performance gain, though, I don't know what you can
expect.  I've heard that some [other?] Lisp implementations tend to compile
CLOS forms, even when they're evaluated.

dave

--- Russell McManus <russell_mcmanus@yahoo.com> wrote:

> 
> I have an application that writes out CLOS instances into a source
> code file which is subsequently compiled.  This is to allow the
> instances to be reloaded quickly using the standard LOAD function (of
> course you have to define MAKE-LOAD-FORM methods for this to work).
> 
> Unfortunately, I don't think that I can get this idiom to work using a
> delivered lispworks image because the file compiler has been removed.
> It works fine with LWL 4.2.7 when I am running out of the IDE.
> 
> Is there any work around so that I can get the desired functionality?
> As of right now, I'm using LWL 4.2.7, but I don't think that this is
> version specific.
> 
> Here is some example code that shows that idiom:
> 
> (defun load-web-data (&key (dir *web-dir*)
>                            (name "web-data"))
>   (load (compile-file-pathname
>    (make-pathname :defaults dir
>                             :name name)))
>   (setf *web-id*
>         (max *web-id*
>              (1+ (loop for instance in *web-instances*
>                        maximize (web-id instance))))))
> 
> (defun dump-web-data (&key (dir *web-dir*)
>                            (name "web-data"))
>   (let ((cf (make-pathname :defaults dir
>                            :name name
>                            :type "lisp")))
>     (with-open-file (s cf
>                        :direction :output
>                        :if-exists :supersede
>                        :if-does-not-exist :create)
>       (dolist (var '(*web-instances*))
>       (format s "(SETF ~S '#.~S)" var var)))
>     (compile-file cf :output-file
>                   (compile-file-pathname
>                    (make-pathname :defaults cf :type nil)))))
> 
> And here is the contents of one of the files that gets compiled and
> then loaded:
> 
> (SETF ORG.CL-USER::*WEB-INSTANCES* '#.ORG.CL-USER::*WEB-INSTANCES*)
> 
> -russ
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 
> 


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


Re: fasl loader usage in a delivered image

Russell McManus <russell_mcmanus@yahoo.com> writes:

> I have an application that writes out CLOS instances into a source
> code file which is subsequently compiled.  This is to allow the
> instances to be reloaded quickly using the standard LOAD function (of
> course you have to define MAKE-LOAD-FORM methods for this to work).

<shameless_plug>
If you aren't particularly attached to using load to get your
instances back you could always use cl-store (http://cliki.net/cl-store). 

(defun load-web-data (&key (dir *web-dir*)
                           (name "web-data"))
  (let ((path (make-pathname :defaults dir :name name :type "dat")))
    (setf *web-id*
          (max *web-id*
               (1+ (loop for instance in (cl-store:restore path)
                         maximize (web-id instance)))))))

(defun dump-web-data (&key (dir *web-dir*)
                           (name "web-data"))
  (let ((cf (make-pathname :defaults dir :name name :type "dat")))
    (cl-store:store *web-instances* cf)))

</shameless_plug>


Regards,
  Sean.

-- 
"My doctor says that I have a malformed public-duty gland and a
 natural  deficiency in moral fibre," he muttered to himself, "and
 that I am therefore excused from saving Universes."
 - Life, the Universe, and Everything     Douglas Adams.


Re: fasl loader usage in a delivered image

Hello Russell,

| I have an application that writes out CLOS instances into a source
| code file which is subsequently compiled.  This is to allow the
| instances to be reloaded quickly using the standard LOAD function (of
| course you have to define MAKE-LOAD-FORM methods for this to work).
|
| Unfortunately, I don't think that I can get this idiom to work using a
| delivered lispworks image because the file compiler has been removed.
| It works fine with LWL 4.2.7 when I am running out of the IDE.
|
| Is there any work around so that I can get the desired functionality?
| As of right now, I'm using LWL 4.2.7, but I don't think that this is
| version specific.
|...snip...|

I would recommend using hcl:dump-forms-to-file and sys:load-data-file. They
work fine in a delivered image and do not need the file compiler.

Moreover, in my exepriece, the binary _data_ files are upward compatible
among LispWorks version, despite of what readme-4400.txt says:

  11.9  Binary Incompatibilty
  If you have binaries (fasl files) which were compiled using
  LispWorks 4.3 or previous versions, please note that these
  are not compatible with this release.

I am not sure whether they will retain this kind of upgrade compatibility in
the future, but I hope so.
--
Sincerely,
Dmitri Ivanov
lisp.ystok.ru


Updated at: 2020-12-10 08:53 UTC