From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 08990BB83 for ; Mon, 14 Aug 2006 17:21:28 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7EFLRmv004691 for ; Mon, 14 Aug 2006 17:21:27 +0200 Received: by nf-out-0910.google.com with SMTP id l37so105332nfc for ; Mon, 14 Aug 2006 08:21:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=J5csn0w4Q714lxmKbr7RRnU5yR+ah9ZNjEqgumxP3Z5fuRyegppq6cajheKZsuBBT6n4zj0No6inPcstqJIuJMaAOlnOUl/lKyv3ElzbqssrjYmdZUerCbCs2NA6ts/ctrMmbGn0HcE8D6JMISpfBiuzCpgWlug4TgYj1oo+KZ4= Received: by 10.49.21.8 with SMTP id y8mr1355332nfi; Mon, 14 Aug 2006 08:21:25 -0700 (PDT) Received: by 10.49.32.6 with HTTP; Mon, 14 Aug 2006 08:21:25 -0700 (PDT) Message-ID: Date: Mon, 14 Aug 2006 17:21:25 +0200 From: Tom To: caml-list@yquem.inria.fr Subject: Dynamic loading of bytecode MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_82491_21475230.1155568885951" X-j-chkmail-Score: MSGID : 44E094F7.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44E094F7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bytecode:01 hiearchy:01 toploop:01 bytecode:01 ocamlc:01 ocamlc:01 toploop:01 hiearchy:01 compile:01 compile:01 simplify:01 simplify:01 modules:02 modules:02 dependent:02 X-Attachments: cset="UTF-8" cset="UTF-8" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=HTML_20_30,HTML_MESSAGE, RCVD_BY_IP autolearn=disabled version=3.0.3 ------=_Part_82491_21475230.1155568885951 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline There is a really stupid question I want to ask, I have been searching online for some days now and couldn't get it answered... How can you load the whole module hiearchy (many modules, dependent on one another) with a single command in toploop? Say I have files a.ml: let f x = x - 1 and b.ml: let g x y = x + f y - f x and I compile them into bytecode ocamlc -c a.ml ocamlc -c b.ml and then I want to be able to load them into the toploop so that I could access both modules A and B: # let simplify x = B.g x - A.f x How do I do that? ------=_Part_82491_21475230.1155568885951 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline There is a really stupid question I want to ask, I have been searching online for some days now and couldn't get it answered...

How can you load the whole module hiearchy (many modules, dependent on one another) with a single command in toploop?

Say I have files a.ml:

  let f x = x - 1

and b.ml:

  let g x y = x + f y - f x


and I compile them into bytecode

  ocamlc -c a.ml
  ocamlc -c b.ml

and then I want to be able to load them into the toploop so that I could access both modules A and B:

  # let simplify x = B.g x - A.f x


How do I do that?
------=_Part_82491_21475230.1155568885951-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 33898BB83 for ; Mon, 14 Aug 2006 17:41:38 +0200 (CEST) Received: from smtp-msa-out07.orange.fr (smtp7.orange.fr [193.252.22.24]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7EFfX4U022391 for ; Mon, 14 Aug 2006 17:41:38 +0200 Received: from morgana (ARennes-257-1-49-109.w81-53.abo.wanadoo.fr [81.53.128.109]) by mwinf0701.orange.fr (SMTP Server) with ESMTP id 7AEF97000082; Mon, 14 Aug 2006 17:41:31 +0200 (CEST) X-ME-UUID: 20060814154131503.7AEF97000082@mwinf0701.orange.fr Received: from david by morgana with local (Exim 4.50) id 1GCeaV-0002XP-P7; Mon, 14 Aug 2006 17:42:47 +0200 To: Tom Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Dynamic loading of bytecode References: From: David MENTRE Organization: none Date: Mon, 14 Aug 2006 17:42:47 +0200 In-Reply-To: (tom.primozic@gmail.com's message of "Mon, 14 Aug 2006 17:21:25 +0200") Message-ID: <87oduniars.fsf@linux-france.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at concorde with ID 44E099AD.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bytecode:01 bytecode:01 ocamlc:01 ocamlc:01 toploop:01 ocaml:01 toplevel:01 ocaml:01 cmo:01 cmo:01 3.08.3:01 toplevel:01 3.08.3:01 val:01 gpg:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, Tom writes: > Say I have files a.ml: > > let f x = x - 1 > > and b.ml: > > let g x y = x + f y - f x let g x y = x + A.f y - A.f x > > and I compile them into bytecode > > ocamlc -c a.ml > ocamlc -c b.ml > > and then I want to be able to load them into the toploop so that I could > access both modules A and B: > > # let simplify x = B.g x - A.f x > > > How do I do that? * In command line given to ocaml toplevel: $ ocaml a.cmo b.cmo Objective Caml version 3.08.3 # B.g 1 2;; * Inside the toplevel, you need to #load each bytecode file: $ ocaml Objective Caml version 3.08.3 # #load "a.cmo";; # #load "b.cmo";; # let simplify x = B.g x x - A.f x;; val simplify : int -> int = TFM: http://caml.inria.fr/pub/docs/manual-ocaml/manual023.html Best wishes, d. PS: This kind of question might better go to caml-beginners@ mailing list. -- GPG/PGP key: A3AD7A2A David MENTRE 5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 31423BB83 for ; Thu, 17 Aug 2006 13:48:02 +0200 (CEST) Received: from [128.93.11.95] (estephe.inria.fr [128.93.11.95]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7HBm1ag026977; Thu, 17 Aug 2006 13:48:01 +0200 Message-ID: <44E45771.3090805@inria.fr> Date: Thu, 17 Aug 2006 13:48:01 +0200 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.6-6mdk (X11/20050322) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Dynamic loading of bytecode References: In-Reply-To: X-Enigmail-Version: 0.92.0.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; bytecode:01 hiearchy:01 toploop:01 makefile:01 ocamlc:01 mylib:01 cmo:01 cmo:01 toplevel:01 mylib:01 caml-list:01 cma:01 cma:01 modules:02 dependent:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 > How can you load the whole module hiearchy (many modules, dependent on > one another) with a single command in toploop? You cannot. However, you could build a .cma archive via a Makefile: ocamlc -a -o mylib.cma a.cmo b.cmo and issue the toplevel command #load "mylib.cma", which will load both module implementations at once. - Xavier Leroy From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 16DBFBB83 for ; Fri, 18 Aug 2006 03:15:28 +0200 (CEST) Received: from mail.rsise.anu.edu.au (mail.rsise.anu.edu.au [150.203.208.4]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7I1FOMU028556 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 18 Aug 2006 03:15:27 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 00C0154030 for ; Fri, 18 Aug 2006 11:15:06 +1000 (EST) Received: from mail.rsise.anu.edu.au ([150.203.208.4]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04210-03 for ; Fri, 18 Aug 2006 11:15:05 +1000 (EST) Received: from pulp.rsise.anu.edu.au (pulp.rsise.anu.edu.au [150.203.208.49]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id DEB275402F for ; Fri, 18 Aug 2006 11:15:05 +1000 (EST) Received: by pulp.rsise.anu.edu.au (Postfix, from userid 1560) id D3427A0AFC8; Fri, 18 Aug 2006 11:15:17 +1000 (EST) Date: Fri, 18 Aug 2006 11:15:17 +1000 From: Pietro Abate To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Dynamic loading of bytecode Message-ID: <20060818011517.GA6557@pulp.rsise.anu.edu.au> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at mail.rsise.anu.edu.au X-Spam: no; 0.00; bytecode:01 hiearchy:01 toploop:01 dependencies:01 hashtbl:01 hashtbl:01 uncapitalize:01 cmo:01 modname:01 modname:01 printf:01 printf:01 dynlink:01 loadfile:01 endline:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Mon, Aug 14, 2006 at 05:21:25PM +0200, Tom wrote: > How can you load the whole module hiearchy (many modules, dependent on one > another) with a single command in toploop? I use these two functions to resolve linear dependencies. I'm sure there is a better solution... let modules = Hashtbl.create 17;; let are_loading = Hashtbl.create 17;; let find_in_path path name = let filename = ((String.uncapitalize name) ^ ".cmo") in if not (Filename.is_implicit filename) then if Sys.file_exists filename then filename else raise Not_found else begin let rec try_dir = function | [] -> raise Not_found | dir::rem -> let fullname = Filename.concat dir filename in if Sys.file_exists fullname then fullname else try_dir rem in try_dir path end let rec load_module modname path = try Hashtbl.find modules modname with Not_found -> try Hashtbl.add modules modname (); Hashtbl.add are_loading modname (); (* Printf.printf "Loading: %s ..." modname; *) Dynlink.loadfile (modname); (* print_endline "done."; *) Hashtbl.remove are_loading modname with | Dynlink.Error(Dynlink.Unavailable_unit(depend)) | Dynlink.Error( Dynlink.Linking_error(_,Dynlink.Undefined_global(depend)) ) -> begin try if Hashtbl.mem are_loading depend then failwith ("Crossing with "^depend); load_module (find_in_path path depend) path; Hashtbl.remove modules modname; load_module modname path with Not_found -> failwith ("Cannot find " ^String.lowercase(depend)^" in "^ (List.fold_left (fun s x -> s^x) " " path)) end | Dynlink.Error(e) -> failwith (Dynlink.error_message e) ;; -- ++ Blog: http://blog.rsise.anu.edu.au/?q=pietro ++ ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html