[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 1998-06-23 (00:50) |
From: | Xavier Leroy <Xavier.Leroy@i...> |
Subject: | Re: Dynamic usage of Ocaml evaluator? |
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