From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA21348 for caml-redistribution; Tue, 23 Jun 1998 02:50:53 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA24188 for ; Mon, 22 Jun 1998 11:00:53 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id LAA03463; Mon, 22 Jun 1998 11:00:36 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA16214; Mon, 22 Jun 1998 11:00:36 +0200 (MET DST) Message-ID: <19980622110036.30478@pauillac.inria.fr> Date: Mon, 22 Jun 1998 11:00:36 +0200 From: Xavier Leroy To: Jan Skibinski , caml-list@inria.fr Subject: Re: Dynamic usage of Ocaml evaluator? References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: ; from Jan Skibinski on Thu, Jun 18, 1998 at 03:48:42AM -0500 Sender: weis 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