# HG changeset patch # User kleing # Date 1011129690 -3600 # Node ID 7b7051ae49a04dd3182e24b63d892f141f8ff873 # Parent fc3a6054907534103acd5eef980eabcb31ac8150 tuned for directly executable definitions diff -r fc3a60549075 -r 7b7051ae49a0 src/HOL/MicroJava/BV/Effect.thy --- a/src/HOL/MicroJava/BV/Effect.thy Tue Jan 15 21:09:31 2002 +0100 +++ b/src/HOL/MicroJava/BV/Effect.thy Tue Jan 15 22:21:30 2002 +0100 @@ -6,7 +6,7 @@ header {* Effect of Instructions on the State Type *} -theory Effect = JVMType + JVMExec: +theory Effect = JVMType + JVMExceptions: types succ_type = "(p_count \ state_type option) list" @@ -97,6 +97,23 @@ eff :: "instr => jvm_prog => p_count => exception_table => state_type option => succ_type" "eff i G pc et s == (map (\pc'. (pc',norm_eff i G s)) (succs i pc)) @ (xcpt_eff i G pc s et)" +constdefs + isPrimT :: "ty \ bool" + "isPrimT T == case T of PrimT T' \ True | RefT T' \ False" + + isRefT :: "ty \ bool" + "isRefT T == case T of PrimT T' \ False | RefT T' \ True" + +lemma isPrimT [simp]: + "isPrimT T = (\T'. T = PrimT T')" by (simp add: isPrimT_def split: ty.splits) + +lemma isRefT [simp]: + "isRefT T = (\T'. T = RefT T')" by (simp add: isRefT_def split: ty.splits) + + +lemma "list_all2 P a b \ \(x,y) \ set (zip a b). P x y" + by (simp add: list_all2_def) + text "Conditions under which eff is applicable:" consts @@ -126,23 +143,22 @@ "app' (Swap, G, maxs, rT, (ts1#ts2#ST,LT)) = True" "app' (IAdd, G, maxs, rT, (PrimT Integer#PrimT Integer#ST,LT)) = True" -"app' (Ifcmpeq b, G, maxs, rT, (ts#ts'#ST,LT)) = ((\p. ts = PrimT p \ ts' = PrimT p) \ - (\r r'. ts = RefT r \ ts' = RefT r'))" +"app' (Ifcmpeq b, G, maxs, rT, (ts#ts'#ST,LT)) = (isPrimT ts \ ts' = ts \ + isRefT ts \ isRefT ts')" "app' (Goto b, G, maxs, rT, s) = True" "app' (Return, G, maxs, rT, (T#ST,LT)) = (G \ T \ rT)" -"app' (Throw, G, maxs, rT, (T#ST,LT)) = (\r. T = RefT r)" +"app' (Throw, G, maxs, rT, (T#ST,LT)) = isRefT T" + "app' (Invoke C mn fpTs, G, maxs, rT, s) = (length fpTs < length (fst s) \ (let apTs = rev (take (length fpTs) (fst s)); X = hd (drop (length fpTs) (fst s)) in - G \ X \ Class C \ is_class G C \ method (G,C) (mn,fpTs) \ None \ - (\(aT,fT)\set(zip apTs fpTs). G \ aT \ fT)))" - + G \ X \ Class C \ is_class G C \ method (G,C) (mn,fpTs) \ None \ + list_all2 (\x y. G \ x \ y) apTs fpTs))" + "app' (i,G,maxs,rT,s) = False" - - constdefs xcpt_app :: "instr \ jvm_prog \ nat \ exception_table \ bool" "xcpt_app i G pc et \ \C\set(xcpt_names (i,G,pc,et)). is_class G C" @@ -276,8 +292,7 @@ lemma appIfcmpeq[simp]: "app (Ifcmpeq b) G maxs rT pc et (Some s) = (\ts1 ts2 ST LT. s = (ts1#ts2#ST,LT) \ ((\ p. ts1 = PrimT p \ ts2 = PrimT p) \ (\r r'. ts1 = RefT r \ ts2 = RefT r')))" - by (cases s, cases "2 T ST LT. s = (T#ST,LT) \ (G \ T \ rT))" @@ -299,6 +314,7 @@ method (G,C) (mn,fpTs) = Some (mD', rT', b') \ (\C \ set (match_any G pc et). is_class G C))" (is "?app s = ?P s") proof (cases (open) s) + note list_all2_def [simp] case Pair have "?app (a,b) ==> ?P (a,b)" proof - @@ -323,17 +339,26 @@ show ?thesis by (unfold app_def, clarsimp) blast qed with Pair - have "?app s ==> ?P s" by simp + have "?app s \ ?P s" by (simp only:) moreover - have "?P s \ ?app s" by (unfold app_def) clarsimp + have "?P s \ ?app s" by (unfold app_def) (clarsimp simp add: min_def) ultimately - show ?thesis by blast + show ?thesis by (rule iffI) qed lemma effNone: "(pc', s') \ set (eff i G pc et None) \ s' = None" by (auto simp add: eff_def xcpt_eff_def norm_eff_def) + +text {* some helpers to make the specification directly executable: *} +declare list_all2_Nil [code] +declare list_all2_Cons [code] + +lemma xcpt_app_lemma [code]: + "xcpt_app i G pc et = list_all (is_class G) (xcpt_names (i, G, pc, et))" + by (simp add: list_all_conv) + lemmas [simp del] = app_def xcpt_app_def end