Date: Mon, 22 Jun 1998 11:00:36 +0200
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Jan Skibinski <jans@numeric-quest.com>, caml-list@inria.fr
Subject: Re: Dynamic usage of Ocaml evaluator?
In-Reply-To: <Pine.LNX.3.95.980618023921.13536B-100000@info.numeric-quest.com>; from Jan Skibinski on Thu, Jun 18, 1998 at 03:48:42AM -0500
For several reasons, "eval" is hard to support well in Caml. There
are typing issues, of course. Also, the Caml Light and Objective Caml
implementations are more targeted towards batch compilation than
towards run-time code generation. (Remember, those two
implementations are not interpreters, but full compilers.)
This said, your solution with Toploop.run_script is reasonable, and
probably the simplest way to get what you want. I'm assuming you're
not concerned about security, as it allows embedded scripts to do
pretty much anything the user could do (e.g. by calling Sys.command).
An alternate solution would be to compile the ML source by calling the
ocamlc compiler, then load the compiled bytecode using the Dynlink
library. This allows more precise control on what the user code has
access to. However, in your particular case it doesn't make much
sense to generate a .cmo file that you're going to use only once.
> Is there any better way to do it? Is the code below correct? It works,
> but I am afraid that it might leave the toplevel in some unstable state.
> Normally I do exit from the toplevel after I finished producing the
> document (70 or so pages), but I wonder what might go wrong on a long
> run?
I think it should work fine. Some of the bytecode will accumulate in
memory (i.e. the bytecode for the functions defined in the embedded ML
text), but you'd really need large quantities of embedded ML before
that becomes noticeable.
Regards,
- Xavier Leroy
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:14 MET