Re: exportFn and evalStream questions

John Reppy <[email protected]> Mon, 5 Oct 2009 09:12:57 -0500
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
On Oct 5, 2009, at 7:43 AM, Joe Wells wrote:

> Dear SML/NJ gurus,
>
> Would it be possible for someone to please answer 1 or more of the
> following questions about exportFn and evalStream?

I can answer the first two.  Dave or Matthias should be able to address
the others.

>
> 1. Where does exportFn discard the contents of the top-level
>   environment?  I've been looking through the source code and if I
>   have seen it I certainly have not recognized it.  It is clear that
>   this is happening both from the documentation and also from the
>   fact that subsequent uses of evalStream or useStream seem to
>   complain that all identifiers are undefined.

The discarding of the environment is effectively done by the GC.  We
isolate the return continuation of the exported function so that it
does not refer to the top-level-loop, and, thus, the environment becomes
garbage.

>
> 2. Is it possible to get the same space-saving effect as exportFn
>   without having to write a heap image to disk and then exec a fresh
>   sml process to load the heap image?  (Another problem this would
>   avoid is the fact that exportFn closes all files and clears the
>   signal handler table.)  Is it enough to clear the top-level
>   environment by hand and then let the garbage collector do its work?
>   And does anyone have any example SML code that clears the top-level
>   environment correctly?  Can doing this release memory back to the
>   system?  If not, can doing this at least reduce the amount of work
>   the garbage collector needs to do regularly?

Yes, as long as you don't want to return to the top-level loop.  See
the code in

	base/system/Basis/Implementation/NJ/export.sml

>
> 3. Is is possible to preserve some portion of the top-level
>   environment across an exportFn?  It would be enough to preserve the
>   constructors and type names of some datatypes and built-in types,
>   so that evalStream and useStream could still work for parsing, type
>   checking, and pretty printing datatype values.

>
> 4. Can someone provide an example of constructing a custom environment
>   for use with evalStream?  Any example would do.  I already know how
>   to do something that seems equivalent to the top-level environment.
>   It would be particularly nice if the example showed how to include
>   just datatype constructors and type names.
>
> Thanks for your time in considering my questions.  And extra thanks
> if anyone answers even just one of my questions!
>
> --  
> Joe
>
>
> --  
> Heriot-Watt University is a Scottish charity
> registered under charity number SC000278.
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart  
> your
> developing skills, take BlackBerry mobile applications to market and  
> stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register  
> now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf