(* Title: HOL/Bali/Trans.thy Author: David von Oheimb and Norbert Schirmer
Operational transition (small-step) semantics of the execution of Java expressions and statements
PRELIMINARY!!!!!!!!
*)
theory Trans imports Evaln begin
definition
groundVar :: "var \ bool" where "groundVar v \ (case v of
LVar ln \<Rightarrow> True
| {accC,statDeclC,stat}e..fn \<Rightarrow> \<exists> a. e=Lit a
| e1.[e2] \<Rightarrow> \<exists> a i. e1= Lit a \<and> e2 = Lit i
| InsInitV c v \<Rightarrow> False)"
lemma groundVar_cases: assumes ground: "groundVar v" obtains (LVar) ln where"v=LVar ln"
| (FVar) accC statDeclC stat a fn where"v={accC,statDeclC,stat}(Lit a)..fn"
| (AVar) a i where"v=(Lit a).[Lit i]" using ground LVar FVar AVar by (cases v) (auto simp add: groundVar_def)
definition
groundExprs :: "expr list \ bool" where"groundExprs es \ (\e \ set es. \v. e = Lit v)"
primrec the_var:: "prog \ state \ var \ (vvar \ state)" where "the_var G s (LVar ln) = (lvar ln (store s),s)"
| the_var_FVar_def: "the_var G s ({accC,statDeclC,stat}a..fn) =fvar statDeclC stat fn (the_val a) s"
| the_var_AVar_def: "the_var G s(a.[i]) =avar G (the_val i) (the_val a) s"
lemma the_var_FVar_simp[simp]: "the_var G s ({accC,statDeclC,stat}(Lit a)..fn) = fvar statDeclC stat fn a s" by (simp) declare the_var_FVar_def [simp del]
lemma the_var_AVar_simp: "the_var G s ((Lit a).[Lit i]) = avar G i a s" by (simp) declare the_var_AVar_def [simp del]
inductive
step :: "[prog,term \ state,term \ state] \ bool" (\_\_ \1 _\[61,82,82] 81) for G :: prog where
(* evaluation of expression *) (* cf. 15.5 *)
Abrupt: "\\v. t \ \Lit v\; \<forall> t. t \<noteq> \<langle>l\<bullet> Skip\<rangle>; \<forall> C vn c. t \<noteq> \<langle>Try Skip Catch(C vn) c\<rangle>; \<forall> x c. t \<noteq> \<langle>Skip Finally c\<rangle> \<and> xc \<noteq> Xcpt x; \<forall> a c. t \<noteq> \<langle>FinA a c\<rangle>\<rbrakk> \<Longrightarrow>
G\<turnstile>(t,Some xc,s) \<mapsto>1 (\<langle>Lit undefined\<rangle>,Some xc,s)"
| InsInitE: "\G\(\c\,Norm s) \1 (\c'\, s')\ \<Longrightarrow>
G\<turnstile>(\<langle>InsInitE c e\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE c' e\<rangle>, s')"
| Methd: "G\(\Methd D sig\,Norm s) \1 (\body G D sig\,Norm s)"
| Body: "G\(\Body D c\,Norm s) \1 (\InsInitE (Init D) (Body D c)\,Norm s)"
| InsInitBody: "\G\(\c\,Norm s) \1 (\c'\,s')\ \<Longrightarrow>
G\<turnstile>(\<langle>InsInitE Skip (Body D c)\<rangle>,Norm s) \<mapsto>1(\<langle>InsInitE Skip (Body D c')\<rangle>,s')"
| InsInitBodyRet: "G\(\InsInitE Skip (Body D Skip)\,Norm s) \<mapsto>1 (\<langle>Lit (the ((locals s) Result))\<rangle>,abupd (absorb Ret) (Norm s))"
(* LVar: "G\<turnstile>(LVar vn,Norm s)" is already evaluated *)
| FVar: "\\ inited statDeclC (globs s)\ \<Longrightarrow>
G\<turnstile>(\<langle>{accC,statDeclC,stat}e..fn\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitV (Init statDeclC) ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s)"
| InsInitFVarE: "\G\(\e\,Norm s) \1 (\e'\,s')\ \<Longrightarrow>
G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitV Skip ({accC,statDeclC,stat}e'..fn)\<rangle>,s')"
| InsInitFVar: "G\(\InsInitV Skip ({accC,statDeclC,stat}Lit a..fn)\,Norm s) \<mapsto>1 (\<langle>{accC,statDeclC,stat}Lit a..fn\<rangle>,Norm s)" \<comment> \<open>Notice, that we do not have literal values for \<open>vars\<close>.
The rules for accessing variables (\<open>Acc\<close>) and assigning to variables
(\<open>Ass\<close>), test this with the predicate \<open>groundVar\<close>. After
initialisation isdoneand the \<open>FVar\<close> is evaluated, we can't just
throw away the \<open>InsInitFVar\<close> term and return a literal value, as in the
cases of \<open>New\<close> or \<open>NewC\<close>. Instead we just return the evaluated \<open>FVar\<close> and test for initialisation in the rule \<open>FVar\<close>.\<close>
| Fin: "G\(\Skip Finally c2\,(a,s)) \1 (\FinA a c2\,Norm s)"
| FinAC: "\G\(\c\,s) \1 (\c'\,s')\ \<Longrightarrow>
G\<turnstile>(\<langle>FinA a c\<rangle>,s) \<mapsto>1 (\<langle>FinA a c'\<rangle>,s')"
| FinA: "G\(\FinA a Skip\,s) \1 (\Skip\,abupd (abrupt_if (a\None) a) s)"
| Init1: "\inited C (globs s)\ \<Longrightarrow>
G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)"
| Init: "\the (class G C)=c; \ inited C (globs s)\ \<Longrightarrow>
G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>(if C = Object then Skip else (Init (super c)));;
Expr (Callee (locals s) (InsInitE (init c) SKIP))\<rangle>
,Norm (init_class_obj G C s))" \<comment> \<open>\<open>InsInitE\<close> is just used as trick to embed the statement \<open>init c\<close> into an expression\<close>
| InsInitESKIP: "G\(\InsInitE Skip SKIP\,Norm s) \1 (\SKIP\,Norm s)"
abbreviation
stepn:: "[prog, term \ state,nat,term \ state] \ bool" (\_\_ \_ _\[61,82,82] 81) where"G\p \n p' \ (p,p') \ {(x, y). step G x y}^^n"
abbreviation
steptr:: "[prog,term \ state,term \ state] \ bool" (\_\_ \* _\[61,82,82] 81) where"G\p \* p' \ (p,p') \ {(x, y). step G x y}\<^sup>*"
(* Equivalenzen: Bigstep zu Smallstep komplett. Smallstep zu Bigstep, nur wenn nicht die Ausdrücke Callee, FinA ,\<dots>
*)
(* lemma imp_eval_trans: assumes eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" shows trans: "G\<turnstile>(t,s0) \<mapsto>* (\<langle>Lit v\<rangle>,s1)"
*) (* Jetzt muss man bei trans natürlich wieder unterscheiden: Stmt, Expr, Var! Sowas blödes: Am besten den Terminus ground auf Var,Stmt,Expr hochziehen und dann the_vals definieren\<dots> G\<turnstile>(t,s0) \<mapsto>* (t',s1) \<and> the_vals t' = v
*)
end
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.