src/Pure/ML/exn_properties.ML
author wenzelm
Wed, 06 Apr 2016 17:16:30 +0200
changeset 62891 7a11ea5c9626
parent 62821 48c24d0b6d85
child 62923 3a122e1e352a
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62355
00f7618a9f2b clarified file names;
wenzelm
parents: 61138
diff changeset
     1
(*  Title:      Pure/ML/exn_properties.ML
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     3
62355
00f7618a9f2b clarified file names;
wenzelm
parents: 61138
diff changeset
     4
Exception properties.
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     5
*)
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     6
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     7
signature EXN_PROPERTIES =
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
     8
sig
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
     9
  val position_of_polyml_location: ML_Compiler0.polyml_location -> Position.T
62516
5732f1c31566 tuned signature -- clarified modules;
wenzelm
parents: 62468
diff changeset
    10
  val position: exn -> Position.T
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    11
  val get: exn -> Properties.T
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    12
  val update: Properties.entry list -> exn -> exn
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    13
end;
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    14
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    15
structure Exn_Properties: EXN_PROPERTIES =
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    16
struct
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    17
56303
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    18
(* source locations *)
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    19
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    20
fun props_of_polyml_location (loc: ML_Compiler0.polyml_location) =
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    21
  (case YXML.parse_body (#file loc) of
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    22
    [] => []
58714
ca0b7d7cc9a3 suppress special Poly/ML location inBasis (see $ML_SOURCES/mlsource/MLCompiler/STRUCT_VALS.ML);
wenzelm
parents: 56303
diff changeset
    23
  | [XML.Text file] =>
ca0b7d7cc9a3 suppress special Poly/ML location inBasis (see $ML_SOURCES/mlsource/MLCompiler/STRUCT_VALS.ML);
wenzelm
parents: 56303
diff changeset
    24
      if file = "Standard Basis" then []
62468
d97e13e5ea5b clarified modules;
wenzelm
parents: 62387
diff changeset
    25
      else [(Markup.fileN, ML_System.standard_path file)]
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    26
  | body => XML.Decode.properties body);
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    27
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    28
fun position_of_polyml_location loc =
56303
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    29
  Position.make
62387
ad3eb2889f9a support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
wenzelm
parents: 62355
diff changeset
    30
   {line = FixedInt.toInt (#startLine loc),
ad3eb2889f9a support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
wenzelm
parents: 62355
diff changeset
    31
    offset = FixedInt.toInt (#startPosition loc),
ad3eb2889f9a support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
wenzelm
parents: 62355
diff changeset
    32
    end_offset = FixedInt.toInt (#endPosition loc),
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    33
    props = props_of_polyml_location loc};
62516
5732f1c31566 tuned signature -- clarified modules;
wenzelm
parents: 62468
diff changeset
    34
5732f1c31566 tuned signature -- clarified modules;
wenzelm
parents: 62468
diff changeset
    35
fun position exn =
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    36
  (case Exn.polyml_location exn of
62516
5732f1c31566 tuned signature -- clarified modules;
wenzelm
parents: 62468
diff changeset
    37
    NONE => Position.none
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    38
  | SOME loc => position_of_polyml_location loc);
56303
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    39
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    40
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    41
(* exception properties *)
4cc3f4db3447 clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
wenzelm
parents: 50911
diff changeset
    42
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    43
fun get exn =
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    44
  (case Exn.polyml_location exn of
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    45
    NONE => []
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    46
  | SOME loc => props_of_polyml_location loc);
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    47
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    48
fun update entries exn =
62518
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    49
  if Exn.is_interrupt exn then exn
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    50
  else
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    51
    let
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    52
      val loc =
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    53
        the_default {file = "", startLine = 0, endLine = 0, startPosition = 0, endPosition = 0}
62821
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    54
          (Exn.polyml_location exn);
48c24d0b6d85 tuned signature;
wenzelm
parents: 62518
diff changeset
    55
      val props = props_of_polyml_location loc;
62518
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    56
      val props' = fold Properties.put entries props;
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    57
    in
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    58
      if props = props' then exn
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    59
      else
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    60
        let
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    61
          val loc' =
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    62
            {file = YXML.string_of_body (XML.Encode.properties props'),
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    63
              startLine = #startLine loc, endLine = #endLine loc,
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    64
              startPosition = #startPosition loc, endPosition = #endPosition loc};
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    65
        in
62891
7a11ea5c9626 tuned signature;
wenzelm
parents: 62821
diff changeset
    66
          Multithreading.uninterruptible (fn _ => fn () =>
62518
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    67
            PolyML.raiseWithLocation (exn, loc') handle exn' => exn') ()
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    68
        end
b8efcc9edd7b avoid accidental handling of interrupts;
wenzelm
parents: 62516
diff changeset
    69
    end;
50911
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    70
ee7fe4230642 more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
diff changeset
    71
end;