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 32A47820A1 for ; Thu, 22 Aug 2013 07:47:59 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of oleg@okmij.org) identity=pra; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of oleg@okmij.org designates 66.39.3.115 as permitted sender) identity=mailfrom; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@www1.g3.pair.com) identity=helo; client-ip=66.39.3.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="postmaster@www1.g3.pair.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AooCAKOlFVJCJwNzemdsb2JhbABaxAKBMw4BAQsHDQk8giQBAQQBbQwFFjRpFIgPBq4rkFcHFoN+A5diAZR0PA X-IPAS-Result: AooCAKOlFVJCJwNzemdsb2JhbABaxAKBMw4BAQsHDQk8giQBAQQBbQwFFjRpFIgPBq4rkFcHFoN+A5diAZR0PA X-IronPort-AV: E=Sophos;i="4.89,932,1367964000"; d="scan'208";a="30012797" Received: from www1.g3.pair.com ([66.39.3.115]) by mail2-smtp-roc.national.inria.fr with SMTP; 22 Aug 2013 07:47:57 +0200 Received: (qmail 29799 invoked by uid 9370); 22 Aug 2013 05:47:56 -0000 Date: 22 Aug 2013 05:47:56 -0000 Message-ID: <20130822054756.29798.qmail@www1.g3.pair.com> From: oleg@okmij.org To: evgenyr@cs.ubc.ca CC: caml-list@inria.fr In-reply-to: <20130815070432.GA31041@jade.home.test> Subject: Re: [Caml-list] Callback.register equivalent before runtime is > 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 ()