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

new stand-alone executable trick



 [Note: Since my 102/13 message, I had to update and exp-tag a few
 MzScheme files to make the following trick work. The change is the
 addition of `provide-library'.]

mzc (the current exp-tagged version in CVS) can now embed Scheme code
into a copy of the MzScheme or MrEd executable. This trick makes it
easy to create a stand-alone executable for environments where big
executables are ok, but multi-file apps are not.

The new flags for mzc are --exe and --gui-exe:

  mzc --exe demo.exe demo.scm
     Creates an executable that is equivalent to 
     `mzscheme -mvqf- demo.scm'

  mzc --gui-exe guidemo.exe guidemo.scm
     Creates an executable that is equivalent to 
     `mred -mvqf- guidemo.scm'

Any number of files can be specified in the place of demo.ss. The files
can be Scheme source (.scm) or byte code (.zo).

If a Scheme program uses `require-library', then the corresponding
library collections should also go into in the executable. The
++collect flag embeds a whole collection:

  mzc --exe demo.exe ++collect mzlib demo.scm
     where demo.scm uses `require-library' to get MzLib functionality

The ++collect flag can be used multiple times.

----------------------------------------

How it works:

The MzScheme and MrEd 102/13 executables contain a static string to be
parsed as extra command-line arguments. In a copy of MzScheme or MrEd,
mzc modifies this static string to -k <n> <m>, where -k is roughly like
-l, except that it loads from the current executable at file positions
<n> through <m>.

mzc writes an <n> corresponding to the original end-of-file for the
executable. It then appends the provided source code onto the
executable, and computes <m> as the new end-of-file.

Library code is appended first, wrapped as follows:

  (provide-library 
   (lambda ()
     (let ([p (open-input-string <LIBRARY-FILE-CONTENT>)])
       ... read and evaluate from p...))
   <LIBRARY> <COLLECTION>)

where the new `provide-library' procedure lets a programmer install an
arbitrary library-loading thunk for a library (assuming the library is
not already loaded).

Is it always ok to toss extra bytes onto the end of an executable file?
I don't know, but it's worked on all the platforms I've tried so far.

Matthew