| author | wenzelm | 
| Sun, 27 Oct 2024 12:54:58 +0100 | |
| changeset 81277 | 0eb96012d416 | 
| parent 78764 | a3dcae9a2ebe | 
| permissions | -rw-r--r-- | 
| 62355 | 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 | 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 | 9  | 
val position_of_polyml_location: ML_Compiler0.polyml_location -> Position.T  | 
| 62516 | 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  | 
| 78679 | 12  | 
val identify: Properties.T -> exn -> exn  | 
13  | 
val the_serial: exn -> int  | 
|
14  | 
val ord: exn ord  | 
|
| 
50911
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
15  | 
end;  | 
| 
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
16  | 
|
| 
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
17  | 
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
 | 
18  | 
struct  | 
| 
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
19  | 
|
| 
56303
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
50911 
diff
changeset
 | 
20  | 
(* source locations *)  | 
| 
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
50911 
diff
changeset
 | 
21  | 
|
| 62821 | 22  | 
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
 | 
23  | 
(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
 | 
24  | 
[] => []  | 
| 
58714
 
ca0b7d7cc9a3
suppress special Poly/ML location inBasis (see $ML_SOURCES/mlsource/MLCompiler/STRUCT_VALS.ML);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
25  | 
| [XML.Text file] =>  | 
| 
 
ca0b7d7cc9a3
suppress special Poly/ML location inBasis (see $ML_SOURCES/mlsource/MLCompiler/STRUCT_VALS.ML);
 
wenzelm 
parents: 
56303 
diff
changeset
 | 
26  | 
if file = "Standard Basis" then []  | 
| 62468 | 27  | 
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
 | 
28  | 
| 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
 | 
29  | 
|
| 62821 | 30  | 
fun position_of_polyml_location loc =  | 
| 77776 | 31  | 
Position.of_props  | 
| 
62387
 
ad3eb2889f9a
support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
 
wenzelm 
parents: 
62355 
diff
changeset
 | 
32  | 
   {line = FixedInt.toInt (#startLine loc),
 | 
| 
 
ad3eb2889f9a
support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
 
wenzelm 
parents: 
62355 
diff
changeset
 | 
33  | 
offset = FixedInt.toInt (#startPosition loc),  | 
| 
 
ad3eb2889f9a
support for polyml-git ec49a49972c5 (branch FixedPrecisionInt);
 
wenzelm 
parents: 
62355 
diff
changeset
 | 
34  | 
end_offset = FixedInt.toInt (#endPosition loc),  | 
| 62821 | 35  | 
props = props_of_polyml_location loc};  | 
| 62516 | 36  | 
|
37  | 
fun position exn =  | 
|
| 62821 | 38  | 
(case Exn.polyml_location exn of  | 
| 62516 | 39  | 
NONE => Position.none  | 
| 62821 | 40  | 
| 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
 | 
41  | 
|
| 
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
50911 
diff
changeset
 | 
42  | 
|
| 
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
50911 
diff
changeset
 | 
43  | 
(* exception properties *)  | 
| 
 
4cc3f4db3447
clarified Isabelle/ML bootstrap, such that Execution does not require ML_Compiler;
 
wenzelm 
parents: 
50911 
diff
changeset
 | 
44  | 
|
| 
50911
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
45  | 
fun get exn =  | 
| 62821 | 46  | 
(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
 | 
47  | 
NONE => []  | 
| 62821 | 48  | 
| 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
 | 
49  | 
|
| 
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
50  | 
fun update entries exn =  | 
| 78680 | 51  | 
let  | 
52  | 
val loc =  | 
|
53  | 
      the_default {file = "", startLine = 0, endLine = 0, startPosition = 0, endPosition = 0}
 | 
|
54  | 
(Exn.polyml_location exn);  | 
|
55  | 
val props = props_of_polyml_location loc;  | 
|
56  | 
val props' = fold Properties.put entries props;  | 
|
57  | 
in  | 
|
58  | 
if props = props' then exn  | 
|
59  | 
else  | 
|
60  | 
let  | 
|
61  | 
val loc' =  | 
|
62  | 
          {file = YXML.string_of_body (XML.Encode.properties props'),
 | 
|
63  | 
startLine = #startLine loc, endLine = #endLine loc,  | 
|
64  | 
startPosition = #startPosition loc, endPosition = #endPosition loc};  | 
|
65  | 
in  | 
|
| 78720 | 66  | 
Thread_Attributes.uninterruptible_body (fn _ =>  | 
67  | 
PolyML.raiseWithLocation (exn, loc') handle exn' => exn')  | 
|
| 78680 | 68  | 
end  | 
69  | 
end;  | 
|
| 
50911
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
70  | 
|
| 78679 | 71  | 
|
72  | 
(* identification via serial numbers *)  | 
|
73  | 
||
74  | 
fun identify default_props exn =  | 
|
| 
78764
 
a3dcae9a2ebe
distinguish proper interrupts from Poly/ML RTS breakdown;
 
wenzelm 
parents: 
78720 
diff
changeset
 | 
75  | 
if Exn.is_interrupt_proper exn then exn  | 
| 78680 | 76  | 
else  | 
77  | 
let  | 
|
78  | 
val props = get exn;  | 
|
79  | 
val update_serial =  | 
|
80  | 
if Properties.defined props Markup.serialN then []  | 
|
81  | 
else [(Markup.serialN, serial_string ())];  | 
|
82  | 
val update_props = filter_out (Properties.defined props o #1) default_props;  | 
|
83  | 
in update (update_serial @ update_props) exn end;  | 
|
| 78679 | 84  | 
|
85  | 
fun the_serial exn =  | 
|
86  | 
Value.parse_int (the (Properties.get (get exn) Markup.serialN));  | 
|
87  | 
||
88  | 
val ord = rev_order o int_ord o apply2 the_serial;  | 
|
89  | 
||
| 
50911
 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 
wenzelm 
parents:  
diff
changeset
 | 
90  | 
end;  |