1
votes

As all we know, in we can use #use directive in OCaml toplevel to load ml files then execute.

And we can also use ocaml.exe to load and execute ml files.

Here my requirement has some changes to these two situations:

I have a main process, who creates a ocaml toplevel to execute scripts, the two process communicates with shared memory and stdin/stdout. The address(token) of shared memory are given in Sys.argv.

The problem is, I want to load ml files dynamically after the creation of process, so the ml to execute is not given at first.

If I start the process with "ocaml.ml xx.ml [params]", the script will be executed at once and I can't simply use #use directive after the beginning of the script.

If I go into interactive mode, I can't give the shared address since once I give these prams, they are considered as ml filename.

So anyone has an idea to make it happen? The ocaml toplevel is a background service and it calls a script who enters an event loop once started.

1
Have you written an .ocamlinit file?Edward Minnix
yes, but that doesn't change anything for me, actually I don't want to go into interactive mode but repl.Enzojz

1 Answers

0
votes

It seems to me that you could send the parameters for communication to the interactive toplevel before entering your event loop.

Or you could use the compiler libraries to take control of the repl directly and interleave Toploop.execute_phrase and Toploop.use_silently.

Another option might be to spawn a native process and use dynlinking rather than loading ml files.