1 (* camlp4r pa_macro.cmo *)
2 (****************************************************************************)
6 (* INRIA Rocquencourt *)
8 (* Copyright 2001-2006 Institut National de Recherche en Informatique et *)
9 (* en Automatique. All rights reserved. This file is distributed under *)
10 (* the terms of the GNU Library General Public License, with the special *)
11 (* exception on linking described in LICENSE at the top of the Objective *)
12 (* Caml source tree. *)
14 (****************************************************************************)
17 * - Daniel de Rauglaudre: initial version
18 * - Nicolas Pouillard: refactoring
24 type t = Queue.t string;
26 exception Error of string and string;
28 value include_dir x y = Queue.add y x;
30 value fold_load_path x f acc = Queue.fold (fun x y -> f y x) acc x;
32 value mk ?(ocaml_stdlib = True) ?(camlp4_stdlib = True) () =
33 let q = Queue.create () in do {
34 if ocaml_stdlib then include_dir q Camlp4_config.ocaml_standard_library else ();
35 if camlp4_stdlib then do {
36 include_dir q Camlp4_config.camlp4_standard_library;
37 include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Parsers");
38 include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Printers");
39 include_dir q (Filename.concat Camlp4_config.camlp4_standard_library "Camlp4Filters");
45 (* Load files in core *)
47 value find_in_path x name =
48 if not (Filename.is_implicit name) then
49 if Sys.file_exists name then name else raise Not_found
56 let fullname = Filename.concat dir name in
57 if Sys.file_exists fullname then Some fullname else None
59 in match res with [ None -> raise Not_found | Some x -> x ];
62 let _initialized = ref False in
65 if not _initialized.val then
68 Dynlink.allow_unsafe_modules True;
69 _initialized.val := True
73 raise (Error "Camlp4's dynamic loader initialization" (Dynlink.error_message e)) ]
76 try find_in_path _path file with
77 [ Not_found -> raise (Error file "file not found in path") ]
79 try Dynlink.loadfile fname with
80 [ Dynlink.Error e -> raise (Error fname (Dynlink.error_message e)) ]
84 value is_native = Dynlink.is_native;