From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id CC611820A1 for ; Fri, 23 Aug 2013 22:39:25 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of evgenyr@cs.ubc.ca) identity=pra; client-ip=142.103.6.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="evgenyr@cs.ubc.ca"; x-sender="evgenyr@cs.ubc.ca"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of evgenyr@cs.ubc.ca) identity=mailfrom; client-ip=142.103.6.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="evgenyr@cs.ubc.ca"; x-sender="evgenyr@cs.ubc.ca"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.cs.ubc.ca) identity=helo; client-ip=142.103.6.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="evgenyr@cs.ubc.ca"; x-sender="postmaster@smtp.cs.ubc.ca"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag8BAL3HF1KOZwY0kGdsb2JhbABaxASBIBYOAQEBAQkUCRkjgiQBAQEEOjMMEAsYCRMSDwVciAG2dJBwBxaDBnwDiS+OOgGGFo8G X-IPAS-Result: Ag8BAL3HF1KOZwY0kGdsb2JhbABaxASBIBYOAQEBAQkUCRkjgiQBAQEEOjMMEAsYCRMSDwVciAG2dJBwBxaDBnwDiS+OOgGGFo8G X-IronPort-AV: E=Sophos;i="4.89,944,1367964000"; d="scan'208";a="30206167" Received: from smtp.cs.ubc.ca ([142.103.6.52]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 Aug 2013 22:39:23 +0200 Received: from jade.home.test (d154-5-175-186.bchsia.telus.net [154.5.175.186] (may be forged)) (authenticated bits=0) by smtp.cs.ubc.ca (8.14.5/8.13.6) with ESMTP id r7NKdCPP024412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 23 Aug 2013 13:39:20 -0700 Date: Fri, 23 Aug 2013 13:39:35 -0700 From: Evgeny Roubinchtein To: oleg@okmij.org Cc: caml-list@inria.fr Message-ID: <20130823203932.GA8684@jade.home.test> References: <20130815070432.GA31041@jade.home.test> <20130822054756.29798.qmail@www1.g3.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130822054756.29798.qmail@www1.g3.pair.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] Callback.register equivalent before runtime is 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