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 CAA17200; Fri, 1 Nov 2002 02:56:47 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 CAA17360 for ; Fri, 1 Nov 2002 02:56:46 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gA11ukD21545 for ; Fri, 1 Nov 2002 02:56:46 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id gA11ujB35069 for ; Fri, 1 Nov 2002 02:56:45 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.12.3/jb-1.1) id gA11ujeR020634 for ; Fri, 1 Nov 2002 02:56:45 +0100 (MET) Date: Fri, 1 Nov 2002 02:56:44 +0100 (MET) From: Alain Frisch To: Caml list Subject: [Caml-list] Identifying the code part of a closure Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, for some reasons(*), I need to associate to a runtime closure an integer that identifies its code pointer. Is the following a "safe" solution for ocamlc and ocamlopt ("safe" means here that it works in all cases, with the current implementation, under all the architectures where ocamlopt exists) ? let addr (h : 'a -> 'b) : int = fst (Obj.magic h);; Do you see a better way to achieve this ? -- Alain (*) for those who are interested, what I'm trying to do is to implement a functional language by compiling it to OCaml; the closures of the language map directly to OCaml closures. It turns out that the language has explicit typing for functions (for instance: fun (t1 -> t2) x -> ...) and the semantics of the language has to access the type information (t1 -> t2) at runtime; all the closures for a function share this piece of information, so I'd like to store it during program initialization in a structure indexed by some integer computed from a sample closure of the function. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners