Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Identifying the code part of a closure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <frisch@c...>
Subject: [Caml-list] Identifying the code part of a closure
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