From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Dynamic loading of bytecode
Date: Fri, 18 Aug 2006 11:15:17 +1000 [thread overview]
Message-ID: <20060818011517.GA6557@pulp.rsise.anu.edu.au> (raw)
In-Reply-To: <c1490a380608140821q497970cfr6a8f091ec73b19ef@mail.gmail.com>
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
prev parent reply other threads:[~2006-08-18 1:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-14 15:21 Tom
2006-08-14 15:42 ` [Caml-list] " David MENTRE
2006-08-17 11:48 ` Xavier Leroy
2006-08-18 1:15 ` Pietro Abate [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060818011517.GA6557@pulp.rsise.anu.edu.au \
--to=pietro.abate@anu.edu.au \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox