src/HOL/Bali/State.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 41778 5f79a9e42507
child 55417 01fbfb60c33e
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12857
a4386cc9b1c3 tuned header;
wenzelm
parents: 12854
diff changeset
     1
(*  Title:      HOL/Bali/State.thy
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     2
    Author:     David von Oheimb
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     3
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     4
header {* State for evaluation of Java expressions and statements *}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     5
33965
f57c11db4ad4 Inl and Inr now with authentic syntax
haftmann
parents: 32960
diff changeset
     6
theory State
f57c11db4ad4 Inl and Inr now with authentic syntax
haftmann
parents: 32960
diff changeset
     7
imports DeclConcepts
f57c11db4ad4 Inl and Inr now with authentic syntax
haftmann
parents: 32960
diff changeset
     8
begin
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     9
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    10
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    11
design issues:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    12
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    13
\item all kinds of objects (class instances, arrays, and class objects)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    14
  are handeled via a general object abstraction
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    15
\item the heap and the map for class objects are combined into a single table
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    16
  @{text "(recall (loc, obj) table \<times> (qtname, obj) table  ~=  (loc + qtname, obj) table)"}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    17
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    18
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    19
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    20
section "objects"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    21
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
    22
datatype  obj_tag =     --{* tag for generic object   *}
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
    23
          CInst qtname  --{* class instance           *}
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
    24
        | Arr  ty int   --{* array with component type and length *}
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
    25
    --{* | CStat qtname   the tag is irrelevant for a class object,
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
    26
                           i.e. the static fields of a class,
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
    27
                           since its type is given already by the reference to 
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
    28
                           it (see below) *}
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    29
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
    30
type_synonym vn = "fspec + int"                 --{* variable name      *}
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
    31
record  obj  = 
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
    32
          tag :: "obj_tag"                      --{* generalized object *}
31127
b63c3f6bd3be values is now a keyword
haftmann
parents: 30235
diff changeset
    33
          "values" :: "(vn, val) table"      
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    34
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    35
translations 
35431
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
    36
  (type) "fspec" <= (type) "vname \<times> qtname" 
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
    37
  (type) "vn"    <= (type) "fspec + int"
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
    38
  (type) "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option\<rparr>"
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
    39
  (type) "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option,\<dots>::'a\<rparr>"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    40
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    41
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    42
  the_Arr :: "obj option \<Rightarrow> ty \<times> int \<times> (vn, val) table"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    43
  where "the_Arr obj = (SOME (T,k,t). obj = Some \<lparr>tag=Arr T k,values=t\<rparr>)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    44
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    45
lemma the_Arr_Arr [simp]: "the_Arr (Some \<lparr>tag=Arr T k,values=cs\<rparr>) = (T,k,cs)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    46
apply (auto simp: the_Arr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    47
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    48
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    49
lemma the_Arr_Arr1 [simp,intro,dest]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    50
 "\<lbrakk>tag obj = Arr T k\<rbrakk> \<Longrightarrow> the_Arr (Some obj) = (T,k,values obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    51
apply (auto simp add: the_Arr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    52
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    53
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    54
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    55
  upd_obj :: "vn \<Rightarrow> val \<Rightarrow> obj \<Rightarrow> obj"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    56
  where "upd_obj n v = (\<lambda>obj. obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    57
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    58
lemma upd_obj_def2 [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    59
  "upd_obj n v obj = obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    60
apply (auto simp: upd_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    61
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    62
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    63
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    64
  obj_ty :: "obj \<Rightarrow> ty" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    65
  "obj_ty obj = (case tag obj of 
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    66
                  CInst C \<Rightarrow> Class C 
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
    67
                | Arr T k \<Rightarrow> T.[])"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    68
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    69
lemma obj_ty_eq [intro!]: "obj_ty \<lparr>tag=oi,values=x\<rparr> = obj_ty \<lparr>tag=oi,values=y\<rparr>" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    70
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    71
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    72
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    73
lemma obj_ty_eq1 [intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    74
  "tag obj = tag obj' \<Longrightarrow> obj_ty obj = obj_ty obj'" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    75
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    76
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    77
lemma obj_ty_cong [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    78
  "obj_ty (obj \<lparr>values:=vs\<rparr>) = obj_ty obj" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    79
by auto
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
    80
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    81
lemma obj_ty_CInst [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    82
 "obj_ty \<lparr>tag=CInst C,values=vs\<rparr> = Class C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    83
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    84
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    85
lemma obj_ty_CInst1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    86
 "\<lbrakk>tag obj = CInst C\<rbrakk> \<Longrightarrow> obj_ty obj = Class C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    87
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    88
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    89
lemma obj_ty_Arr [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    90
 "obj_ty \<lparr>tag=Arr T i,values=vs\<rparr> = T.[]"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    91
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    92
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    93
lemma obj_ty_Arr1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    94
 "\<lbrakk>tag obj = Arr T i\<rbrakk> \<Longrightarrow> obj_ty obj = T.[]"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    95
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    96
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    97
lemma obj_ty_widenD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    98
 "G\<turnstile>obj_ty obj\<preceq>RefT t \<Longrightarrow> (\<exists>C. tag obj = CInst C) \<or> (\<exists>T k. tag obj = Arr T k)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    99
apply (unfold obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   100
apply (auto split add: obj_tag.split_asm)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   101
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   102
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   103
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   104
  obj_class :: "obj \<Rightarrow> qtname" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   105
  "obj_class obj = (case tag obj of 
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   106
                     CInst C \<Rightarrow> C 
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   107
                   | Arr T k \<Rightarrow> Object)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   108
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   109
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   110
lemma obj_class_CInst [simp]: "obj_class \<lparr>tag=CInst C,values=vs\<rparr> = C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   111
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   112
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   113
lemma obj_class_CInst1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   114
  "tag obj = CInst C \<Longrightarrow> obj_class obj = C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   115
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   116
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   117
lemma obj_class_Arr [simp]: "obj_class \<lparr>tag=Arr T k,values=vs\<rparr> = Object" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   118
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   119
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   120
lemma obj_class_Arr1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   121
 "tag obj = Arr T k \<Longrightarrow> obj_class obj = Object" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   122
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   123
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   124
lemma obj_ty_obj_class: "G\<turnstile>obj_ty obj\<preceq> Class statC = G\<turnstile>obj_class obj \<preceq>\<^sub>C statC"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   125
apply (case_tac "tag obj")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   126
apply (auto simp add: obj_ty_def obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   127
apply (case_tac "statC = Object")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   128
apply (auto dest: widen_Array_Class)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   129
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   130
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   131
section "object references"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   132
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
   133
type_synonym oref = "loc + qtname"         --{* generalized object reference *}
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   134
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   135
  Heap  :: "loc   \<Rightarrow> oref"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   136
  Stat  :: "qtname \<Rightarrow> oref"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   137
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   138
translations
33965
f57c11db4ad4 Inl and Inr now with authentic syntax
haftmann
parents: 32960
diff changeset
   139
  "Heap" => "CONST Inl"
f57c11db4ad4 Inl and Inr now with authentic syntax
haftmann
parents: 32960
diff changeset
   140
  "Stat" => "CONST Inr"
35431
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   141
  (type) "oref" <= (type) "loc + qtname"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   142
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   143
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   144
  fields_table :: "prog \<Rightarrow> qtname \<Rightarrow> (fspec \<Rightarrow> field \<Rightarrow> bool)  \<Rightarrow> (fspec, ty) table" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   145
  "fields_table G C P =
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   146
    Option.map type \<circ> table_of (filter (split P) (DeclConcepts.fields G C))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   147
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   148
lemma fields_table_SomeI: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   149
"\<lbrakk>table_of (DeclConcepts.fields G C) n = Some f; P n f\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   150
 \<Longrightarrow> fields_table G C P n = Some (type f)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   151
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   152
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   153
apply (rule exI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   154
apply (rule conjI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   155
apply (erule map_of_filter_in)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   156
apply assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   157
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   158
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   159
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   160
(* unused *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   161
lemma fields_table_SomeD': "fields_table G C P fn = Some T \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   162
  \<exists>f. (fn,f)\<in>set(DeclConcepts.fields G C) \<and> type f = T"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   163
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   164
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   165
apply (drule map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   166
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   167
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   168
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   169
lemma fields_table_SomeD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   170
"\<lbrakk>fields_table G C P fn = Some T; unique (DeclConcepts.fields G C)\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   171
  \<exists>f. table_of (DeclConcepts.fields G C) fn = Some f \<and> type f = T"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   172
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   173
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   174
apply (rule exI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   175
apply (rule conjI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   176
apply (erule table_of_filter_unique_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   177
apply assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   178
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   179
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   180
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   181
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   182
  in_bounds :: "int \<Rightarrow> int \<Rightarrow> bool" ("(_/ in'_bounds _)" [50, 51] 50)
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   183
  where "i in_bounds k = (0 \<le> i \<and> i < k)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   184
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   185
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   186
  arr_comps :: "'a \<Rightarrow> int \<Rightarrow> int \<Rightarrow> 'a option"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   187
  where "arr_comps T k = (\<lambda>i. if i in_bounds k then Some T else None)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   188
  
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   189
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   190
  var_tys :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> (vn, ty) table" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   191
  "var_tys G oi r =
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   192
    (case r of 
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   193
      Heap a \<Rightarrow> (case oi of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   194
                   CInst C \<Rightarrow> fields_table G C (\<lambda>n f. \<not>static f) (+) empty
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   195
                 | Arr T k \<Rightarrow> empty (+) arr_comps T k)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   196
    | Stat C \<Rightarrow> fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) 
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   197
                (+) empty)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   198
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   199
lemma var_tys_Some_eq: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   200
 "var_tys G oi r n = Some T 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   201
  = (case r of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   202
       Inl a \<Rightarrow> (case oi of  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   203
                   CInst C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> fields_table G C (\<lambda>n f. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   204
                               \<not>static f) nt = Some T)  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   205
                 | Arr t k \<Rightarrow> (\<exists> i. n = Inr i  \<and> i in_bounds k \<and> t = T))  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   206
     | Inr C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   207
                 fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) nt 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   208
                  = Some T))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   209
apply (unfold var_tys_def arr_comps_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   210
apply (force split add: sum.split_asm sum.split obj_tag.split)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   211
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   212
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   213
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   214
section "stores"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   215
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
   216
type_synonym globs               --{* global variables: heap and static variables *}
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
   217
        = "(oref , obj) table"
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
   218
type_synonym heap
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
   219
        = "(loc  , obj) table"
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
   220
(* type_synonym locals                   
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
   221
        = "(lname, val) table" *) (* defined in Value.thy local variables *)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   222
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   223
translations
35431
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   224
 (type) "globs"  <= (type) "(oref , obj) table"
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   225
 (type) "heap"   <= (type) "(loc  , obj) table"
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   226
(*  (type) "locals" <= (type) "(lname, val) table" *)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   227
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   228
datatype st = (* pure state, i.e. contents of all variables *)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
   229
         st globs locals
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   230
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   231
subsection "access"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   232
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   233
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   234
  globs :: "st \<Rightarrow> globs"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   235
  where "globs = st_case (\<lambda>g l. g)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   236
  
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   237
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   238
  locals :: "st \<Rightarrow> locals"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   239
  where "locals = st_case (\<lambda>g l. l)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   240
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   241
definition heap :: "st \<Rightarrow> heap" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   242
 "heap s = globs s \<circ> Heap"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   243
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   244
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   245
lemma globs_def2 [simp]: " globs (st g l) = g"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   246
by (simp add: globs_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   247
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   248
lemma locals_def2 [simp]: "locals (st g l) = l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   249
by (simp add: locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   250
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   251
lemma heap_def2 [simp]:  "heap s a=globs s (Heap a)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   252
by (simp add: heap_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   253
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   254
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   255
abbreviation val_this :: "st \<Rightarrow> val"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   256
  where "val_this s == the (locals s This)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   257
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   258
abbreviation lookup_obj :: "st \<Rightarrow> val \<Rightarrow> obj"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   259
  where "lookup_obj s a' == the (heap s (the_Addr a'))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   260
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   261
subsection "memory allocation"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   262
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   263
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   264
  new_Addr :: "heap \<Rightarrow> loc option" where
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   265
  "new_Addr h = (if (\<forall>a. h a \<noteq> None) then None else Some (SOME a. h a = None))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   266
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   267
lemma new_AddrD: "new_Addr h = Some a \<Longrightarrow> h a = None"
18576
8d98b7711e47 Reversed Larry's option/iff change.
nipkow
parents: 18447
diff changeset
   268
apply (auto simp add: new_Addr_def)
18447
da548623916a removed or modified some instances of [iff]
paulson
parents: 16417
diff changeset
   269
apply (erule someI) 
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   270
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   271
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   272
lemma new_AddrD2: "new_Addr h = Some a \<Longrightarrow> \<forall>b. h b \<noteq> None \<longrightarrow> b \<noteq> a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   273
apply (drule new_AddrD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   274
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   275
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   276
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   277
lemma new_Addr_SomeI: "h a = None \<Longrightarrow> \<exists>b. new_Addr h = Some b \<and> h b = None"
18576
8d98b7711e47 Reversed Larry's option/iff change.
nipkow
parents: 18447
diff changeset
   278
apply (simp add: new_Addr_def)
18447
da548623916a removed or modified some instances of [iff]
paulson
parents: 16417
diff changeset
   279
apply (fast intro: someI2)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   280
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   281
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   282
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   283
subsection "initialization"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   284
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   285
abbreviation init_vals :: "('a, ty) table \<Rightarrow> ('a, val) table"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   286
  where "init_vals vs == Option.map default_val \<circ> vs"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   287
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   288
lemma init_arr_comps_base [simp]: "init_vals (arr_comps T 0) = empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   289
apply (unfold arr_comps_def in_bounds_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   290
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   291
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   292
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   293
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   294
lemma init_arr_comps_step [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   295
"0 < j \<Longrightarrow> init_vals (arr_comps T  j    ) =  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   296
           init_vals (arr_comps T (j - 1))(j - 1\<mapsto>default_val T)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   297
apply (unfold arr_comps_def in_bounds_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   298
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   299
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   300
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   301
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   302
subsection "update"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   303
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   304
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   305
  gupd :: "oref  \<Rightarrow> obj \<Rightarrow> st \<Rightarrow> st" ("gupd'(_\<mapsto>_')" [10, 10] 1000)
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   306
  where "gupd r obj = st_case (\<lambda>g l. st (g(r\<mapsto>obj)) l)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   307
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   308
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   309
  lupd :: "lname \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st" ("lupd'(_\<mapsto>_')" [10, 10] 1000)
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   310
  where "lupd vn v = st_case (\<lambda>g l. st g (l(vn\<mapsto>v)))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   311
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   312
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   313
  upd_gobj :: "oref \<Rightarrow> vn \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   314
  where "upd_gobj r n v = st_case (\<lambda>g l. st (chg_map (upd_obj n v) r g) l)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   315
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   316
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   317
  set_locals  :: "locals \<Rightarrow> st \<Rightarrow> st"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   318
  where "set_locals l = st_case (\<lambda>g l'. st g l)"
30235
58d147683393 Made Option a separate theory and renamed option_map to Option.map
nipkow
parents: 28524
diff changeset
   319
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   320
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   321
  init_obj :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> st \<Rightarrow> st"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   322
  where "init_obj G oi r = gupd(r\<mapsto>\<lparr>tag=oi, values=init_vals (var_tys G oi r)\<rparr>)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   323
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   324
abbreviation
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   325
  init_class_obj :: "prog \<Rightarrow> qtname \<Rightarrow> st \<Rightarrow> st"
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   326
  where "init_class_obj G C == init_obj G undefined (Inr C)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   327
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   328
lemma gupd_def2 [simp]: "gupd(r\<mapsto>obj) (st g l) = st (g(r\<mapsto>obj)) l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   329
apply (unfold gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   330
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   331
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   332
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   333
lemma lupd_def2 [simp]: "lupd(vn\<mapsto>v) (st g l) = st g (l(vn\<mapsto>v))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   334
apply (unfold lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   335
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   336
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   337
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   338
lemma globs_gupd [simp]: "globs  (gupd(r\<mapsto>obj) s) = globs s(r\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   339
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   340
by (simp add: gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   341
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   342
lemma globs_lupd [simp]: "globs  (lupd(vn\<mapsto>v ) s) = globs  s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   343
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   344
by (simp add: lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   345
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   346
lemma locals_gupd [simp]: "locals (gupd(r\<mapsto>obj) s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   347
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   348
by (simp add: gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   349
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   350
lemma locals_lupd [simp]: "locals (lupd(vn\<mapsto>v ) s) = locals s(vn\<mapsto>v )"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   351
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   352
by (simp add: lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   353
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   354
lemma globs_upd_gobj_new [rule_format (no_asm), simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   355
  "globs s r = None \<longrightarrow> globs (upd_gobj r n v s) = globs s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   356
apply (unfold upd_gobj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   357
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   358
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   359
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   360
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   361
lemma globs_upd_gobj_upd [rule_format (no_asm), simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   362
"globs s r=Some obj\<longrightarrow> globs (upd_gobj r n v s) = globs s(r\<mapsto>upd_obj n v obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   363
apply (unfold upd_gobj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   364
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   365
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   366
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   367
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   368
lemma locals_upd_gobj [simp]: "locals (upd_gobj r n v s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   369
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   370
by (simp add: upd_gobj_def) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   371
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   372
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   373
lemma globs_init_obj [simp]: "globs (init_obj G oi r s) t =  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   374
  (if t=r then Some \<lparr>tag=oi,values=init_vals (var_tys G oi r)\<rparr> else globs s t)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   375
apply (unfold init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   376
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   377
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   378
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   379
lemma locals_init_obj [simp]: "locals (init_obj G oi r s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   380
by (simp add: init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   381
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   382
lemma surjective_st [simp]: "st (globs s) (locals s) = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   383
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   384
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   385
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   386
lemma surjective_st_init_obj: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   387
 "st (globs (init_obj G oi r s)) (locals s) = init_obj G oi r s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   388
apply (subst locals_init_obj [THEN sym])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   389
apply (rule surjective_st)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   390
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   391
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   392
lemma heap_heap_upd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   393
  "heap (st (g(Inl a\<mapsto>obj)) l) = heap (st g l)(a\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   394
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   395
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   396
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   397
lemma heap_stat_upd [simp]: "heap (st (g(Inr C\<mapsto>obj)) l) = heap (st g l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   398
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   399
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   400
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   401
lemma heap_local_upd [simp]: "heap (st g (l(vn\<mapsto>v))) = heap (st g l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   402
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   403
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   404
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   405
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   406
lemma heap_gupd_Heap [simp]: "heap (gupd(Heap a\<mapsto>obj) s) = heap s(a\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   407
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   408
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   409
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   410
lemma heap_gupd_Stat [simp]: "heap (gupd(Stat C\<mapsto>obj) s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   411
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   412
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   413
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   414
lemma heap_lupd [simp]: "heap (lupd(vn\<mapsto>v) s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   415
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   416
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   417
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   418
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   419
lemma heap_upd_gobj_Stat [simp]: "heap (upd_gobj (Stat C) n v s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   420
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   421
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   422
apply (case_tac "globs s (Stat C)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   423
apply  auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   424
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   425
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   426
lemma set_locals_def2 [simp]: "set_locals l (st g l') = st g l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   427
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   428
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   429
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   430
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   431
lemma set_locals_id [simp]: "set_locals (locals s) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   432
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   433
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   434
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   435
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   436
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   437
lemma set_set_locals [simp]: "set_locals l (set_locals l' s) = set_locals l s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   438
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   439
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   440
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   441
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   442
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   443
lemma locals_set_locals [simp]: "locals (set_locals l s) = l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   444
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   445
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   446
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   447
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   448
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   449
lemma globs_set_locals [simp]: "globs (set_locals l s) = globs s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   450
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   451
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   452
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   453
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   454
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   455
lemma heap_set_locals [simp]: "heap (set_locals l s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   456
apply (unfold heap_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   457
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   458
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   459
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   460
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   461
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   462
section "abrupt completion"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   463
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   464
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   465
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   466
primrec the_Xcpt :: "abrupt \<Rightarrow> xcpt"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   467
  where "the_Xcpt (Xcpt x) = x"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   468
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   469
primrec the_Jump :: "abrupt => jump"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   470
  where "the_Jump (Jump j) = j"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   471
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   472
primrec the_Loc :: "xcpt \<Rightarrow> loc"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   473
  where "the_Loc (Loc a) = a"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   474
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   475
primrec the_Std :: "xcpt \<Rightarrow> xname"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   476
  where "the_Std (Std x) = x"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 31127
diff changeset
   477
        
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   478
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   479
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   480
  abrupt_if :: "bool \<Rightarrow> abopt \<Rightarrow> abopt \<Rightarrow> abopt"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   481
  where "abrupt_if c x' x = (if c \<and> (x = None) then x' else x)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   482
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   483
lemma abrupt_if_True_None [simp]: "abrupt_if True x None = x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   484
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   485
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   486
lemma abrupt_if_True_not_None [simp]: "x \<noteq> None \<Longrightarrow> abrupt_if True x y \<noteq> None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   487
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   488
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   489
lemma abrupt_if_False [simp]: "abrupt_if False x y = y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   490
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   491
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   492
lemma abrupt_if_Some [simp]: "abrupt_if c x (Some y) = Some y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   493
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   494
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   495
lemma abrupt_if_not_None [simp]: "y \<noteq> None \<Longrightarrow> abrupt_if c x y = y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   496
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   497
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   498
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   499
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   500
lemma split_abrupt_if: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   501
"P (abrupt_if c x' x) = 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   502
      ((c \<and> x = None \<longrightarrow> P x') \<and> (\<not> (c \<and> x = None) \<longrightarrow> P x))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   503
apply (unfold abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   504
apply (split split_if)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   505
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   506
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   507
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   508
abbreviation raise_if :: "bool \<Rightarrow> xname \<Rightarrow> abopt \<Rightarrow> abopt"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   509
  where "raise_if c xn == abrupt_if c (Some (Xcpt (Std xn)))"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   510
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   511
abbreviation np :: "val \<Rightarrow> abopt \<Rightarrow> abopt"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   512
  where "np v == raise_if (v = Null) NullPointer"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   513
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   514
abbreviation check_neg :: "val \<Rightarrow> abopt \<Rightarrow> abopt"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   515
  where "check_neg i' == raise_if (the_Intg i'<0) NegArrSize"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   516
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   517
abbreviation error_if :: "bool \<Rightarrow> error \<Rightarrow> abopt \<Rightarrow> abopt"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   518
  where "error_if c e == abrupt_if c (Some (Error e))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   519
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   520
lemma raise_if_None [simp]: "(raise_if c x y = None) = (\<not>c \<and> y = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   521
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   522
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   523
declare raise_if_None [THEN iffD1, dest!]
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   524
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   525
lemma if_raise_if_None [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   526
  "((if b then y else raise_if c x y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   527
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   528
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   529
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   530
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   531
lemma raise_if_SomeD [dest!]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   532
  "raise_if c x y = Some z \<Longrightarrow> c \<and> z=(Xcpt (Std x)) \<and> y=None \<or> (y=Some z)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   533
apply (case_tac y)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   534
apply (case_tac c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   535
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   536
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   537
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   538
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   539
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   540
lemma error_if_None [simp]: "(error_if c e y = None) = (\<not>c \<and> y = None)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   541
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   542
by auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   543
declare error_if_None [THEN iffD1, dest!]
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   544
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   545
lemma if_error_if_None [simp]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   546
  "((if b then y else error_if c e y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   547
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   548
apply auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   549
done
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   550
13524
604d0f3622d6 *** empty log message ***
wenzelm
parents: 13337
diff changeset
   551
lemma error_if_SomeD [dest!]:
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   552
  "error_if c e y = Some z \<Longrightarrow> c \<and> z=(Error e) \<and> y=None \<or> (y=Some z)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   553
apply (case_tac y)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   554
apply (case_tac c)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   555
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   556
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   557
apply auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   558
done
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   559
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   560
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   561
  absorb :: "jump \<Rightarrow> abopt \<Rightarrow> abopt"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   562
  where "absorb j a = (if a=Some (Jump j) then None else a)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   563
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   564
lemma absorb_SomeD [dest!]: "absorb j a = Some x \<Longrightarrow> a = Some x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   565
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   566
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   567
lemma absorb_same [simp]: "absorb j (Some (Jump j)) = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   568
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   569
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   570
lemma absorb_other [simp]: "a \<noteq> Some (Jump j) \<Longrightarrow> absorb j a = a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   571
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   572
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   573
lemma absorb_Some_NoneD: "absorb j (Some abr) = None \<Longrightarrow> abr = Jump j"
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   574
  by (simp add: absorb_def)
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   575
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   576
lemma absorb_Some_JumpD: "absorb j s = Some (Jump j') \<Longrightarrow> j'\<noteq>j"
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   577
  by (simp add: absorb_def)
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   578
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   579
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   580
section "full program state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   581
41778
5f79a9e42507 modernized specifications;
wenzelm
parents: 40607
diff changeset
   582
type_synonym
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   583
  state = "abopt \<times> st"          --{* state including abruption information *}
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   584
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   585
translations
35431
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   586
  (type) "abopt" <= (type) "abrupt option"
8758fe1fc9f8 cleanup type translations;
wenzelm
parents: 35416
diff changeset
   587
  (type) "state" <= (type) "abopt \<times> st"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   588
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   589
abbreviation
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   590
  Norm :: "st \<Rightarrow> state"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   591
  where "Norm s == (None, s)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   592
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   593
abbreviation (input)
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   594
  abrupt :: "state \<Rightarrow> abopt"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   595
  where "abrupt == fst"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   596
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   597
abbreviation (input)
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   598
  store :: "state \<Rightarrow> st"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   599
  where "store == snd"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   600
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   601
lemma single_stateE: "\<forall>Z. Z = (s::state) \<Longrightarrow> False"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   602
apply (erule_tac x = "(Some k,y)" in all_dupE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   603
apply (erule_tac x = "(None,y)" in allE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   604
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   605
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   606
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   607
lemma state_not_single: "All (op = (x::state)) \<Longrightarrow> R"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   608
apply (drule_tac x = "(if abrupt x = None then Some ?x else None,?y)" in spec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   609
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   610
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   611
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   612
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   613
  normal :: "state \<Rightarrow> bool"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   614
  where "normal = (\<lambda>s. abrupt s = None)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   615
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   616
lemma normal_def2 [simp]: "normal s = (abrupt s = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   617
apply (unfold normal_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   618
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   619
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   620
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   621
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   622
  heap_free :: "nat \<Rightarrow> state \<Rightarrow> bool"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   623
  where "heap_free n = (\<lambda>s. atleast_free (heap (store s)) n)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   624
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   625
lemma heap_free_def2 [simp]: "heap_free n s = atleast_free (heap (store s)) n"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   626
apply (unfold heap_free_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   627
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   628
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   629
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   630
subsection "update"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   631
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   632
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   633
  abupd :: "(abopt \<Rightarrow> abopt) \<Rightarrow> state \<Rightarrow> state"
40607
30d512bf47a7 map_pair replaces prod_fun
haftmann
parents: 37956
diff changeset
   634
  where "abupd f = map_pair f id"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   635
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   636
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   637
  supd :: "(st \<Rightarrow> st) \<Rightarrow> state \<Rightarrow> state"
40607
30d512bf47a7 map_pair replaces prod_fun
haftmann
parents: 37956
diff changeset
   638
  where "supd = map_pair id"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   639
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   640
lemma abupd_def2 [simp]: "abupd f (x,s) = (f x,s)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   641
by (simp add: abupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   642
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   643
lemma abupd_abrupt_if_False [simp]: "\<And> s. abupd (abrupt_if False xo) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   644
by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   645
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   646
lemma supd_def2 [simp]: "supd f (x,s) = (x,f s)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   647
by (simp add: supd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   648
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   649
lemma supd_lupd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   650
 "\<And> s. supd (lupd vn v ) s = (abrupt s,lupd vn v (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   651
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   652
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   653
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   654
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   655
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   656
lemma supd_gupd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   657
 "\<And> s. supd (gupd r obj) s = (abrupt s,gupd r obj (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   658
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   659
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   660
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   661
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   662
lemma supd_init_obj [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   663
 "supd (init_obj G oi r) s = (abrupt s,init_obj G oi r (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   664
apply (unfold init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   665
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   666
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   667
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   668
lemma abupd_store_invariant [simp]: "store (abupd f s) = store s"
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   669
  by (cases s) simp
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   670
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   671
lemma supd_abrupt_invariant [simp]: "abrupt (supd f s) = abrupt s"
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   672
  by (cases s) simp
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   673
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   674
abbreviation set_lvars :: "locals \<Rightarrow> state \<Rightarrow> state"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   675
  where "set_lvars l == supd (set_locals l)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   676
35067
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   677
abbreviation restore_lvars :: "state  \<Rightarrow> state \<Rightarrow> state"
af4c18c30593 modernized syntax translations, using mostly abbreviation/notation;
wenzelm
parents: 33965
diff changeset
   678
  where "restore_lvars s' s == set_lvars (locals (store s')) s"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   679
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   680
lemma set_set_lvars [simp]: "\<And> s. set_lvars l (set_lvars l' s) = set_lvars l s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   681
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   682
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   683
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   684
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   685
lemma set_lvars_id [simp]: "\<And> s. set_lvars (locals (store s)) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   686
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   687
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   688
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   689
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   690
section "initialisation test"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   691
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   692
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   693
  inited :: "qtname \<Rightarrow> globs \<Rightarrow> bool"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   694
  where "inited C g = (g (Stat C) \<noteq> None)"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   695
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   696
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   697
  initd :: "qtname \<Rightarrow> state \<Rightarrow> bool"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   698
  where "initd C = inited C \<circ> globs \<circ> store"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   699
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   700
lemma not_inited_empty [simp]: "\<not>inited C empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   701
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   702
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   703
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   704
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   705
lemma inited_gupdate [simp]: "inited C (g(r\<mapsto>obj)) = (inited C g \<or> r = Stat C)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   706
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   707
apply (auto split add: st.split)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   708
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   709
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   710
lemma inited_init_class_obj [intro!]: "inited C (globs (init_class_obj G C s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   711
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   712
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   713
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   714
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   715
lemma not_initedD: "\<not> inited C g \<Longrightarrow> g (Stat C) = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   716
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   717
apply (erule notnotD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   718
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   719
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   720
lemma initedD: "inited C g \<Longrightarrow> \<exists> obj. g (Stat C) = Some obj"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   721
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   722
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   723
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   724
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   725
lemma initd_def2 [simp]: "initd C s = inited C (globs (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   726
apply (unfold initd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   727
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   728
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   729
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   730
section {* @{text error_free} *}
37956
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   731
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   732
definition
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   733
  error_free :: "state \<Rightarrow> bool"
ee939247b2fb modernized/unified some specifications;
wenzelm
parents: 35431
diff changeset
   734
  where "error_free s = (\<not> (\<exists> err. abrupt s = Some (Error err)))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   735
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   736
lemma error_free_Norm [simp,intro]: "error_free (Norm s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   737
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   738
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   739
lemma error_free_normal [simp,intro]: "normal s \<Longrightarrow> error_free s"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   740
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   741
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   742
lemma error_free_Xcpt [simp]: "error_free (Some (Xcpt x),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   743
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   744
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   745
lemma error_free_Jump [simp,intro]: "error_free (Some (Jump j),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   746
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   747
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   748
lemma error_free_Error [simp]: "error_free (Some (Error e),s) = False"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   749
by (simp add: error_free_def)  
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   750
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   751
lemma error_free_Some [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   752
 "\<not> (\<exists> err. x=Error err) \<Longrightarrow> error_free ((Some x),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   753
by (auto simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   754
13524
604d0f3622d6 *** empty log message ***
wenzelm
parents: 13337
diff changeset
   755
lemma error_free_abupd_absorb [simp,intro]: 
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   756
 "error_free s \<Longrightarrow> error_free (abupd (absorb j) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   757
by (cases s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   758
   (auto simp add: error_free_def absorb_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   759
         split: split_if_asm)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   760
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   761
lemma error_free_absorb [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   762
 "error_free (a,s) \<Longrightarrow> error_free (absorb j a, s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   763
by (auto simp add: error_free_def absorb_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   764
            split: split_if_asm)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   765
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   766
lemma error_free_abrupt_if [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   767
"\<lbrakk>error_free s; \<not> (\<exists> err. x=Error err)\<rbrakk>
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   768
 \<Longrightarrow> error_free (abupd (abrupt_if p (Some x)) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   769
by (cases s)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   770
   (auto simp add: abrupt_if_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   771
            split: split_if)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   772
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   773
lemma error_free_abrupt_if1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   774
"\<lbrakk>error_free (a,s); \<not> (\<exists> err. x=Error err)\<rbrakk>
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   775
 \<Longrightarrow> error_free (abrupt_if p (Some x) a, s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   776
by  (auto simp add: abrupt_if_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   777
            split: split_if)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   778
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   779
lemma error_free_abrupt_if_Xcpt [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   780
 "error_free s 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   781
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Xcpt x))) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   782
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   783
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   784
lemma error_free_abrupt_if_Xcpt1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   785
 "error_free (a,s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   786
  \<Longrightarrow> error_free (abrupt_if p (Some (Xcpt x)) a, s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   787
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   788
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   789
lemma error_free_abrupt_if_Jump [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   790
 "error_free s 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   791
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Jump j))) s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   792
by simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   793
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   794
lemma error_free_abrupt_if_Jump1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   795
 "error_free (a,s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   796
  \<Longrightarrow> error_free (abrupt_if p (Some (Jump j)) a, s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   797
by simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   798
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   799
lemma error_free_raise_if [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   800
 "error_free s \<Longrightarrow> error_free (abupd (raise_if p x) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   801
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   802
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   803
lemma error_free_raise_if1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   804
 "error_free (a,s) \<Longrightarrow> error_free ((raise_if p x a), s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   805
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   806
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   807
lemma error_free_supd [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   808
 "error_free s \<Longrightarrow> error_free (supd f s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   809
by (cases s) (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   810
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   811
lemma error_free_supd1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   812
 "error_free (a,s) \<Longrightarrow> error_free (a,f s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   813
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   814
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   815
lemma error_free_set_lvars [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   816
"error_free s \<Longrightarrow> error_free ((set_lvars l) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   817
by (cases s) simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   818
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   819
lemma error_free_set_locals [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   820
"error_free (x, s)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   821
       \<Longrightarrow> error_free (x, set_locals l s')"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   822
by (simp add: error_free_def)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   823
13688
a0b16d42d489 "Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents: 13524
diff changeset
   824
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   825
end
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   826