src/Pure/ML/ml_init.ML
author wenzelm
Thu, 23 Jan 2025 22:19:30 +0100
changeset 81960 326ecfc079a6
parent 80853 a34eca8caccb
permissions -rw-r--r--
support for @{instantiate (no_beta) ...};
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67205
06c91eac25f2 clarified file name;
wenzelm
parents: 63925
diff changeset
     1
(*  Title:      Pure/ML/ml_init.ML
62818
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     3
67205
06c91eac25f2 clarified file name;
wenzelm
parents: 63925
diff changeset
     4
Initial ML environment.
62818
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     5
*)
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     6
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     7
val seconds = Time.fromReal;
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     8
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
     9
val _ =
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    10
  List.app ML_Name_Space.forget_val
78740
45ff003d337c discontinue obsolete "Interrupt" constructor (NB: catch-all pattern produces ML compiler error);
wenzelm
parents: 78650
diff changeset
    11
    ["isSome", "getOpt", "valOf", "foldl", "foldr", "print", "explode", "concat", "Interrupt"];
62818
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    12
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    13
val ord = SML90.ord;
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    14
val chr = SML90.chr;
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    15
val raw_explode = SML90.explode;
63925
500646ef617a avoid old SML90;
wenzelm
parents: 62943
diff changeset
    16
val implode = String.concat;
62818
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    17
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    18
val pointer_eq = PolyML.pointerEq;
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    19
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    20
val error_depth = PolyML.error_depth;
2733b240bfea clarified modules;
wenzelm
parents:
diff changeset
    21
62923
3a122e1e352a clarified bootstrap;
wenzelm
parents: 62883
diff changeset
    22
structure Basic_Exn: BASIC_EXN = Exn;
3a122e1e352a clarified bootstrap;
wenzelm
parents: 62883
diff changeset
    23
open Basic_Exn;
67206
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    24
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    25
structure String =
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    26
struct
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    27
  open String;
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    28
  fun substring (s, i, n) =
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    29
    if n = 1 then String.str (String.sub (s, i))
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    30
    else String.substring (s, i, n);
b8f30228a55b minor performance tuning, notably for Library.fold_string etc.;
wenzelm
parents: 67205
diff changeset
    31
end;
75594
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    32
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    33
structure Substring =
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    34
struct
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    35
  open Substring;
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    36
  val empty = full "";
80853
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    37
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    38
local
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    39
  val chars = Vector.tabulate (Char.maxOrd, Substring.full o String.str o Char.chr);
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    40
in
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    41
  fun full str =
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    42
    (case String.size str of
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    43
      0 => empty
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    44
    | 1 => Vector.sub (chars, Char.ord (String.sub (str, 0)))
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    45
    | _ => Substring.full str);
75594
303f885d4a8c clarified signature: more operations;
wenzelm
parents: 73384
diff changeset
    46
end;
80853
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    47
a34eca8caccb minor performance tuning, notably for Bytes.add (e.g. YXML output);
wenzelm
parents: 78740
diff changeset
    48
end;