src/HOL/MicroJava/BV/JVM.thy
author oheimb
Thu, 18 Jan 2001 17:38:56 +0100
changeset 10925 5ffe7ed8899a
parent 10897 697fab84709e
child 11186 63f3e98df2a4
permissions -rw-r--r--
is_class and class now as defs (rather than translations); corrected Digest.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     1
(*  Title:      HOL/BCV/JVM.thy
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     2
    ID:         $Id$
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     3
    Author:     Tobias Nipkow
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     4
    Copyright   2000 TUM
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     5
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     6
*)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     7
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
     8
header "Kildall for the JVM"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
     9
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
    10
theory JVM = Kildall + JVMType + Opt + Product + DFA_err + StepMono + BVSpec:
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    11
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    12
constdefs
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    13
  exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> instr list \<Rightarrow> nat \<Rightarrow> state \<Rightarrow> state"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    14
  "exec G maxs rT bs == err_step (\<lambda>pc. app (bs!pc) G maxs rT) (\<lambda>pc. step (bs!pc) G)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    15
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    16
  kiljvm :: "jvm_prog => nat => nat => ty => instr list => state list => state list"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    17
  "kiljvm G maxs maxr rT bs ==
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
    18
  kildall (JVMType.sl G maxs maxr) (exec G maxs rT bs) (\<lambda>pc. succs (bs!pc) pc)"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    19
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    20
  wt_kil :: "jvm_prog \<Rightarrow> cname \<Rightarrow> ty list \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> instr list \<Rightarrow> bool"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    21
  "wt_kil G C pTs rT mxs mxl ins ==
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    22
   bounded (\<lambda>n. succs (ins!n) n) (size ins) \<and> 0 < size ins \<and> 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    23
   (let first  = Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err));
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    24
        start  = OK first#(replicate (size ins-1) (OK None));
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    25
        result = kiljvm G mxs (1+size pTs+mxl) rT ins start
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    26
    in \<forall>n < size ins. result!n \<noteq> Err)"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    27
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    28
  wt_jvm_prog_kildall :: "jvm_prog => bool"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    29
  "wt_jvm_prog_kildall G ==
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    30
  wf_prog (\<lambda>G C (sig,rT,(maxs,maxl,b)). wt_kil G C (snd sig) rT maxs maxl b) G"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    31
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    32
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    33
lemma special_ex_swap_lemma [iff]: 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    34
  "(? X. (? n. X = A n & P n) & Q X) = (? n. Q(A n) & P n)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    35
  by blast
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    36
10630
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    37
lemmas [iff del] = not_None_eq
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    38
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    39
theorem exec_pres_type:
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    40
  "[| wf_prog wf_mb S |] ==> 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    41
      pres_type (exec S maxs rT bs) (size bs) (states S maxs maxr)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    42
 apply (unfold pres_type_def list_def step_def JVM_states_unfold)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    43
 apply (clarify elim!: option_map_in_optionI lift_in_errI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    44
 apply (simp add: exec_def err_step_def lift_def split: err.split)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    45
 apply (simp add: step_def option_map_def split: option.splits)  
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    46
 apply clarify
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    47
 apply (case_tac "bs!p")
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    48
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    49
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    50
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    51
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    52
 apply fastsimp
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    53
 apply clarsimp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    54
 defer
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    55
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    56
 apply fastsimp
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    57
 apply clarsimp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    58
 defer
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    59
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    60
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    61
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    62
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    63
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    64
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    65
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    66
 apply fastsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    67
 apply fastsimp
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    68
 defer
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    69
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    70
 (* Invoke *)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    71
 apply (simp add: Un_subset_iff)
10630
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    72
 apply (drule method_wf_mdecl, assumption+)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    73
 apply (simp add: wf_mdecl_def wf_mhead_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    74
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
    75
 (* Getfield *)
10630
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    76
 apply (rule_tac fn = "(vname,cname)" in fields_is_type)
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    77
 defer
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    78
 apply assumption+
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    79
 apply (simp add: field_def)
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    80
 apply (drule map_of_SomeD)
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    81
 apply (rule map_of_SomeI)
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    82
 apply (auto simp add: unique_fields)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    83
 done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    84
10630
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    85
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    86
lemmas [iff] = not_None_eq
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    87
f89c3fc4fde1 updated for is_class changes
kleing
parents: 10612
diff changeset
    88
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    89
theorem exec_mono:
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    90
  "wf_prog wf_mb G ==>
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
    91
  mono (JVMType.le G maxs maxr) (exec G maxs rT bs) (size bs) (states G maxs maxr)"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    92
  apply (unfold mono_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    93
  apply clarify
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    94
  apply (unfold lesub_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    95
  apply (case_tac t)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    96
   apply (simp add: JVM_le_unfold Err.le_def exec_def err_step_def lift_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    97
  apply (case_tac s)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    98
   apply (simp add: JVM_le_unfold Err.le_def exec_def err_step_def lift_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
    99
  apply (simp add: JVM_le_convert exec_def err_step_def lift_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   100
  apply (simp add: JVM_le_unfold Err.le_def exec_def err_step_def lift_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   101
  apply (rule conjI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   102
   apply clarify
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   103
   apply (rule step_mono, assumption+)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   104
  apply (rule impI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   105
  apply (erule contrapos_nn)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   106
  apply (rule app_mono, assumption+)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   107
  done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   108
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   109
theorem semilat_JVM_slI:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   110
  "[| wf_prog wf_mb G |] ==> semilat (JVMType.sl G maxs maxr)"
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   111
  apply (unfold JVMType.sl_def stk_esl_def reg_sl_def)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   112
  apply (rule semilat_opt)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   113
  apply (rule err_semilat_Product_esl)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   114
  apply (rule err_semilat_upto_esl)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   115
  apply (rule err_semilat_JType_esl, assumption+)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   116
  apply (rule err_semilat_eslI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   117
  apply (rule semilat_Listn_sl)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   118
  apply (rule err_semilat_JType_esl, assumption+)  
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   119
  done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   120
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   121
lemma sl_triple_conv:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   122
  "JVMType.sl G maxs maxr == 
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   123
  (states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)"
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   124
  by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   125
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   126
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   127
theorem is_bcv_kiljvm:
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   128
  "[| wf_prog wf_mb G; bounded (\<lambda>pc. succs (bs!pc) pc) (size bs) |] ==> 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   129
      is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT bs) (\<lambda>pc. succs (bs!pc) pc)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   130
             (size bs) (states G maxs maxr) (kiljvm G maxs maxr rT bs)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   131
  apply (unfold kiljvm_def sl_triple_conv)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   132
  apply (rule is_bcv_kildall)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   133
       apply (simp (no_asm) add: sl_triple_conv [symmetric]) 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   134
       apply (force intro!: semilat_JVM_slI dest: wf_acyclic simp add: symmetric sl_triple_conv)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   135
      apply (simp (no_asm) add: JVM_le_unfold)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   136
      apply (blast intro!: order_widen wf_converse_subcls1_impl_acc_subtype
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   137
                   dest: wf_subcls1 wf_acyclic) 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   138
     apply (simp add: JVM_le_unfold)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   139
    apply (erule exec_pres_type)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   140
    apply assumption
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   141
  apply (erule exec_mono)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   142
  done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   143
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   144
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   145
theorem wt_kil_correct:
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   146
  "[| wt_kil G C pTs rT maxs mxl bs; wf_prog wf_mb G; 
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   147
      is_class G C; \<forall>x \<in> set pTs. is_type G x |]
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   148
  ==> \<exists>phi. wt_method G C pTs rT maxs mxl bs phi"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   149
proof -
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   150
  let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)))
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   151
                #(replicate (size bs-1) (OK None))"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   152
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   153
  assume wf:      "wf_prog wf_mb G"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   154
  assume isclass: "is_class G C"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   155
  assume istype:  "\<forall>x \<in> set pTs. is_type G x"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   156
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   157
  assume "wt_kil G C pTs rT maxs mxl bs"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   158
  then obtain maxr r where    
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   159
    bounded: "bounded (\<lambda>pc. succs (bs!pc) pc) (size bs)" and
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   160
    result:  "r = kiljvm G maxs maxr rT bs ?start" and
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   161
    success: "\<forall>n < size bs. r!n \<noteq> Err" and
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   162
    instrs:  "0 < size bs" and
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   163
    maxr:    "maxr = Suc (length pTs + mxl)" 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   164
    by (unfold wt_kil_def) simp
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   165
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   166
  { fix pc
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   167
    have "succs (bs!pc) pc \<noteq> []"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   168
      by (cases "bs!pc") auto
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   169
  }
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   170
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   171
  hence non_empty: "non_empty (\<lambda>pc. succs (bs!pc) pc)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   172
    by (unfold non_empty_def) blast
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   173
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   174
  from wf bounded
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   175
  have bcv:
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   176
    "is_bcv (JVMType.le G maxs maxr) Err (exec G maxs rT bs) (\<lambda>pc. succs (bs!pc) pc)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   177
            (size bs) (states G maxs maxr) (kiljvm G maxs maxr rT bs)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   178
    by (rule is_bcv_kiljvm)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   179
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   180
  { fix l x
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   181
    have "set (replicate l x) \<subseteq> {x}"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   182
      by (cases "0 < l") simp+
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   183
  } note subset_replicate = this
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   184
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   185
  from istype
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   186
  have "set pTs \<subseteq> types G"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   187
    by auto
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   188
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10812
diff changeset
   189
  hence "OK ` set pTs \<subseteq> err (types G)"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   190
    by auto
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   191
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   192
  with instrs maxr isclass 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   193
  have "?start \<in> list (length bs) (states G maxs maxr)"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   194
    apply (unfold list_def JVM_states_unfold)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   195
    apply simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   196
    apply (rule conjI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   197
     apply (simp add: Un_subset_iff)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   198
     apply (rule_tac B = "{Err}" in subset_trans)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   199
      apply (simp add: subset_replicate)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   200
     apply simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   201
    apply (rule_tac B = "{OK None}" in subset_trans)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   202
     apply (simp add: subset_replicate)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   203
    apply simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   204
    done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   205
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   206
  with bcv success result 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   207
  have 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   208
    "\<exists>ts\<in>list (length bs) (states G maxs maxr).
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   209
         ?start <=[JVMType.le G maxs maxr] ts \<and>
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   210
         welltyping (JVMType.le G maxs maxr) Err (exec G maxs rT bs) (\<lambda>pc. succs (bs ! pc) pc) ts"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   211
    by (unfold is_bcv_def) auto
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   212
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   213
  then obtain phi' where
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   214
    l: "phi' \<in> list (length bs) (states G maxs maxr)" and
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   215
    s: "?start <=[JVMType.le G maxs maxr] phi'" and
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   216
    w: "welltyping (JVMType.le G maxs maxr) Err (exec G maxs rT bs) (\<lambda>pc. succs (bs ! pc) pc) phi'"
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   217
    by blast
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   218
   
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   219
  hence dynamic:
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   220
    "dynamic_wt (sup_state_opt G) (exec G maxs rT bs) (\<lambda>pc. succs (bs ! pc) pc) phi'"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   221
    by (simp add: dynamic_wt_def exec_def JVM_le_Err_conv)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   222
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   223
  from s
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   224
  have le: "JVMType.le G maxs maxr (?start ! 0) (phi'!0)"    
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   225
    by (drule_tac p=0 in le_listD) (simp add: lesub_def)+
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   226
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   227
  from l
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   228
  have l: "size phi' = size bs"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   229
    by simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   230
  
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   231
  with instrs w
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   232
  have "phi' ! 0 \<noteq> Err"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   233
    by (unfold welltyping_def) simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   234
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   235
  with instrs l
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   236
  have phi0: "OK (map ok_val phi' ! 0) = phi' ! 0"
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   237
    by (clarsimp simp add: not_Err_eq)
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   238
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   239
  from l bounded
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   240
  have "bounded (\<lambda>pc. succs (bs ! pc) pc) (length phi')"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   241
    by simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   242
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   243
  with dynamic non_empty
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   244
  have "static_wt (sup_state_opt G) (\<lambda>pc. app (bs!pc) G maxs rT) (\<lambda>pc. step (bs!pc) G) 
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   245
                                    (\<lambda>pc. succs (bs!pc) pc) (map ok_val phi')"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   246
    by (auto intro: dynamic_imp_static simp add: exec_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   247
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   248
  with instrs l le bounded
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   249
  have "wt_method G C pTs rT maxs mxl bs (map ok_val phi')"
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   250
    apply (unfold wt_method_def static_wt_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   251
    apply simp
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   252
    apply (rule conjI)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   253
     apply (unfold wt_start_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   254
     apply (rule JVM_le_convert [THEN iffD1])
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   255
     apply (simp (no_asm) add: phi0)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   256
    apply clarify
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   257
    apply (erule allE, erule impE, assumption)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   258
    apply (elim conjE)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   259
    apply (clarsimp simp add: lesub_def wt_instr_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   260
    apply (unfold bounded_def)
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   261
    apply blast    
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   262
    done
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   263
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   264
  thus ?thesis by blast
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   265
qed
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   266
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   267
10657
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   268
(* there's still one easy, and one nontrivial (but provable) sorry in here  *)
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   269
(*
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   270
theorem wt_kil_complete:
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   271
  "[| wt_method G C pTs rT maxs mxl bs phi; wf_prog wf_mb G; 
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   272
      length phi = length bs; is_class G C; \<forall>x \<in> set pTs. is_type G x |]
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   273
  ==> wt_kil G C pTs rT maxs mxl bs"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   274
proof -
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   275
  assume wf:      "wf_prog wf_mb G"  
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   276
  assume isclass: "is_class G C"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   277
  assume istype:  "\<forall>x \<in> set pTs. is_type G x"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   278
  assume length:  "length phi = length bs"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   279
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   280
  assume "wt_method G C pTs rT maxs mxl bs phi"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   281
  then obtain
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   282
    instrs:   "0 < length bs" and
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   283
    wt_start: "wt_start G C pTs mxl phi" and
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   284
    wt_ins:   "\<forall>pc. pc < length bs \<longrightarrow> 
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   285
                    wt_instr (bs ! pc) G rT phi maxs (length bs) pc"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   286
    by (unfold wt_method_def) simp
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   287
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   288
  let ?succs = "\<lambda>pc. succs (bs!pc) pc"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   289
  let ?step  = "\<lambda>pc. step (bs!pc) G"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   290
  let ?app   = "\<lambda>pc. app (bs!pc) G maxs rT"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   291
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   292
  from wt_ins
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   293
  have bounded: "bounded ?succs (size bs)"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   294
    by (unfold wt_instr_def bounded_def) blast
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   295
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   296
  from wt_ins
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   297
  have "static_wt (sup_state_opt G) ?app ?step ?succs phi"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   298
    apply (unfold static_wt_def wt_instr_def lesub_def)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   299
    apply (simp (no_asm) only: length)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   300
    apply blast
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   301
    done
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   302
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   303
  with bounded
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   304
  have "dynamic_wt (sup_state_opt G) (err_step ?app ?step) ?succs (map OK phi)"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   305
    by - (erule static_imp_dynamic, simp add: length)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   306
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   307
  hence dynamic:
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   308
    "dynamic_wt (sup_state_opt G) (exec G maxs rT bs) ?succs (map OK phi)"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   309
    by (unfold exec_def)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   310
 
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   311
  let ?maxr = "1+size pTs+mxl"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   312
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   313
  from wf bounded
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   314
  have is_bcv: 
10812
ead84e90bfeb merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents: 10657
diff changeset
   315
    "is_bcv (JVMType.le G maxs ?maxr) Err (exec G maxs rT bs) ?succs 
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   316
            (size bs) (states G maxs ?maxr) (kiljvm G maxs ?maxr rT bs)"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   317
    by (rule is_bcv_kiljvm)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   318
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   319
  let ?start = "OK (Some ([],(OK (Class C))#((map OK pTs))@(replicate mxl Err)))
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   320
                #(replicate (size bs-1) (OK None))"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   321
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   322
  { fix l x
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   323
    have "set (replicate l x) \<subseteq> {x}"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   324
      by (cases "0 < l") simp+
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   325
  } note subset_replicate = this
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   326
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   327
  from istype
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   328
  have "set pTs \<subseteq> types G"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   329
    by auto
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   330
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10812
diff changeset
   331
  hence "OK ` set pTs \<subseteq> err (types G)"
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   332
    by auto
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   333
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   334
  with instrs isclass 
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   335
  have start:
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   336
    "?start \<in> list (length bs) (states G maxs ?maxr)"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   337
    apply (unfold list_def JVM_states_unfold)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   338
    apply simp
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   339
    apply (rule conjI)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   340
     apply (simp add: Un_subset_iff)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   341
     apply (rule_tac B = "{Err}" in subset_trans)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   342
      apply (simp add: subset_replicate)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   343
     apply simp
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   344
    apply (rule_tac B = "{OK None}" in subset_trans)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   345
     apply (simp add: subset_replicate)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   346
    apply simp
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   347
    done
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   348
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   349
  let ?phi = "map OK phi"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   350
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   351
  have 1: "?phi \<in> list (length bs) (states G maxs ?maxr)" sorry
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   352
10657
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   353
  have 2: "?start <=[le G maxs ?maxr] ?phi"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   354
  proof -
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   355
    { fix n
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   356
      from wt_start
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   357
      have "G \<turnstile> ok_val (?start!0) <=' phi!0"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   358
        by (simp add: wt_start_def)
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   359
      moreover
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   360
      from instrs length
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   361
      have "0 < length phi" by simp
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   362
      ultimately
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   363
      have "le G maxs ?maxr (?start!0) (?phi!0)"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   364
        by (simp add: JVM_le_Err_conv Err.le_def lesub_def)
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   365
      moreover
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   366
      { fix n'
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   367
        have "le G maxs ?maxr (OK None) (?phi!n)"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   368
          by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def 
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   369
            split: err.splits)        
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   370
        hence "[| n = Suc n'; n < length ?start |] 
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   371
          ==> le G maxs ?maxr (?start!n) (?phi!n)"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   372
          by simp
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   373
      }
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   374
      ultimately
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   375
      have "n < length ?start ==> le G maxs ?maxr (?start!n) (?phi!n)"
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   376
        by - (cases n, blast+)
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   377
    }
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   378
    thus ?thesis sorry
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   379
  qed         
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   380
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   381
  from dynamic
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   382
  have "welltyping (le G maxs ?maxr) Err (exec G maxs rT bs) ?succs ?phi"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   383
    by (simp add: dynamic_wt_def JVM_le_Err_conv)
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   384
  
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   385
  with start 1 2 is_bcv
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   386
  have "\<forall>p. p < length bs \<longrightarrow> kiljvm G maxs ?maxr rT bs ?start ! p \<noteq> Err"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   387
    by (unfold is_bcv_def) blast
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   388
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   389
  with bounded instrs
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   390
  show "wt_kil G C pTs rT maxs mxl bs"
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   391
    by (unfold wt_kil_def) simp
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   392
qed
10657
7e5d659899bf removed sorry proof
kleing
parents: 10651
diff changeset
   393
*)
10651
bb3a81a005f7 completeness (unfinished)
kleing
parents: 10637
diff changeset
   394
10637
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   395
lemma is_type_pTs:
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   396
  "[| wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls; 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   397
      t \<in> set (snd sig) |]
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   398
  ==> is_type G t"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   399
proof -
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   400
  assume "wf_prog wf_mb G" 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   401
         "(C,S,fs,mdecls) \<in> set G"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   402
         "(sig,rT,code) \<in> set mdecls"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   403
  hence "wf_mdecl wf_mb G C (sig,rT,code)"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   404
    by (unfold wf_prog_def wf_cdecl_def) auto
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   405
  hence "\<forall>t \<in> set (snd sig). is_type G t" 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   406
    by (unfold wf_mdecl_def wf_mhead_def) auto
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   407
  moreover
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   408
  assume "t \<in> set (snd sig)"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   409
  ultimately
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   410
  show ?thesis by blast
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   411
qed
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   412
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   413
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   414
theorem jvm_kildall_correct:
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   415
  "wt_jvm_prog_kildall G ==> \<exists>Phi. wt_jvm_prog G Phi"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   416
proof -  
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   417
  assume wtk: "wt_jvm_prog_kildall G"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   418
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   419
  then obtain wf_mb where
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   420
    wf: "wf_prog wf_mb G"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   421
    by (auto simp add: wt_jvm_prog_kildall_def)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   422
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   423
  let ?Phi = "\<lambda>C sig. let (C,rT,(maxs,maxl,ins)) = the (method (G,C) sig) in 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   424
              SOME phi. wt_method G C (snd sig) rT maxs maxl ins phi"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   425
   
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   426
  { fix C S fs mdecls sig rT code
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   427
    assume "(C,S,fs,mdecls) \<in> set G" "(sig,rT,code) \<in> set mdecls"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   428
    with wf
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   429
    have "method (G,C) sig = Some (C,rT,code) \<and> is_class G C \<and> (\<forall>t \<in> set (snd sig). is_type G t)"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   430
      by (simp add: methd is_type_pTs)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   431
  } note this [simp]
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   432
 
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   433
  from wtk
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   434
  have "wt_jvm_prog G ?Phi"
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   435
    apply (unfold wt_jvm_prog_def wt_jvm_prog_kildall_def wf_prog_def wf_cdecl_def)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   436
    apply clarsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   437
    apply (drule bspec, assumption)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   438
    apply (unfold wf_mdecl_def)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   439
    apply clarsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   440
    apply (drule bspec, assumption)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   441
    apply clarsimp
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   442
    apply (drule wt_kil_correct [OF _ wf])
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   443
    apply (auto intro: someI)
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   444
    done
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   445
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   446
  thus ?thesis by blast
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   447
qed
41d309b48afe kildall ==> wt_method for whole program
kleing
parents: 10630
diff changeset
   448
10592
fc0b575a2cf7 BCV Integration
kleing
parents:
diff changeset
   449
end