src/HOL/MicroJava/BV/Effect.thy
author berghofe
Wed, 20 Feb 2002 15:58:38 +0100
changeset 12907 27e6d344d724
parent 12772 7b7051ae49a0
child 12911 704713ca07ea
permissions -rw-r--r--
New function change_type for changing type assignments of theorems, axioms and oracles.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Effect.thy
d09d0f160888 exceptions
kleing
parents:
diff changeset
     2
    ID:         $Id$
d09d0f160888 exceptions
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein
d09d0f160888 exceptions
kleing
parents:
diff changeset
     4
    Copyright   2000 Technische Universitaet Muenchen
d09d0f160888 exceptions
kleing
parents:
diff changeset
     5
*)
d09d0f160888 exceptions
kleing
parents:
diff changeset
     6
d09d0f160888 exceptions
kleing
parents:
diff changeset
     7
header {* Effect of Instructions on the State Type *}
d09d0f160888 exceptions
kleing
parents:
diff changeset
     8
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
     9
theory Effect = JVMType + JVMExceptions:
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    10
d09d0f160888 exceptions
kleing
parents:
diff changeset
    11
types
d09d0f160888 exceptions
kleing
parents:
diff changeset
    12
  succ_type = "(p_count \<times> state_type option) list"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    13
d09d0f160888 exceptions
kleing
parents:
diff changeset
    14
text {* Program counter of successor instructions: *}
d09d0f160888 exceptions
kleing
parents:
diff changeset
    15
consts
d09d0f160888 exceptions
kleing
parents:
diff changeset
    16
  succs :: "instr => p_count => p_count list"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    17
primrec 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    18
  "succs (Load idx) pc         = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    19
  "succs (Store idx) pc        = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    20
  "succs (LitPush v) pc        = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    21
  "succs (Getfield F C) pc     = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    22
  "succs (Putfield F C) pc     = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    23
  "succs (New C) pc            = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    24
  "succs (Checkcast C) pc      = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    25
  "succs Pop pc                = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    26
  "succs Dup pc                = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    27
  "succs Dup_x1 pc             = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    28
  "succs Dup_x2 pc             = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    29
  "succs Swap pc               = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    30
  "succs IAdd pc               = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    31
  "succs (Ifcmpeq b) pc        = [pc+1, nat (int pc + b)]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    32
  "succs (Goto b) pc           = [nat (int pc + b)]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    33
  "succs Return pc             = [pc]"  
d09d0f160888 exceptions
kleing
parents:
diff changeset
    34
  "succs (Invoke C mn fpTs) pc = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    35
  "succs Throw pc              = [pc]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    36
d09d0f160888 exceptions
kleing
parents:
diff changeset
    37
text "Effect of instruction on the state type:"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    38
consts 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    39
eff' :: "instr \<times> jvm_prog \<times> state_type => state_type"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    40
d09d0f160888 exceptions
kleing
parents:
diff changeset
    41
recdef eff' "{}"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    42
"eff' (Load idx,  G, (ST, LT))          = (ok_val (LT ! idx) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    43
"eff' (Store idx, G, (ts#ST, LT))       = (ST, LT[idx:= OK ts])"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    44
"eff' (LitPush v, G, (ST, LT))           = (the (typeof (\<lambda>v. None) v) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    45
"eff' (Getfield F C, G, (oT#ST, LT))    = (snd (the (field (G,C) F)) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    46
"eff' (Putfield F C, G, (vT#oT#ST, LT)) = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    47
"eff' (New C, G, (ST,LT))               = (Class C # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    48
"eff' (Checkcast C, G, (RefT rt#ST,LT)) = (Class C # ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    49
"eff' (Pop, G, (ts#ST,LT))              = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    50
"eff' (Dup, G, (ts#ST,LT))              = (ts#ts#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    51
"eff' (Dup_x1, G, (ts1#ts2#ST,LT))      = (ts1#ts2#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    52
"eff' (Dup_x2, G, (ts1#ts2#ts3#ST,LT))  = (ts1#ts2#ts3#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    53
"eff' (Swap, G, (ts1#ts2#ST,LT))        = (ts2#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    54
"eff' (IAdd, G, (PrimT Integer#PrimT Integer#ST,LT)) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    55
                                         = (PrimT Integer#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    56
"eff' (Ifcmpeq b, G, (ts1#ts2#ST,LT))   = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    57
"eff' (Goto b, G, s)                    = s"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    58
  -- "Return has no successor instruction in the same method"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    59
"eff' (Return, G, s)                    = s" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    60
  -- "Throw always terminates abruptly"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    61
"eff' (Throw, G, s)                     = s"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    62
"eff' (Invoke C mn fpTs, G, (ST,LT))    = (let ST' = drop (length fpTs) ST 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    63
  in  (fst (snd (the (method (G,C) (mn,fpTs))))#(tl ST'),LT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    64
d09d0f160888 exceptions
kleing
parents:
diff changeset
    65
d09d0f160888 exceptions
kleing
parents:
diff changeset
    66
consts
d09d0f160888 exceptions
kleing
parents:
diff changeset
    67
  match_any :: "jvm_prog \<Rightarrow> p_count \<Rightarrow> exception_table \<Rightarrow> cname list"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    68
primrec
d09d0f160888 exceptions
kleing
parents:
diff changeset
    69
  "match_any G pc [] = []"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    70
  "match_any G pc (e#es) = (let (start_pc, end_pc, handler_pc, catch_type) = e;
d09d0f160888 exceptions
kleing
parents:
diff changeset
    71
                                es' = match_any G pc es 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    72
                            in 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    73
                            if start_pc <= pc \<and> pc < end_pc then catch_type#es' else es')"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    74
d09d0f160888 exceptions
kleing
parents:
diff changeset
    75
d09d0f160888 exceptions
kleing
parents:
diff changeset
    76
consts
d09d0f160888 exceptions
kleing
parents:
diff changeset
    77
  xcpt_names :: "instr \<times> jvm_prog \<times> p_count \<times> exception_table => cname list" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    78
recdef xcpt_names "{}"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    79
  "xcpt_names (Getfield F C, G, pc, et) = [Xcpt NullPointer]" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    80
  "xcpt_names (Putfield F C, G, pc, et) = [Xcpt NullPointer]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    81
  "xcpt_names (New C, G, pc, et)        = [Xcpt OutOfMemory]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    82
  "xcpt_names (Checkcast C, G, pc, et)  = [Xcpt ClassCast]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    83
  "xcpt_names (Throw, G, pc, et)        = match_any G pc et"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    84
  "xcpt_names (Invoke C m p, G, pc, et) = match_any G pc et" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    85
  "xcpt_names (i, G, pc, et)            = []" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    86
d09d0f160888 exceptions
kleing
parents:
diff changeset
    87
d09d0f160888 exceptions
kleing
parents:
diff changeset
    88
constdefs
d09d0f160888 exceptions
kleing
parents:
diff changeset
    89
  xcpt_eff :: "instr \<Rightarrow> jvm_prog \<Rightarrow> p_count \<Rightarrow> state_type option \<Rightarrow> exception_table \<Rightarrow> succ_type"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    90
  "xcpt_eff i G pc s et == 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    91
   map (\<lambda>C. (the (match_exception_table G C pc et), case s of None \<Rightarrow> None | Some s' \<Rightarrow> Some ([Class C], snd s'))) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    92
       (xcpt_names (i,G,pc,et))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    93
d09d0f160888 exceptions
kleing
parents:
diff changeset
    94
  norm_eff :: "instr \<Rightarrow> jvm_prog \<Rightarrow> state_type option \<Rightarrow> state_type option"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    95
  "norm_eff i G == option_map (\<lambda>s. eff' (i,G,s))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    96
d09d0f160888 exceptions
kleing
parents:
diff changeset
    97
  eff :: "instr => jvm_prog => p_count => exception_table => state_type option => succ_type"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    98
  "eff i G pc et s == (map (\<lambda>pc'. (pc',norm_eff i G s)) (succs i pc)) @ (xcpt_eff i G pc s et)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    99
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   100
constdefs
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   101
  isPrimT :: "ty \<Rightarrow> bool"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   102
  "isPrimT T == case T of PrimT T' \<Rightarrow> True | RefT T' \<Rightarrow> False"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   103
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   104
  isRefT :: "ty \<Rightarrow> bool"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   105
  "isRefT T == case T of PrimT T' \<Rightarrow> False | RefT T' \<Rightarrow> True"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   106
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   107
lemma isPrimT [simp]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   108
  "isPrimT T = (\<exists>T'. T = PrimT T')" by (simp add: isPrimT_def split: ty.splits)
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   109
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   110
lemma isRefT [simp]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   111
  "isRefT T = (\<exists>T'. T = RefT T')" by (simp add: isRefT_def split: ty.splits)
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   112
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   113
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   114
lemma "list_all2 P a b \<Longrightarrow> \<forall>(x,y) \<in> set (zip a b). P x y"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   115
  by (simp add: list_all2_def) 
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   116
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   117
d09d0f160888 exceptions
kleing
parents:
diff changeset
   118
text "Conditions under which eff is applicable:"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   119
consts
d09d0f160888 exceptions
kleing
parents:
diff changeset
   120
app' :: "instr \<times> jvm_prog \<times> nat \<times> ty \<times> state_type => bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   121
d09d0f160888 exceptions
kleing
parents:
diff changeset
   122
recdef app' "{}"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   123
"app' (Load idx, G, maxs, rT, s)                  = (idx < length (snd s) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   124
                                                    (snd s) ! idx \<noteq> Err \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   125
                                                    length (fst s) < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   126
"app' (Store idx, G, maxs, rT, (ts#ST, LT))       = (idx < length LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   127
"app' (LitPush v, G, maxs, rT, s)                  = (length (fst s) < maxs \<and> typeof (\<lambda>t. None) v \<noteq> None)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   128
"app' (Getfield F C, G, maxs, rT, (oT#ST, LT))    = (is_class G C \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   129
                                              field (G,C) F \<noteq> None \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   130
                                              fst (the (field (G,C) F)) = C \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   131
                                              G \<turnstile> oT \<preceq> (Class C))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   132
"app' (Putfield F C, G, maxs, rT, (vT#oT#ST, LT)) = (is_class G C \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   133
                                              field (G,C) F \<noteq> None \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   134
                                              fst (the (field (G,C) F)) = C \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   135
                                              G \<turnstile> oT \<preceq> (Class C) \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   136
                                              G \<turnstile> vT \<preceq> (snd (the (field (G,C) F))))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   137
"app' (New C, G, maxs, rT, s)                     = (is_class G C \<and> length (fst s) < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   138
"app' (Checkcast C, G, maxs, rT, (RefT rt#ST,LT)) = (is_class G C)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   139
"app' (Pop, G, maxs, rT, (ts#ST,LT))              = True"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   140
"app' (Dup, G, maxs, rT, (ts#ST,LT))              = (1+length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   141
"app' (Dup_x1, G, maxs, rT, (ts1#ts2#ST,LT))      = (2+length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   142
"app' (Dup_x2, G, maxs, rT, (ts1#ts2#ts3#ST,LT))  = (3+length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   143
"app' (Swap, G, maxs, rT, (ts1#ts2#ST,LT))        = True"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   144
"app' (IAdd, G, maxs, rT, (PrimT Integer#PrimT Integer#ST,LT)) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   145
                                                 = True"
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   146
"app' (Ifcmpeq b, G, maxs, rT, (ts#ts'#ST,LT))    = (isPrimT ts \<and> ts' = ts \<or> 
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   147
                                                     isRefT ts \<and> isRefT ts')"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   148
"app' (Goto b, G, maxs, rT, s)                    = True"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   149
"app' (Return, G, maxs, rT, (T#ST,LT))            = (G \<turnstile> T \<preceq> rT)"
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   150
"app' (Throw, G, maxs, rT, (T#ST,LT))             = isRefT T"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   151
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   152
"app' (Invoke C mn fpTs, G, maxs, rT, s)          = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   153
   (length fpTs < length (fst s) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   154
   (let apTs = rev (take (length fpTs) (fst s));
d09d0f160888 exceptions
kleing
parents:
diff changeset
   155
        X    = hd (drop (length fpTs) (fst s)) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   156
    in  
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   157
        G \<turnstile> X \<preceq> Class C \<and> is_class G C \<and> method (G,C) (mn,fpTs) \<noteq> None \<and>
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   158
        list_all2 (\<lambda>x y. G \<turnstile> x \<preceq> y) apTs fpTs))"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   159
  
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   160
"app' (i,G,maxs,rT,s)                             = False"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   161
d09d0f160888 exceptions
kleing
parents:
diff changeset
   162
constdefs
d09d0f160888 exceptions
kleing
parents:
diff changeset
   163
  xcpt_app :: "instr \<Rightarrow> jvm_prog \<Rightarrow> nat \<Rightarrow> exception_table \<Rightarrow> bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   164
  "xcpt_app i G pc et \<equiv> \<forall>C\<in>set(xcpt_names (i,G,pc,et)). is_class G C"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   165
d09d0f160888 exceptions
kleing
parents:
diff changeset
   166
  app :: "instr => jvm_prog => nat => ty => nat => exception_table => state_type option => bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   167
  "app i G maxs rT pc et s == case s of None => True | Some t => app' (i,G,maxs,rT,t) \<and> xcpt_app i G pc et"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   168
d09d0f160888 exceptions
kleing
parents:
diff changeset
   169
d09d0f160888 exceptions
kleing
parents:
diff changeset
   170
lemma 1: "2 < length a ==> (\<exists>l l' l'' ls. a = l#l'#l''#ls)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   171
proof (cases a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   172
  fix x xs assume "a = x#xs" "2 < length a"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   173
  thus ?thesis by - (cases xs, simp, cases "tl xs", auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   174
qed auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   175
d09d0f160888 exceptions
kleing
parents:
diff changeset
   176
lemma 2: "\<not>(2 < length a) ==> a = [] \<or> (\<exists> l. a = [l]) \<or> (\<exists> l l'. a = [l,l'])"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   177
proof -;
d09d0f160888 exceptions
kleing
parents:
diff changeset
   178
  assume "\<not>(2 < length a)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   179
  hence "length a < (Suc (Suc (Suc 0)))" by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   180
  hence * : "length a = 0 \<or> length a = Suc 0 \<or> length a = Suc (Suc 0)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   181
    by (auto simp add: less_Suc_eq)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   182
d09d0f160888 exceptions
kleing
parents:
diff changeset
   183
  { 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   184
    fix x 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   185
    assume "length x = Suc 0"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   186
    hence "\<exists> l. x = [l]"  by - (cases x, auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   187
  } note 0 = this
d09d0f160888 exceptions
kleing
parents:
diff changeset
   188
d09d0f160888 exceptions
kleing
parents:
diff changeset
   189
  have "length a = Suc (Suc 0) ==> \<exists>l l'. a = [l,l']" by (cases a, auto dest: 0)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   190
  with * show ?thesis by (auto dest: 0)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   191
qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   192
d09d0f160888 exceptions
kleing
parents:
diff changeset
   193
lemmas [simp] = app_def xcpt_app_def
d09d0f160888 exceptions
kleing
parents:
diff changeset
   194
d09d0f160888 exceptions
kleing
parents:
diff changeset
   195
text {* 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   196
\medskip
d09d0f160888 exceptions
kleing
parents:
diff changeset
   197
simp rules for @{term app}
d09d0f160888 exceptions
kleing
parents:
diff changeset
   198
*}
d09d0f160888 exceptions
kleing
parents:
diff changeset
   199
lemma appNone[simp]: "app i G maxs rT pc et None = True" by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   200
d09d0f160888 exceptions
kleing
parents:
diff changeset
   201
d09d0f160888 exceptions
kleing
parents:
diff changeset
   202
lemma appLoad[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   203
"(app (Load idx) G maxs rT pc et (Some s)) = (\<exists>ST LT. s = (ST,LT) \<and> idx < length LT \<and> LT!idx \<noteq> Err \<and> length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   204
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   205
d09d0f160888 exceptions
kleing
parents:
diff changeset
   206
lemma appStore[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   207
"(app (Store idx) G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT) \<and> idx < length LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   208
  by (cases s, cases "2 < length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   209
d09d0f160888 exceptions
kleing
parents:
diff changeset
   210
lemma appLitPush[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   211
"(app (LitPush v) G maxs rT pc et (Some s)) = (\<exists>ST LT. s = (ST,LT) \<and> length ST < maxs \<and> typeof (\<lambda>v. None) v \<noteq> None)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   212
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   213
d09d0f160888 exceptions
kleing
parents:
diff changeset
   214
lemma appGetField[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   215
"(app (Getfield F C) G maxs rT pc et (Some s)) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   216
 (\<exists> oT vT ST LT. s = (oT#ST, LT) \<and> is_class G C \<and>  
d09d0f160888 exceptions
kleing
parents:
diff changeset
   217
  field (G,C) F = Some (C,vT) \<and> G \<turnstile> oT \<preceq> (Class C) \<and> is_class G (Xcpt NullPointer))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   218
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   219
d09d0f160888 exceptions
kleing
parents:
diff changeset
   220
lemma appPutField[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   221
"(app (Putfield F C) G maxs rT pc et (Some s)) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   222
 (\<exists> vT vT' oT ST LT. s = (vT#oT#ST, LT) \<and> is_class G C \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   223
  field (G,C) F = Some (C, vT') \<and> G \<turnstile> oT \<preceq> (Class C) \<and> G \<turnstile> vT \<preceq> vT' \<and> is_class G (Xcpt NullPointer))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   224
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   225
d09d0f160888 exceptions
kleing
parents:
diff changeset
   226
lemma appNew[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   227
  "(app (New C) G maxs rT pc et (Some s)) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   228
  (\<exists>ST LT. s=(ST,LT) \<and> is_class G C \<and> length ST < maxs \<and> is_class G (Xcpt OutOfMemory))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   229
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   230
d09d0f160888 exceptions
kleing
parents:
diff changeset
   231
lemma appCheckcast[simp]: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   232
  "(app (Checkcast C) G maxs rT pc et (Some s)) =  
d09d0f160888 exceptions
kleing
parents:
diff changeset
   233
  (\<exists>rT ST LT. s = (RefT rT#ST,LT) \<and> is_class G C \<and> is_class G (Xcpt ClassCast))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   234
  by (cases s, cases "fst s", simp add: app_def) (cases "hd (fst s)", auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   235
d09d0f160888 exceptions
kleing
parents:
diff changeset
   236
lemma appPop[simp]: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   237
"(app Pop G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   238
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   239
d09d0f160888 exceptions
kleing
parents:
diff changeset
   240
d09d0f160888 exceptions
kleing
parents:
diff changeset
   241
lemma appDup[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   242
"(app Dup G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT) \<and> 1+length ST < maxs)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   243
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   244
d09d0f160888 exceptions
kleing
parents:
diff changeset
   245
d09d0f160888 exceptions
kleing
parents:
diff changeset
   246
lemma appDup_x1[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   247
"(app Dup_x1 G maxs rT pc et (Some s)) = (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT) \<and> 2+length ST < maxs)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   248
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   249
d09d0f160888 exceptions
kleing
parents:
diff changeset
   250
d09d0f160888 exceptions
kleing
parents:
diff changeset
   251
lemma appDup_x2[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   252
"(app Dup_x2 G maxs rT pc et (Some s)) = (\<exists>ts1 ts2 ts3 ST LT. s = (ts1#ts2#ts3#ST,LT) \<and> 3+length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   253
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   254
d09d0f160888 exceptions
kleing
parents:
diff changeset
   255
d09d0f160888 exceptions
kleing
parents:
diff changeset
   256
lemma appSwap[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   257
"app Swap G maxs rT pc et (Some s) = (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   258
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   259
d09d0f160888 exceptions
kleing
parents:
diff changeset
   260
d09d0f160888 exceptions
kleing
parents:
diff changeset
   261
lemma appIAdd[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   262
"app IAdd G maxs rT pc et (Some s) = (\<exists> ST LT. s = (PrimT Integer#PrimT Integer#ST,LT))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   263
  (is "?app s = ?P s")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   264
proof (cases (open) s)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   265
  case Pair
d09d0f160888 exceptions
kleing
parents:
diff changeset
   266
  have "?app (a,b) = ?P (a,b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   267
  proof (cases "a")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   268
    fix t ts assume a: "a = t#ts"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   269
    show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   270
    proof (cases t)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   271
      fix p assume p: "t = PrimT p"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   272
      show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   273
      proof (cases p)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   274
        assume ip: "p = Integer"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   275
        show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   276
        proof (cases ts)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   277
          fix t' ts' assume t': "ts = t' # ts'"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   278
          show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   279
          proof (cases t')
d09d0f160888 exceptions
kleing
parents:
diff changeset
   280
            fix p' assume "t' = PrimT p'"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   281
            with t' ip p a
d09d0f160888 exceptions
kleing
parents:
diff changeset
   282
            show ?thesis by - (cases p', auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   283
          qed (auto simp add: a p ip t')
d09d0f160888 exceptions
kleing
parents:
diff changeset
   284
        qed (auto simp add: a p ip)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   285
      qed (auto simp add: a p)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   286
    qed (auto simp add: a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   287
  qed auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   288
  with Pair show ?thesis by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   289
qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   290
d09d0f160888 exceptions
kleing
parents:
diff changeset
   291
d09d0f160888 exceptions
kleing
parents:
diff changeset
   292
lemma appIfcmpeq[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   293
"app (Ifcmpeq b) G maxs rT pc et (Some s) = (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   294
 ((\<exists> p. ts1 = PrimT p \<and> ts2 = PrimT p) \<or> (\<exists>r r'. ts1 = RefT r \<and> ts2 = RefT r')))" 
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   295
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   296
d09d0f160888 exceptions
kleing
parents:
diff changeset
   297
lemma appReturn[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   298
"app Return G maxs rT pc et (Some s) = (\<exists>T ST LT. s = (T#ST,LT) \<and> (G \<turnstile> T \<preceq> rT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   299
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   300
d09d0f160888 exceptions
kleing
parents:
diff changeset
   301
lemma appGoto[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   302
"app (Goto branch) G maxs rT pc et (Some s) = True"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   303
  by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   304
d09d0f160888 exceptions
kleing
parents:
diff changeset
   305
lemma appThrow[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   306
  "app Throw G maxs rT pc et (Some s) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   307
  (\<exists>T ST LT r. s=(T#ST,LT) \<and> T = RefT r \<and> (\<forall>C \<in> set (match_any G pc et). is_class G C))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   308
  by (cases s, cases "2 < length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   309
d09d0f160888 exceptions
kleing
parents:
diff changeset
   310
lemma appInvoke[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   311
"app (Invoke C mn fpTs) G maxs rT pc et (Some s) = (\<exists>apTs X ST LT mD' rT' b'.
d09d0f160888 exceptions
kleing
parents:
diff changeset
   312
  s = ((rev apTs) @ (X # ST), LT) \<and> length apTs = length fpTs \<and> is_class G C \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   313
  G \<turnstile> X \<preceq> Class C \<and> (\<forall>(aT,fT)\<in>set(zip apTs fpTs). G \<turnstile> aT \<preceq> fT) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   314
  method (G,C) (mn,fpTs) = Some (mD', rT', b') \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   315
  (\<forall>C \<in> set (match_any G pc et). is_class G C))" (is "?app s = ?P s")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   316
proof (cases (open) s)
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   317
  note list_all2_def [simp]
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   318
  case Pair
d09d0f160888 exceptions
kleing
parents:
diff changeset
   319
  have "?app (a,b) ==> ?P (a,b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   320
  proof -
d09d0f160888 exceptions
kleing
parents:
diff changeset
   321
    assume app: "?app (a,b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   322
    hence "a = (rev (rev (take (length fpTs) a))) @ (drop (length fpTs) a) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   323
           length fpTs < length a" (is "?a \<and> ?l") 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   324
      by (auto simp add: app_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   325
    hence "?a \<and> 0 < length (drop (length fpTs) a)" (is "?a \<and> ?l") 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   326
      by auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   327
    hence "?a \<and> ?l \<and> length (rev (take (length fpTs) a)) = length fpTs" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   328
      by (auto simp add: min_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   329
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> 0 < length ST" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   330
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   331
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> ST \<noteq> []" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   332
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   333
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   334
           (\<exists>X ST'. ST = X#ST')" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   335
      by (simp add: neq_Nil_conv)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   336
    hence "\<exists>apTs X ST. a = rev apTs @ X # ST \<and> length apTs = length fpTs" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   337
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   338
    with app
d09d0f160888 exceptions
kleing
parents:
diff changeset
   339
    show ?thesis by (unfold app_def, clarsimp) blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   340
  qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   341
  with Pair 
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   342
  have "?app s \<Longrightarrow> ?P s" by (simp only:)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   343
  moreover
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   344
  have "?P s \<Longrightarrow> ?app s" by (unfold app_def) (clarsimp simp add: min_def)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   345
  ultimately
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   346
  show ?thesis by (rule iffI) 
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   347
qed 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   348
d09d0f160888 exceptions
kleing
parents:
diff changeset
   349
lemma effNone: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   350
  "(pc', s') \<in> set (eff i G pc et None) \<Longrightarrow> s' = None"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   351
  by (auto simp add: eff_def xcpt_eff_def norm_eff_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   352
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   353
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   354
text {* some helpers to make the specification directly executable: *}
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   355
declare list_all2_Nil [code]
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   356
declare list_all2_Cons [code]
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   357
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   358
lemma xcpt_app_lemma [code]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   359
  "xcpt_app i G pc et = list_all (is_class G) (xcpt_names (i, G, pc, et))"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   360
  by (simp add: list_all_conv)
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   361
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   362
lemmas [simp del] = app_def xcpt_app_def
d09d0f160888 exceptions
kleing
parents:
diff changeset
   363
d09d0f160888 exceptions
kleing
parents:
diff changeset
   364
end