1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
open Clflags
|
|
|
|
|
2011-12-30 08:28:16 -08:00
|
|
|
let usage = "Usage: ocaml <options> <object-files> [script-file [arguments]]\n\
|
|
|
|
options are:"
|
1996-10-24 07:17:48 -07:00
|
|
|
|
2002-02-07 18:56:04 -08:00
|
|
|
let preload_objects = ref []
|
|
|
|
|
|
|
|
let prepare ppf =
|
|
|
|
Toploop.set_paths ();
|
2003-06-30 08:31:06 -07:00
|
|
|
try
|
2010-01-22 04:48:24 -08:00
|
|
|
let res =
|
2003-06-30 08:31:06 -07:00
|
|
|
List.for_all (Topdirs.load_file ppf) (List.rev !preload_objects) in
|
|
|
|
!Toploop.toplevel_startup_hook ();
|
|
|
|
res
|
2002-02-07 18:56:04 -08:00
|
|
|
with x ->
|
|
|
|
try Errors.report_error ppf x; false
|
|
|
|
with x ->
|
|
|
|
Format.fprintf ppf "Uncaught exception: %s\n" (Printexc.to_string x);
|
|
|
|
false
|
1997-07-03 07:32:35 -07:00
|
|
|
|
2011-12-30 08:28:16 -08:00
|
|
|
(* If [name] is "", then the "file" is stdin treated as a script file. *)
|
2002-02-07 18:56:04 -08:00
|
|
|
let file_argument name =
|
|
|
|
let ppf = Format.err_formatter in
|
|
|
|
if Filename.check_suffix name ".cmo" || Filename.check_suffix name ".cma"
|
|
|
|
then preload_objects := name :: !preload_objects
|
2003-05-23 07:44:08 -07:00
|
|
|
else
|
|
|
|
begin
|
|
|
|
let newargs = Array.sub Sys.argv !Arg.current
|
|
|
|
(Array.length Sys.argv - !Arg.current)
|
|
|
|
in
|
|
|
|
if prepare ppf && Toploop.run_script ppf name newargs
|
|
|
|
then exit 0
|
|
|
|
else exit 2
|
|
|
|
end
|
2001-09-06 22:56:31 -07:00
|
|
|
|
2004-11-26 17:04:19 -08:00
|
|
|
let print_version () =
|
2011-04-26 05:16:50 -07:00
|
|
|
Printf.printf "The OCaml toplevel, version %s\n" Sys.ocaml_version;
|
2004-11-26 17:04:19 -08:00
|
|
|
exit 0;
|
|
|
|
;;
|
|
|
|
|
2010-05-20 07:06:29 -07:00
|
|
|
let print_version_num () =
|
|
|
|
Printf.printf "%s\n" Sys.ocaml_version;
|
|
|
|
exit 0;
|
|
|
|
;;
|
|
|
|
|
2010-04-13 03:44:25 -07:00
|
|
|
module Options = Main_args.Make_bytetop_options (struct
|
|
|
|
let set r () = r := true
|
|
|
|
let clear r () = r := false
|
|
|
|
|
2011-12-20 02:35:43 -08:00
|
|
|
let _absname = set Location.absname
|
2010-04-13 03:44:25 -07:00
|
|
|
let _I dir =
|
|
|
|
let dir = Misc.expand_directory Config.standard_library dir in
|
|
|
|
include_dirs := dir :: !include_dirs
|
|
|
|
let _init s = init_file := Some s
|
|
|
|
let _labels = clear classic
|
|
|
|
let _no_app_funct = clear applicative_functors
|
|
|
|
let _noassert = set noassert
|
|
|
|
let _nolabels = set classic
|
|
|
|
let _noprompt = set noprompt
|
2012-01-27 04:48:15 -08:00
|
|
|
let _nopromptcont = set nopromptcont
|
2010-04-13 03:44:25 -07:00
|
|
|
let _nostdlib = set no_std_include
|
2013-01-25 01:12:31 -08:00
|
|
|
let _ppx s = ppx := s :: !ppx
|
2010-04-13 03:44:25 -07:00
|
|
|
let _principal = set principal
|
2013-01-29 06:21:12 -08:00
|
|
|
let _short_paths = clear real_paths
|
2010-04-13 03:44:25 -07:00
|
|
|
let _rectypes = set recursive_types
|
2011-12-30 08:28:16 -08:00
|
|
|
let _stdin () = file_argument ""
|
2010-04-13 03:44:25 -07:00
|
|
|
let _strict_sequence = set strict_sequence
|
|
|
|
let _unsafe = set fast
|
|
|
|
let _version () = print_version ()
|
2010-05-20 07:06:29 -07:00
|
|
|
let _vnum () = print_version_num ()
|
2010-04-13 03:44:25 -07:00
|
|
|
let _w s = Warnings.parse_options false s
|
|
|
|
let _warn_error s = Warnings.parse_options true s
|
2010-05-08 13:11:27 -07:00
|
|
|
let _warn_help = Warnings.help_warnings
|
2010-04-13 03:44:25 -07:00
|
|
|
let _dparsetree = set dump_parsetree
|
2012-12-18 09:19:53 -08:00
|
|
|
let _dtypedtree = set dump_typedtree
|
2012-10-17 09:09:38 -07:00
|
|
|
let _dsource = set dump_source
|
2010-04-13 03:44:25 -07:00
|
|
|
let _drawlambda = set dump_rawlambda
|
|
|
|
let _dlambda = set dump_lambda
|
|
|
|
let _dinstr = set dump_instr
|
|
|
|
|
|
|
|
let anonymous s = file_argument s
|
|
|
|
end);;
|
1999-11-29 11:04:45 -08:00
|
|
|
|
2010-04-13 03:44:25 -07:00
|
|
|
|
|
|
|
let main () =
|
|
|
|
Arg.parse Options.list file_argument usage;
|
2002-02-07 18:56:04 -08:00
|
|
|
if not (prepare Format.err_formatter) then exit 2;
|
2000-04-10 07:59:29 -07:00
|
|
|
Toploop.loop Format.std_formatter
|