From: Evgeny Roubinchtein <evgenyr@cs.ubc.ca>
To: oleg@okmij.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Callback.register equivalent before runtime is
Date: Fri, 23 Aug 2013 13:39:35 -0700 [thread overview]
Message-ID: <20130823203932.GA8684@jade.home.test> (raw)
In-Reply-To: <20130822054756.29798.qmail@www1.g3.pair.com>
On Thu, Aug 22, 2013 at 05:47:56AM -0000, oleg@okmij.org wrote:
>
> > I am learning about run-time compilation, and using OCaml as a base for
> > my experiments. So far, I have a really simple C primitive that just
>
> > However, I am now trying to move to producing bytecode executables, so,
> > if I stay with my current set-up I would need to do the equivalent of
> > Callback.register (i.e., put the address of the wrapper into the hash
> > table maintained by caml_callback_register) before any of the "user
> > code" in the executable starts to run.
>
> You may want to look into how MetaOCaml does it. Briefly, you just
> have to link in your own .cmo file right before user's files. Your
> file will set things up. For example, metaocamlc is a shell script
> that does
>
> exec ocamlc -I +compiler-libs ocamlcommon.cma ocamlbytecomp.cma ocamltoplevel.cma metalib.cma berstart.cmo "$@"
>
> The key is the file berstart.cmo placed before any user files to
> compile and link. That file is trivial and enclosed for
> convenience. The file mentions Toplevel because MetaOCaml relies on
> top-level for executing code created at run-time. You can add your
> registration code to that file.
>
> (*
> To `run' the code we use toplevel facilities.
> If we invoke BER MetaOcaml top level, then Toplevel.topstart() will
> initalialize the top level.
> If we execute a byte-compiled executable, we link with
> the top-level library. But we need initialize it first.
> This is the job of the current file.
>
> This file must be linked in *before* the first user executable.
>
> The present code roughly do the same steps OCaml top level does
> when executing a script.
> See Toplevel.topmain
> *)
>
> let () =
> Toploop.set_paths ();
> Compile.init_path();
> Toploop.initialize_toplevel_env ()
Thank you. Yes, after experimenting with David Allsop's earlier
suggestion, I eventually realized that "module initialization" code gets
executed "early enough for my purposes", so I ended up doing exactly
what you suggested above.
--
Best,
Evgeny
prev parent reply other threads:[~2013-08-23 20:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-15 7:04 [Caml-list] Callback.register equivalent before runtime is initialized? Evgeny Roubinchtein
2013-08-15 7:33 ` David Allsopp
2013-08-22 5:47 ` [Caml-list] Callback.register equivalent before runtime is oleg
2013-08-23 20:39 ` Evgeny Roubinchtein [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130823203932.GA8684@jade.home.test \
--to=evgenyr@cs.ubc.ca \
--cc=caml-list@inria.fr \
--cc=oleg@okmij.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).