diff --git a/generator/main.ml b/generator/main.ml index f3a2e7d6a1a4fd09a2fd27d91f3f793072cd77e4..b6dde0e1ec4a45eecbf87f29288ab4cb080b7d3c 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -1,4 +1,3 @@ - open Params open Format open Mytools @@ -12,6 +11,7 @@ open Mytools (*#########################################################################*) let ppf = Format.std_formatter +let stdlib_path = ref "stdlib_ml" (* err_formatter *) @@ -21,18 +21,21 @@ let ppf = Format.std_formatter let tool_name = "ml2js" +(** Configures the compilers load paths from the commandline and stdlib *) +(* FIXME: Relative stdlib dir should be absolute or findlib derived + * we're manually specified using -I for now... *) let init_path () = - Config.load_path := - "stdlib_ml" :: List.rev (Config.standard_library :: !Clflags.include_dirs); + (* Compmisc.init_path false; (* to use this, lots of parameters need tweaking *)*) + Config.load_path := "" :: List.rev_append !Clflags.include_dirs [!stdlib_path]; Env.reset_cache () (** Return the initial environment in which compilation proceeds. *) let initial_env () = - try - let env = Env.initial_unsafe_string in - Env.open_pers_signature "Stdlib" env - with Not_found -> - Misc.fatal_error "cannot open stdlib" + Clflags.nopervasives := true; + (* Stdlib module name, instead of Pervasives *) + add_to_list Compenv.implicit_modules "Stdlib"; + Compmisc.initial_env () + (** Analysis of an implementation file. * ppf: error printer @@ -43,8 +46,8 @@ let process_implementation_file ppf sourcefile oprefix = init_path (); let modulename = Compenv.module_of_filename ppf sourcefile oprefix in Env.set_unit_name modulename; - let env = initial_env () in try + let env = initial_env () in let parsetree = Pparse.parse_implementation ~tool_name ppf sourcefile in if !Clflags.dump_source then fprintf ppf "%a@." Pprintast.structure parsetree; let typing = Typemod.type_implementation sourcefile oprefix modulename env parsetree in @@ -59,7 +62,8 @@ let _ = let files = ref [] in Arg.parse - [ ("-I", Arg.String (add_to_list Clflags.include_dirs), "includes a directory where to look for interface files"); + [ ("-stdlib", Arg.Set_string stdlib_path, "path to look for Stdlib (defaults to 'stdlib_ml')"); + ("-I", Arg.String (add_to_list Clflags.include_dirs), "includes a directory where to look for interface files"); ("-o", Arg.String (fun s -> Clflags.output_name := Some s), "set the output file"); ("-debug", Arg.Set debug, "trace the various steps"); ("-dsource", Arg.Set Clflags.dump_source, "dump source after ppx"); diff --git a/generator/mytools.ml b/generator/mytools.ml index ac221d144b2f36812dbdb4b136c98981354b87cb..3f41fc528bd46d67aa79d71f53182124cf3d2c36 100644 --- a/generator/mytools.ml +++ b/generator/mytools.ml @@ -119,6 +119,8 @@ let list_split3 l = let l3 = List.map (fun (_,_,x) -> x) l in (l1,l2,l3) +let add_to_list li s = + li := s :: !li (**************************************************************) (** String manipulation functions *) diff --git a/generator/params.ml b/generator/params.ml index 565d948b600c3d39ca88f3fa90db53f54e4c48e4..db41f336e2f798c1f6cb441d220e73fb15c9ffc4 100644 --- a/generator/params.ml +++ b/generator/params.ml @@ -2,9 +2,6 @@ let debug = ref false let (~~) f x y = f y x -let add_to_list li s = - li := s :: !li - (****************************************************************) (* MODES *)