Skip to content
This repository
tree: 7eeea769d5
Fetching contributors…

Cannot retrieve contributors at this time

file 290 lines (234 sloc) 8.37 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290

<<common.mli>>=
(*###########################################################################*)
(* Globals *)
(*###########################################################################*)
<<common.mli globals>>

(*###########################################################################*)
(* Basic features *)
(*###########################################################################*)
<<common.mli basic features>>

(*###########################################################################*)
(* Basic types *)
(*###########################################################################*)
<<common.mli for basic types>>

(*###########################################################################*)
(* Collection-like types *)
(*###########################################################################*)
<<common.mli for collection types>>

(*###########################################################################*)
(* Misc functions *)
(*###########################################################################*)
<<common.mli misc>>

(*###########################################################################*)
(* Postlude *)
(*###########################################################################*)
<<common.mli postlude>>
@

\begin{verbatim}
(* Some conventions:
 *
 * When I have some _xxx variables before some functions, it's
 * because I want to show that those functions internally use a global
 * variable. That does not mean I want people to modify this global.
 * In fact they are kind of private, but I still want to show them.
 * Maybe one day OCaml will have an effect type system so I don't need this.
 *
 * The variables that are called _init_xxx show the internal init
 * side effect of the module (like static var trick used in C/C++)
 *
 * Why not split the functionnalities of this file in different files ?
 * Because when I write ocaml script I want simply to load one
 * file, common.ml, and that's it. Cf common_extra.ml for more on this.
 *)
\end{verbatim}


<<common.mli globals>>=
(*****************************************************************************)
(* Flags *)
(*****************************************************************************)
<<common.mli globals flags>>

(*****************************************************************************)
(* Flags and actions *)
(*****************************************************************************)
(* cf poslude *)

(*****************************************************************************)
(* Misc/test *)
(*****************************************************************************)
<<common.mli misc/test>>

@





<<common.mli globals flags>>=
(* see the corresponding section for the use of those flags. See also
 * the "Flags and actions" section at the end of this file.
 *)

(* if set then will not do certain finalize so faster to go back in replay *)
val debugger : bool ref

type prof = PALL | PNONE | PSOME of string list
val profile : prof ref
val show_trace_profile : bool ref


val verbose_level : int ref

(* forbid pr2_once to do the once "optimisation" *)
val disable_pr2_once : bool ref



(* works with new_temp_file *)
val save_tmp_files : bool ref
@



<<common.mli globals>>=
(*****************************************************************************)
(* Module side effect *)
(*****************************************************************************)
(*
 * I define a few unit tests via some let _ = example (... = ...).
 * I also initialize the random seed, cf _init_random .
 * I also set Gc.stack_size, cf _init_gc_stack .
*)
@



<<common.mli globals>>=
(*****************************************************************************)
(* Semi globals *)
(*****************************************************************************)
(* cf the _xxx variables in this file *)
@


% need put after cmdline_options
<<common.mli postlude>>=
val cmdline_flags_devel : unit -> cmdline_options
val cmdline_flags_verbose : unit -> cmdline_options
val cmdline_flags_other : unit -> cmdline_options

val cmdline_actions : unit -> cmdline_actions
@

<<common.ml cmdline>>=

(* I put it inside a func as it can help to give a chance to
 * change the globals before getting the options as some
 * options sometimes may want to show the default value.
 *)
let cmdline_flags_devel () =
  [
    "-debugger", Arg.Set debugger ,
    " option to set if launched inside ocamldebug";
    "-profile", Arg.Unit (fun () -> profile := PALL),
    " gather timing information about important functions";
  ]
let cmdline_flags_verbose () =
  [
    "-verbose_level", Arg.Set_int verbose_level,
    " <int> guess what";
    "-disable_pr2_once", Arg.Set disable_pr2_once,
    " to print more messages";
    "-show_trace_profile", Arg.Set show_trace_profile,
    " show trace";
  ]

let cmdline_flags_other () =
  [
    "-nocheck_stack", Arg.Clear _check_stack,
    " ";
    "-batch_mode", Arg.Set _batch_mode,
    " no interactivity";
    "-keep_tmp_files", Arg.Set save_tmp_files,
    " ";
  ]

(* potentially other common options but not yet integrated:
   
  "-timeout", Arg.Set_int timeout,
  " <sec> interrupt LFS or buggy external plugins";

  (* can't be factorized because of the $ cvs stuff, we want the date
   * of the main.ml file, not common.ml
   *)
  "-version", Arg.Unit (fun () ->
    pr2 "version: _dollar_Date: 2008/06/14 00:54:22 _dollar_";
    raise (Common.UnixExit 0)
    ),
  " guess what";

  "-shorthelp", Arg.Unit (fun () ->
    !short_usage_func();
    raise (Common.UnixExit 0)
  ),
  " see short list of options";
  "-longhelp", Arg.Unit (fun () ->
    !long_usage_func();
    raise (Common.UnixExit 0)
    ),
  "-help", Arg.Unit (fun () ->
    !long_usage_func();
    raise (Common.UnixExit 0)
  ),
  " ";
  "--help", Arg.Unit (fun () ->
    !long_usage_func();
    raise (Common.UnixExit 0)
  ),
  " ";

*)

let cmdline_actions () =
  [
    "-test_check_stack", " <limit>",
    mk_action_1_arg test_check_stack_size;
  ]

@



<<common.mli misc/test>>=
val generic_print : 'a -> string -> string

class ['a] olist :
  'a list ->
  object
    val xs : 'a list
    method fold : ('b -> 'a -> 'b) -> 'b -> 'b
    method view : 'a list
  end

val typing_sux_test : unit -> unit
@

\begin{verbatim}

(*****************************************************************************)
(* Notes *)
(*****************************************************************************)



(* ---------------------------------------------------------------------- *)
(* Maybe could split common.ml and use include tricks as in ofullcommon.ml or
 * Jane Street core lib. But then harder to bundle simple scripts like my
 * make_full_linux_kernel.ml because would then need to pass all the files
 * either to ocamlc or either to some #load. Also as the code of many
 * functions depends on other functions from this common, it would
 * be tedious to add those dependencies. Here simpler (have just the
 * pb of the Prelude, but it's a small problem).
 *
 * pixel means code from Pascal Rigaux
 * julia means code from Julia Lawall
 *)
(* ---------------------------------------------------------------------- *)

(*****************************************************************************)
(* We use *)
(*****************************************************************************)
(*
 * modules:
 * - Pervasives, of course
 * - List
 * - Str
 * - Hashtbl
 * - Format
 * - Buffer
 * - Unix and Sys
 * - Arg
 *
 * functions:
 * - =, <=, max min, abs, ...
 * - List.rev, List.mem, List.partition,
 * - List.fold*, List.concat, ...
 * - Str.global_replace
 * - Filename.is_relative
 * - String.uppercase, String.lowercase
 *
 *
 * The Format library allows to hide passing an indent_level variable.
 * You use as usual the print_string function except that there is
 * this automatic indent_level variable handled for you (and maybe
 * more services). src: julia in coccinelle unparse_cocci.
 *
 * Extra packages
 * - ocamlbdb
 * - ocamlgtk, and gtksourceview
 * - ocamlgl
 * - ocamlpython
 * - ocamlagrep
 * - ocamlfuse
 * - ocamlmpi
 * - ocamlcalendar
 *
 * - pcre
 * - sdl
 *
 * Many functions in this file were inspired by Haskell or Lisp librairies.
 *)

\end{verbatim}
Something went wrong with that request. Please try again.