13224
|
1 |
(* Title: HOL/MicroJava/BV/JVM.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow, Gerwin Klein
|
|
4 |
Copyright 2000 TUM
|
|
5 |
*)
|
|
6 |
|
|
7 |
header {* \isaheader{The Typing Framework for the JVM}\label{sec:JVM} *}
|
|
8 |
|
|
9 |
theory Typing_Framework_JVM = Typing_Framework_err + JVMType + EffectMono + BVSpec:
|
|
10 |
|
|
11 |
|
|
12 |
constdefs
|
|
13 |
exec :: "jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> exception_table \<Rightarrow> instr list \<Rightarrow> state step_type"
|
|
14 |
"exec G maxs rT et bs ==
|
|
15 |
err_step (size bs) (\<lambda>pc. app (bs!pc) G maxs rT pc et) (\<lambda>pc. eff (bs!pc) G pc et)"
|
|
16 |
|
|
17 |
constdefs
|
|
18 |
opt_states :: "'c prog \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (ty list \<times> ty err list) option set"
|
|
19 |
"opt_states G maxs maxr \<equiv> opt (\<Union>{list n (types G) |n. n \<le> maxs} \<times> list maxr (err (types G)))"
|
|
20 |
|
|
21 |
|
|
22 |
section {* Executability of @{term check_bounded} *}
|
|
23 |
consts
|
|
24 |
list_all'_rec :: "('a \<Rightarrow> nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
25 |
primrec
|
|
26 |
"list_all'_rec P n [] = True"
|
|
27 |
"list_all'_rec P n (x#xs) = (P x n \<and> list_all'_rec P (Suc n) xs)"
|
|
28 |
|
|
29 |
constdefs
|
|
30 |
list_all' :: "('a \<Rightarrow> nat \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
31 |
"list_all' P xs \<equiv> list_all'_rec P 0 xs"
|
|
32 |
|
|
33 |
lemma list_all'_rec:
|
|
34 |
"\<And>n. list_all'_rec P n xs = (\<forall>p < size xs. P (xs!p) (p+n))"
|
|
35 |
apply (induct xs)
|
|
36 |
apply auto
|
|
37 |
apply (case_tac p)
|
|
38 |
apply auto
|
|
39 |
done
|
|
40 |
|
|
41 |
lemma list_all' [iff]:
|
|
42 |
"list_all' P xs = (\<forall>n < size xs. P (xs!n) n)"
|
|
43 |
by (unfold list_all'_def) (simp add: list_all'_rec)
|
|
44 |
|
|
45 |
lemma list_all_ball:
|
|
46 |
"list_all P xs = (\<forall>x \<in> set xs. P x)"
|
|
47 |
by (induct xs) auto
|
|
48 |
|
|
49 |
lemma [code]:
|
|
50 |
"check_bounded ins et =
|
|
51 |
(list_all' (\<lambda>i pc. list_all (\<lambda>pc'. pc' < length ins) (succs i pc)) ins \<and>
|
|
52 |
list_all (\<lambda>e. fst (snd (snd e)) < length ins) et)"
|
|
53 |
by (simp add: list_all_ball check_bounded_def)
|
|
54 |
|
|
55 |
|
|
56 |
section {* Connecting JVM and Framework *}
|
|
57 |
|
|
58 |
lemma check_bounded_is_bounded:
|
|
59 |
"check_bounded ins et \<Longrightarrow> bounded (\<lambda>pc. eff (ins!pc) G pc et) (length ins)"
|
|
60 |
by (unfold bounded_def) (blast dest: check_boundedD)
|
|
61 |
|
|
62 |
lemma special_ex_swap_lemma [iff]:
|
|
63 |
"(? X. (? n. X = A n & P n) & Q X) = (? n. Q(A n) & P n)"
|
|
64 |
by blast
|
|
65 |
|
|
66 |
lemmas [iff del] = not_None_eq
|
|
67 |
|
|
68 |
theorem exec_pres_type:
|
|
69 |
"wf_prog wf_mb S \<Longrightarrow>
|
|
70 |
pres_type (exec S maxs rT et bs) (size bs) (states S maxs maxr)"
|
|
71 |
apply (unfold exec_def JVM_states_unfold)
|
|
72 |
apply (rule pres_type_lift)
|
|
73 |
apply clarify
|
|
74 |
apply (case_tac s)
|
|
75 |
apply simp
|
|
76 |
apply (drule effNone)
|
|
77 |
apply simp
|
|
78 |
apply (simp add: eff_def xcpt_eff_def norm_eff_def)
|
|
79 |
apply (case_tac "bs!p")
|
|
80 |
|
|
81 |
apply (clarsimp simp add: not_Err_eq)
|
|
82 |
apply (drule listE_nth_in, assumption)
|
|
83 |
apply fastsimp
|
|
84 |
|
|
85 |
apply (fastsimp simp add: not_None_eq)
|
|
86 |
|
|
87 |
apply (fastsimp simp add: not_None_eq typeof_empty_is_type)
|
|
88 |
|
|
89 |
apply clarsimp
|
|
90 |
apply (erule disjE)
|
|
91 |
apply fastsimp
|
|
92 |
apply clarsimp
|
|
93 |
apply (rule_tac x="1" in exI)
|
|
94 |
apply fastsimp
|
|
95 |
|
|
96 |
apply clarsimp
|
|
97 |
apply (erule disjE)
|
|
98 |
apply (fastsimp dest: field_fields fields_is_type)
|
|
99 |
apply (simp add: match_some_entry split: split_if_asm)
|
|
100 |
apply (rule_tac x=1 in exI)
|
|
101 |
apply fastsimp
|
|
102 |
|
|
103 |
apply clarsimp
|
|
104 |
apply (erule disjE)
|
|
105 |
apply fastsimp
|
|
106 |
apply (simp add: match_some_entry split: split_if_asm)
|
|
107 |
apply (rule_tac x=1 in exI)
|
|
108 |
apply fastsimp
|
|
109 |
|
|
110 |
apply clarsimp
|
|
111 |
apply (erule disjE)
|
|
112 |
apply fastsimp
|
|
113 |
apply clarsimp
|
|
114 |
apply (rule_tac x=1 in exI)
|
|
115 |
apply fastsimp
|
|
116 |
|
|
117 |
defer
|
|
118 |
|
|
119 |
apply fastsimp
|
|
120 |
apply fastsimp
|
|
121 |
|
|
122 |
apply clarsimp
|
|
123 |
apply (rule_tac x="n'+2" in exI)
|
|
124 |
apply simp
|
|
125 |
|
|
126 |
apply clarsimp
|
|
127 |
apply (rule_tac x="Suc (Suc (Suc (length ST)))" in exI)
|
|
128 |
apply simp
|
|
129 |
|
|
130 |
apply clarsimp
|
|
131 |
apply (rule_tac x="Suc (Suc (Suc (Suc (length ST))))" in exI)
|
|
132 |
apply simp
|
|
133 |
|
|
134 |
apply fastsimp
|
|
135 |
apply fastsimp
|
|
136 |
apply fastsimp
|
|
137 |
apply fastsimp
|
|
138 |
|
|
139 |
apply clarsimp
|
|
140 |
apply (erule disjE)
|
|
141 |
apply fastsimp
|
|
142 |
apply clarsimp
|
|
143 |
apply (rule_tac x=1 in exI)
|
|
144 |
apply fastsimp
|
|
145 |
|
|
146 |
apply (erule disjE)
|
|
147 |
apply (clarsimp simp add: Un_subset_iff)
|
|
148 |
apply (drule method_wf_mdecl, assumption+)
|
|
149 |
apply (clarsimp simp add: wf_mdecl_def wf_mhead_def)
|
|
150 |
apply fastsimp
|
|
151 |
apply clarsimp
|
|
152 |
apply (rule_tac x=1 in exI)
|
|
153 |
apply fastsimp
|
|
154 |
done
|
|
155 |
|
|
156 |
lemmas [iff] = not_None_eq
|
|
157 |
|
|
158 |
lemma sup_state_opt_unfold:
|
|
159 |
"sup_state_opt G \<equiv> Opt.le (Product.le (Listn.le (subtype G)) (Listn.le (Err.le (subtype G))))"
|
|
160 |
by (simp add: sup_state_opt_def sup_state_def sup_loc_def sup_ty_opt_def)
|
|
161 |
|
|
162 |
|
|
163 |
lemma app_mono:
|
|
164 |
"app_mono (sup_state_opt G) (\<lambda>pc. app (bs!pc) G maxs rT pc et) (length bs) (opt_states G maxs maxr)"
|
|
165 |
by (unfold app_mono_def lesub_def) (blast intro: EffectMono.app_mono)
|
|
166 |
|
|
167 |
|
|
168 |
lemma list_appendI:
|
|
169 |
"\<lbrakk>a \<in> list x A; b \<in> list y A\<rbrakk> \<Longrightarrow> a @ b \<in> list (x+y) A"
|
|
170 |
apply (unfold list_def)
|
|
171 |
apply (simp (no_asm))
|
|
172 |
apply blast
|
|
173 |
done
|
|
174 |
|
|
175 |
lemma list_map [simp]:
|
|
176 |
"(map f xs \<in> list (length xs) A) = (f ` set xs \<subseteq> A)"
|
|
177 |
apply (unfold list_def)
|
|
178 |
apply simp
|
|
179 |
done
|
|
180 |
|
|
181 |
lemma [iff]:
|
|
182 |
"(OK ` A \<subseteq> err B) = (A \<subseteq> B)"
|
|
183 |
apply (unfold err_def)
|
|
184 |
apply blast
|
|
185 |
done
|
|
186 |
|
|
187 |
lemma [intro]:
|
|
188 |
"x \<in> A \<Longrightarrow> replicate n x \<in> list n A"
|
|
189 |
by (induct n, auto)
|
|
190 |
|
|
191 |
lemma lesubstep_type_simple:
|
|
192 |
"a <=[Product.le (op =) r] b \<Longrightarrow> a <=|r| b"
|
|
193 |
apply (unfold lesubstep_type_def)
|
|
194 |
apply clarify
|
|
195 |
apply (simp add: set_conv_nth)
|
|
196 |
apply clarify
|
|
197 |
apply (drule le_listD, assumption)
|
|
198 |
apply (clarsimp simp add: lesub_def Product.le_def)
|
|
199 |
apply (rule exI)
|
|
200 |
apply (rule conjI)
|
|
201 |
apply (rule exI)
|
|
202 |
apply (rule conjI)
|
|
203 |
apply (rule sym)
|
|
204 |
apply assumption
|
|
205 |
apply assumption
|
|
206 |
apply assumption
|
|
207 |
done
|
|
208 |
|
|
209 |
|
|
210 |
lemma eff_mono:
|
|
211 |
"\<lbrakk>p < length bs; s <=_(sup_state_opt G) t; app (bs!p) G maxs rT pc et t\<rbrakk>
|
|
212 |
\<Longrightarrow> eff (bs!p) G p et s <=|sup_state_opt G| eff (bs!p) G p et t"
|
|
213 |
apply (unfold eff_def)
|
|
214 |
apply (rule lesubstep_type_simple)
|
|
215 |
apply (rule le_list_appendI)
|
|
216 |
apply (simp add: norm_eff_def)
|
|
217 |
apply (rule le_listI)
|
|
218 |
apply simp
|
|
219 |
apply simp
|
|
220 |
apply (simp add: lesub_def)
|
|
221 |
apply (case_tac s)
|
|
222 |
apply simp
|
|
223 |
apply (simp del: split_paired_All split_paired_Ex)
|
|
224 |
apply (elim exE conjE)
|
|
225 |
apply simp
|
|
226 |
apply (drule eff'_mono, assumption)
|
|
227 |
apply assumption
|
|
228 |
apply (simp add: xcpt_eff_def)
|
|
229 |
apply (rule le_listI)
|
|
230 |
apply simp
|
|
231 |
apply simp
|
|
232 |
apply (simp add: lesub_def)
|
|
233 |
apply (case_tac s)
|
|
234 |
apply simp
|
|
235 |
apply simp
|
|
236 |
apply (case_tac t)
|
|
237 |
apply simp
|
|
238 |
apply (clarsimp simp add: sup_state_conv)
|
|
239 |
done
|
|
240 |
|
|
241 |
lemma order_sup_state_opt:
|
14045
|
242 |
"ws_prog G \<Longrightarrow> order (sup_state_opt G)"
|
13224
|
243 |
by (unfold sup_state_opt_unfold) (blast dest: acyclic_subcls1 order_widen)
|
|
244 |
|
|
245 |
theorem exec_mono:
|
14045
|
246 |
"ws_prog G \<Longrightarrow> bounded (exec G maxs rT et bs) (size bs) \<Longrightarrow>
|
13224
|
247 |
mono (JVMType.le G maxs maxr) (exec G maxs rT et bs) (size bs) (states G maxs maxr)"
|
|
248 |
apply (unfold exec_def JVM_le_unfold JVM_states_unfold)
|
|
249 |
apply (rule mono_lift)
|
|
250 |
apply (fold sup_state_opt_unfold opt_states_def)
|
|
251 |
apply (erule order_sup_state_opt)
|
|
252 |
apply (rule app_mono)
|
|
253 |
apply assumption
|
|
254 |
apply clarify
|
|
255 |
apply (rule eff_mono)
|
|
256 |
apply assumption+
|
|
257 |
done
|
|
258 |
|
|
259 |
theorem semilat_JVM_slI:
|
14045
|
260 |
"ws_prog G \<Longrightarrow> semilat (JVMType.sl G maxs maxr)"
|
13224
|
261 |
apply (unfold JVMType.sl_def stk_esl_def reg_sl_def)
|
|
262 |
apply (rule semilat_opt)
|
|
263 |
apply (rule err_semilat_Product_esl)
|
|
264 |
apply (rule err_semilat_upto_esl)
|
|
265 |
apply (rule err_semilat_JType_esl, assumption+)
|
|
266 |
apply (rule err_semilat_eslI)
|
|
267 |
apply (rule Listn_sl)
|
|
268 |
apply (rule err_semilat_JType_esl, assumption+)
|
|
269 |
done
|
|
270 |
|
|
271 |
lemma sl_triple_conv:
|
|
272 |
"JVMType.sl G maxs maxr ==
|
|
273 |
(states G maxs maxr, JVMType.le G maxs maxr, JVMType.sup G maxs maxr)"
|
|
274 |
by (simp (no_asm) add: states_def JVMType.le_def JVMType.sup_def)
|
|
275 |
|
|
276 |
|
|
277 |
lemma map_id [rule_format]:
|
|
278 |
"(\<forall>n < length xs. f (g (xs!n)) = xs!n) \<longrightarrow> map f (map g xs) = xs"
|
|
279 |
by (induct xs, auto)
|
|
280 |
|
|
281 |
|
|
282 |
lemma is_type_pTs:
|
|
283 |
"\<lbrakk> wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; ((mn,pTs),rT,code) \<in> set mdecls \<rbrakk>
|
|
284 |
\<Longrightarrow> set pTs \<subseteq> types G"
|
|
285 |
proof
|
|
286 |
assume "wf_prog wf_mb G"
|
|
287 |
"(C,S,fs,mdecls) \<in> set G"
|
|
288 |
"((mn,pTs),rT,code) \<in> set mdecls"
|
|
289 |
hence "wf_mdecl wf_mb G C ((mn,pTs),rT,code)"
|
14045
|
290 |
by (rule wf_prog_wf_mdecl)
|
13224
|
291 |
hence "\<forall>t \<in> set pTs. is_type G t"
|
|
292 |
by (unfold wf_mdecl_def wf_mhead_def) auto
|
|
293 |
moreover
|
|
294 |
fix t assume "t \<in> set pTs"
|
|
295 |
ultimately
|
|
296 |
have "is_type G t" by blast
|
|
297 |
thus "t \<in> types G" ..
|
|
298 |
qed
|
|
299 |
|
|
300 |
|
|
301 |
lemma jvm_prog_lift:
|
|
302 |
assumes wf:
|
|
303 |
"wf_prog (\<lambda>G C bd. P G C bd) G"
|
|
304 |
|
|
305 |
assumes rule:
|
|
306 |
"\<And>wf_mb C mn pTs C rT maxs maxl b et bd.
|
|
307 |
wf_prog wf_mb G \<Longrightarrow>
|
|
308 |
method (G,C) (mn,pTs) = Some (C,rT,maxs,maxl,b,et) \<Longrightarrow>
|
|
309 |
is_class G C \<Longrightarrow>
|
|
310 |
set pTs \<subseteq> types G \<Longrightarrow>
|
|
311 |
bd = ((mn,pTs),rT,maxs,maxl,b,et) \<Longrightarrow>
|
|
312 |
P G C bd \<Longrightarrow>
|
|
313 |
Q G C bd"
|
|
314 |
|
|
315 |
shows
|
|
316 |
"wf_prog (\<lambda>G C bd. Q G C bd) G"
|
|
317 |
proof -
|
|
318 |
from wf show ?thesis
|
|
319 |
apply (unfold wf_prog_def wf_cdecl_def)
|
|
320 |
apply clarsimp
|
|
321 |
apply (drule bspec, assumption)
|
14045
|
322 |
apply (unfold wf_cdecl_mdecl_def)
|
13224
|
323 |
apply clarsimp
|
|
324 |
apply (drule bspec, assumption)
|
14045
|
325 |
apply (frule methd [OF wf [THEN wf_prog_ws_prog]], assumption+)
|
13224
|
326 |
apply (frule is_type_pTs [OF wf], assumption+)
|
|
327 |
apply clarify
|
|
328 |
apply (drule rule [OF wf], assumption+)
|
|
329 |
apply (rule refl)
|
|
330 |
apply assumption+
|
|
331 |
done
|
|
332 |
qed
|
|
333 |
|
|
334 |
end
|