src/Pure/ML-Systems/polyml_common.ML
author wenzelm
Sun, 20 Mar 2011 21:28:11 +0100
changeset 42012 2c3fe3cbebae
parent 41718 05514b09bb4b
child 42288 2074b31650e6
permissions -rw-r--r--
structure Timing: covers former start_timing/end_timing and Output.timeit etc; explicit Timing.message function; eliminated Output.timing flag, cf. Toplevel.timing; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/polyml_common.ML
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
     2
31308
3fd52453ae81 discontinued support for Poly/ML 4.x versions;
wenzelm
parents: 30672
diff changeset
     3
Compatibility file for Poly/ML -- common part for 5.x.
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
     4
*)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
     5
41352
87adb55fb0fb make SML/NJ and Poly/ML agree on the type of "before";
wenzelm
parents: 40748
diff changeset
     6
fun op before (a, _: unit) = a;
87adb55fb0fb make SML/NJ and Poly/ML agree on the type of "before";
wenzelm
parents: 40748
diff changeset
     7
28443
de653f1ad78b more robust treatment of Interrupt (cf. exn.ML);
wenzelm
parents: 28416
diff changeset
     8
exception Interrupt = SML90.Interrupt;
de653f1ad78b more robust treatment of Interrupt (cf. exn.ML);
wenzelm
parents: 28416
diff changeset
     9
34136
3dcb46ae6185 added basic library -- Scala version;
wenzelm
parents: 33213
diff changeset
    10
use "General/exn.ML";
36876
1abc27d6c362 conditional structure SingleAssignment;
wenzelm
parents: 36162
diff changeset
    11
1abc27d6c362 conditional structure SingleAssignment;
wenzelm
parents: 36162
diff changeset
    12
if List.exists (fn s => s = "SingleAssignment") (PolyML.Compiler.structureNames ())
1abc27d6c362 conditional structure SingleAssignment;
wenzelm
parents: 36162
diff changeset
    13
then ()
1abc27d6c362 conditional structure SingleAssignment;
wenzelm
parents: 36162
diff changeset
    14
else use "ML-Systems/single_assignment_polyml.ML";
1abc27d6c362 conditional structure SingleAssignment;
wenzelm
parents: 36162
diff changeset
    15
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    16
use "ML-Systems/multithreading.ML";
30619
0226c07352db added generic ML_Pretty interface;
wenzelm
parents: 30187
diff changeset
    17
use "ML-Systems/ml_pretty.ML";
30672
beaadd5af500 more systematic type use_context, with particular values ML_Parse.global_context and ML_Context.local_context;
wenzelm
parents: 30625
diff changeset
    18
use "ML-Systems/use_context.ML";
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    19
42012
2c3fe3cbebae structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents: 41718
diff changeset
    20
val seconds = Time.fromReal;
2c3fe3cbebae structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents: 41718
diff changeset
    21
2c3fe3cbebae structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents: 41718
diff changeset
    22
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    23
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    24
(** ML system and platform related **)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    25
26474
94735cff132c added forget_structure;
wenzelm
parents: 26380
diff changeset
    26
val forget_structure = PolyML.Compiler.forgetStructure;
94735cff132c added forget_structure;
wenzelm
parents: 26380
diff changeset
    27
33213
1b550123f133 forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents: 33060
diff changeset
    28
val _ = PolyML.Compiler.forgetValue "isSome";
1b550123f133 forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents: 33060
diff changeset
    29
val _ = PolyML.Compiler.forgetValue "getOpt";
1b550123f133 forget old some old option stuff from NJ -- superceded by material in Pure/General/basics.ML;
wenzelm
parents: 33060
diff changeset
    30
val _ = PolyML.Compiler.forgetValue "valOf";
33004
715566791eb0 always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents: 32776
diff changeset
    31
val _ = PolyML.Compiler.forgetValue "foldl";
715566791eb0 always qualify NJ's old List.foldl/foldr in Isabelle/ML;
wenzelm
parents: 32776
diff changeset
    32
val _ = PolyML.Compiler.forgetValue "foldr";
31324
3ffa005c7701 removed print function from global ML name space, to reduce risk of surprises;
wenzelm
parents: 31319
diff changeset
    33
val _ = PolyML.Compiler.forgetValue "print";
40627
becf5d5187cc renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents: 40393
diff changeset
    34
val _ = PolyML.Compiler.forgetValue "explode";
31324
3ffa005c7701 removed print function from global ML name space, to reduce risk of surprises;
wenzelm
parents: 31319
diff changeset
    35
26474
94735cff132c added forget_structure;
wenzelm
parents: 26380
diff changeset
    36
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    37
(* Compiler options *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    38
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    39
val ml_system_fix_ints = false;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    40
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    41
PolyML.Compiler.printInAlphabeticalOrder := false;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    42
PolyML.Compiler.maxInlineSize := 80;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    43
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    44
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    45
(* old Poly/ML emulation *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    46
31319
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    47
fun quit () = exit 0;
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    48
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    49
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    50
(* restore old-style character / string functions *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    51
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    52
val ord = SML90.ord;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    53
val chr = SML90.chr;
40627
becf5d5187cc renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents: 40393
diff changeset
    54
val raw_explode = SML90.explode;
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    55
val implode = SML90.implode;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    56
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    57
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    58
(* prompts *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    59
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    60
fun ml_prompts p1 p2 = (PolyML.Compiler.prompt1 := p1; PolyML.Compiler.prompt2 := p2);
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    61
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    62
36162
0bd034a80a9a added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents: 35014
diff changeset
    63
(* toplevel printing *)
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    64
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    65
local
39616
8052101883c3 renamed setmp_noncritical to Unsynchronized.setmp to emphasize its meaning;
wenzelm
parents: 39585
diff changeset
    66
  val depth = ref 10;
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    67
in
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    68
  fun get_print_depth () = ! depth;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    69
  fun print_depth n = (depth := n; PolyML.print_depth n);
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    70
end;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    71
31319
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    72
val error_depth = PolyML.error_depth;
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    73
36162
0bd034a80a9a added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents: 35014
diff changeset
    74
val ml_make_string = "PolyML.makestring";
0bd034a80a9a added ML antiquotation @{make_string}, which produces proper pretty printed version in Poly/ML 5.3.0 or later;
wenzelm
parents: 35014
diff changeset
    75
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    76
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    77
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    78
(** OS related **)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    79
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    80
(* current directory *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    81
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    82
val cd = OS.FileSys.chDir;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    83
val pwd = OS.FileSys.getDir;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    84
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    85
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    86
(* getenv *)
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    87
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    88
fun getenv var =
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    89
  (case OS.Process.getEnv var of
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    90
    NONE => ""
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    91
  | SOME txt => txt);
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    92
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
    93
31319
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    94
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    95
(** Runtime system **)
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    96
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    97
val exception_trace = PolyML.exception_trace;
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    98
val timing = PolyML.timing;
6974449ddea9 no longer open PolyML -- to avoid surprises within the global name space;
wenzelm
parents: 31308
diff changeset
    99
val profiling = PolyML.profiling;
26215
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   100
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   101
fun profile 0 f x = f x
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   102
  | profile n f x =
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   103
      let
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   104
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler n;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   105
        val res = Exn.capture f x;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   106
        val _ = RunCall.run_call1 RuntimeCalls.POLY_SYS_profiler 0;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   107
      in Exn.release res end;
94d32a7cd0fb rearrangements to make latest Poly/ML the default, not old 4.x;
wenzelm
parents:
diff changeset
   108