From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA15809; Fri, 7 Dec 2001 15:40:53 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA16088 for caml-list@pauillac.inria.fr; Fri, 7 Dec 2001 15:40:52 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA03583 for ; Thu, 6 Dec 2001 22:28:12 +0100 (MET) Received: from tourian.nerim.net (tourian.nerim.net [62.4.16.79]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id fB6LS9b01061 for ; Thu, 6 Dec 2001 22:28:09 +0100 (MET) Received: from hector.lesours (lesours.starynkevitch.net [80.65.224.217]) by tourian.nerim.net (Postfix) with ESMTP id EFC51D90D for ; Thu, 6 Dec 2001 22:28:08 +0100 (CET) Received: from basile by hector.lesours with local (Exim 3.32 #1 (Debian)) id 16C63r-0000V2-00 for ; Thu, 06 Dec 2001 22:28:07 +0100 From: Basile STARYNKEVITCH MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15375.58084.611097.762861@hector.lesours> Date: Thu, 6 Dec 2001 22:28:04 +0100 To: caml-list@inria.fr Subject: [Caml-list] embedding Ocaml in an existing application X-Mailer: VM 6.97 under Emacs 21.1.2 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, Some remarks (and wishes) about embedding Ocaml (bytecoded) in an existing application. I just embedded (a single day hack) Ocaml inside the Larbin web crawler (coded in C++ by Sebastien Ailleret) on http://pauillac.inria.fr/~ailleret/prog/larbin/ You should be able to get the patch from my personal web page or else email me either at work or at home . This because I need (for the POESIA project) to scan some part of the Web and get some crude measures of features like: percentage of Web pages using Javascript (about 50%) and mean length of such scripts (about 2Kbytes). So I hacked larbin to add Ocaml inside it. I used ocaml v3.02 or v3.01 (bytecode interpreter). First remark: the ocaml linking mechanism use the undocumented -p flag to dump all the Ocaml symbol table. So I had to hack Larbin's main routine to test for the special -p single argument and then call only ocaml_main_init(argv); and exit(0) in that case. I believe that it would be quite trickly to embed Ocaml inside a significant application which uses the -p flag (see the code in ocaml/byterun/startup.c routine parse_command_line). At least I suggest that the linking mechanism use a less natural convention (such as "-print-ocaml-symbols" as argv[1] of main) and that it could be documented. (and I did not found quickly where Ocaml invokes this magic -p flag). Second remark: for embedding Ocaml inside Larbin I need the -use-runtime flag to the ocamlc compiler. But it seems that the next version (v3.03) does not have it anymore. I hope that it will still be possible to embed OCaml inside an application without having to compile the whole application as a shared library. 3rd remark: why don't caml_main take and changes the main argc,argv arguments (like e.g. gtk_init routine in the Gtk toolkit) so that the application can use the other arguments. Otherwise, I suggest to publicize the parse_command_line routine so an embedding application could parse its own main arguments and pass some others to ocaml before starting the Ocaml interpreter. (imagine you want to embed Ocaml inside an existing Gtk application?). My previous post http://caml.inria.fr/archives/200112/msg00015.html regarding a tiny syntactic extension was related to this [Larbin] patch. I think that novice Ocaml users might be interested in a syntactic sugar to register bound values. Regards to all -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet alias: basiletunesorg 8, rue de la Faïencerie, 92340 Bourg La Reine, France ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr