src/HOL/Bali/Eval.thy
changeset 62042 6c6ccf573479
parent 61989 ba8c284d4725
child 62390 842917225d56
equal deleted inserted replaced
62041:52a87574bca9 62042:6c6ccf573479
     1 (*  Title:      HOL/Bali/Eval.thy
     1 (*  Title:      HOL/Bali/Eval.thy
     2     Author:     David von Oheimb
     2     Author:     David von Oheimb
     3 *)
     3 *)
     4 subsection {* Operational evaluation (big-step) semantics of Java expressions and 
     4 subsection \<open>Operational evaluation (big-step) semantics of Java expressions and 
     5           statements
     5           statements
     6 *}
     6 \<close>
     7 
     7 
     8 theory Eval imports State DeclConcepts begin
     8 theory Eval imports State DeclConcepts begin
     9 
     9 
    10 text {*
    10 text \<open>
    11 
    11 
    12 improvements over Java Specification 1.0:
    12 improvements over Java Specification 1.0:
    13 \begin{itemize}
    13 \begin{itemize}
    14 \item dynamic method lookup does not need to consider the return type 
    14 \item dynamic method lookup does not need to consider the return type 
    15       (cf.15.11.4.4)
    15       (cf.15.11.4.4)
    55   \item[++] faciliates exception handling
    55   \item[++] faciliates exception handling
    56   \item[+]  symmetry
    56   \item[+]  symmetry
    57   \end{itemize}
    57   \end{itemize}
    58 \item the rules are defined carefully in order to be applicable even in not
    58 \item the rules are defined carefully in order to be applicable even in not
    59   type-correct situations (yielding undefined values),
    59   type-correct situations (yielding undefined values),
    60   e.g. @{text "the_Addr (Val (Bool b)) = undefined"}.
    60   e.g. \<open>the_Addr (Val (Bool b)) = undefined\<close>.
    61   \begin{itemize}
    61   \begin{itemize}
    62   \item[++] fewer rules 
    62   \item[++] fewer rules 
    63   \item[-]  less readable because of auxiliary functions like @{text the_Addr}
    63   \item[-]  less readable because of auxiliary functions like \<open>the_Addr\<close>
    64   \end{itemize}
    64   \end{itemize}
    65   Alternative: "defensive" evaluation throwing some InternalError exception
    65   Alternative: "defensive" evaluation throwing some InternalError exception
    66                in case of (impossible, for correct programs) type mismatches
    66                in case of (impossible, for correct programs) type mismatches
    67 \item there is exactly one rule per syntactic construct
    67 \item there is exactly one rule per syntactic construct
    68   \begin{itemize}
    68   \begin{itemize}
    79   \item[-]  requires an auxiliary execution relation
    79   \item[-]  requires an auxiliary execution relation
    80   \item[++] avoids copies of allocation code and awkward case distinctions 
    80   \item[++] avoids copies of allocation code and awkward case distinctions 
    81            (whether there is enough memory to allocate the exception) in 
    81            (whether there is enough memory to allocate the exception) in 
    82             evaluation rules
    82             evaluation rules
    83   \end{itemize}
    83   \end{itemize}
    84 \item unfortunately @{text new_Addr} is not directly executable because of 
    84 \item unfortunately \<open>new_Addr\<close> is not directly executable because of 
    85       Hilbert operator.
    85       Hilbert operator.
    86 \end{itemize}
    86 \end{itemize}
    87 simplifications:
    87 simplifications:
    88 \begin{itemize}
    88 \begin{itemize}
    89 \item local variables are initialized with default values 
    89 \item local variables are initialized with default values 
    91 \item garbage collection not considered, therefore also no finalizers
    91 \item garbage collection not considered, therefore also no finalizers
    92 \item stack overflow and memory overflow during class initialization not 
    92 \item stack overflow and memory overflow during class initialization not 
    93       modelled
    93       modelled
    94 \item exceptions in initializations not replaced by ExceptionInInitializerError
    94 \item exceptions in initializations not replaced by ExceptionInInitializerError
    95 \end{itemize}
    95 \end{itemize}
    96 *}
    96 \<close>
    97 
    97 
    98 
    98 
    99 type_synonym vvar = "val \<times> (val \<Rightarrow> state \<Rightarrow> state)"
    99 type_synonym vvar = "val \<times> (val \<Rightarrow> state \<Rightarrow> state)"
   100 type_synonym vals = "(val, vvar, val list) sum3"
   100 type_synonym vals = "(val, vvar, val list) sum3"
   101 translations
   101 translations
   102   (type) "vvar" <= (type) "val \<times> (val \<Rightarrow> state \<Rightarrow> state)"
   102   (type) "vvar" <= (type) "val \<times> (val \<Rightarrow> state \<Rightarrow> state)"
   103   (type) "vals" <= (type) "(val, vvar, val list) sum3" 
   103   (type) "vals" <= (type) "(val, vvar, val list) sum3" 
   104 
   104 
   105 text {* To avoid redundancy and to reduce the number of rules, there is only 
   105 text \<open>To avoid redundancy and to reduce the number of rules, there is only 
   106  one evaluation rule for each syntactic term. This is also true for variables
   106  one evaluation rule for each syntactic term. This is also true for variables
   107  (e.g. see the rules below for @{text LVar}, @{text FVar} and @{text AVar}). 
   107  (e.g. see the rules below for \<open>LVar\<close>, \<open>FVar\<close> and \<open>AVar\<close>). 
   108  So evaluation of a variable must capture both possible further uses: 
   108  So evaluation of a variable must capture both possible further uses: 
   109  read (rule @{text Acc}) or write (rule @{text Ass}) to the variable. 
   109  read (rule \<open>Acc\<close>) or write (rule \<open>Ass\<close>) to the variable. 
   110  Therefor a variable evaluates to a special value @{term vvar}, which is 
   110  Therefor a variable evaluates to a special value @{term vvar}, which is 
   111  a pair, consisting of the current value (for later read access) and an update 
   111  a pair, consisting of the current value (for later read access) and an update 
   112  function (for later write access). Because
   112  function (for later write access). Because
   113  during assignment to an array variable an exception may occur if the types
   113  during assignment to an array variable an exception may occur if the types
   114  don't match, the update function is very generic: it transforms the 
   114  don't match, the update function is very generic: it transforms the 
   120  the whole induction.
   120  the whole induction.
   121  So for future approaches it may be better not to take
   121  So for future approaches it may be better not to take
   122  such a generic update function, but only to store the address and the kind
   122  such a generic update function, but only to store the address and the kind
   123  of variable (array (+ element type), local variable or field) for later 
   123  of variable (array (+ element type), local variable or field) for later 
   124  assignment. 
   124  assignment. 
   125 *}
   125 \<close>
   126 
   126 
   127 abbreviation
   127 abbreviation
   128   dummy_res :: "vals" ("\<diamondsuit>")
   128   dummy_res :: "vals" ("\<diamondsuit>")
   129   where "\<diamondsuit> == In1 Unit"
   129   where "\<diamondsuit> == In1 Unit"
   130 
   130 
   353                    \<Rightarrow> (if mode=Static then None else Some a'))
   353                    \<Rightarrow> (if mode=Static then None else Some a'))
   354       in set_lvars l (if mode = Static then x else np a' x,s))"
   354       in set_lvars l (if mode = Static then x else np a' x,s))"
   355 
   355 
   356 
   356 
   357 
   357 
   358 lemma init_lvars_def2: --{* better suited for simplification *} 
   358 lemma init_lvars_def2: \<comment>\<open>better suited for simplification\<close> 
   359 "init_lvars G C sig mode a' pvs (x,s) =  
   359 "init_lvars G C sig mode a' pvs (x,s) =  
   360   set_lvars 
   360   set_lvars 
   361     (\<lambda> k. 
   361     (\<lambda> k. 
   362        (case k of
   362        (case k of
   363           EName e 
   363           EName e 
   376   body :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> expr" where
   376   body :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> expr" where
   377  "body G C sig =
   377  "body G C sig =
   378     (let m = the (methd G C sig) 
   378     (let m = the (methd G C sig) 
   379      in Body (declclass m) (stmt (mbody (mthd m))))"
   379      in Body (declclass m) (stmt (mbody (mthd m))))"
   380 
   380 
   381 lemma body_def2: --{* better suited for simplification *} 
   381 lemma body_def2: \<comment>\<open>better suited for simplification\<close> 
   382 "body G C sig = Body  (declclass (the (methd G C sig))) 
   382 "body G C sig = Body  (declclass (the (methd G C sig))) 
   383                       (stmt (mbody (mthd (the (methd G C sig)))))"
   383                       (stmt (mbody (mthd (the (methd G C sig)))))"
   384 apply (unfold body_def Let_def)
   384 apply (unfold body_def Let_def)
   385 apply auto
   385 apply auto
   386 done
   386 done
   410               f = (\<lambda>v (x,s). (raise_if (\<not>G,s\<turnstile>v fits T) 
   410               f = (\<lambda>v (x,s). (raise_if (\<not>G,s\<turnstile>v fits T) 
   411                                            ArrStore x
   411                                            ArrStore x
   412                               ,upd_gobj oref n v s)) 
   412                               ,upd_gobj oref n v s)) 
   413      in ((the (cs n),f),abupd (raise_if (\<not>i in_bounds k) IndOutBound \<circ> np a') s))"
   413      in ((the (cs n),f),abupd (raise_if (\<not>i in_bounds k) IndOutBound \<circ> np a') s))"
   414 
   414 
   415 lemma fvar_def2: --{* better suited for simplification *} 
   415 lemma fvar_def2: \<comment>\<open>better suited for simplification\<close> 
   416 "fvar C stat fn a' s =  
   416 "fvar C stat fn a' s =  
   417   ((the 
   417   ((the 
   418      (values 
   418      (values 
   419       (the (globs (store s) (if stat then Stat C else Heap (the_Addr a')))) 
   419       (the (globs (store s) (if stat then Stat C else Heap (the_Addr a')))) 
   420       (Inl (fn,C)))
   420       (Inl (fn,C)))
   425   "
   425   "
   426 apply (unfold fvar_def)
   426 apply (unfold fvar_def)
   427 apply (simp (no_asm) add: Let_def split_beta)
   427 apply (simp (no_asm) add: Let_def split_beta)
   428 done
   428 done
   429 
   429 
   430 lemma avar_def2: --{* better suited for simplification *} 
   430 lemma avar_def2: \<comment>\<open>better suited for simplification\<close> 
   431 "avar G i' a' s =  
   431 "avar G i' a' s =  
   432   ((the ((snd(snd(the_Arr (globs (store s) (Heap (the_Addr a')))))) 
   432   ((the ((snd(snd(the_Arr (globs (store s) (Heap (the_Addr a')))))) 
   433            (Inr (the_Intg i')))
   433            (Inr (the_Intg i')))
   434    ,(\<lambda>v (x,s').  (raise_if (\<not>G,s'\<turnstile>v fits (fst(the_Arr (globs (store s)
   434    ,(\<lambda>v (x,s').  (raise_if (\<not>G,s'\<turnstile>v fits (fst(the_Arr (globs (store s)
   435                                                    (Heap (the_Addr a')))))) 
   435                                                    (Heap (the_Addr a')))))) 
   469        
   469        
   470 subsubsection "evaluation judgments"
   470 subsubsection "evaluation judgments"
   471 
   471 
   472 inductive
   472 inductive
   473   halloc :: "[prog,state,obj_tag,loc,state]\<Rightarrow>bool" ("_\<turnstile>_ \<midarrow>halloc _\<succ>_\<rightarrow> _"[61,61,61,61,61]60) for G::prog
   473   halloc :: "[prog,state,obj_tag,loc,state]\<Rightarrow>bool" ("_\<turnstile>_ \<midarrow>halloc _\<succ>_\<rightarrow> _"[61,61,61,61,61]60) for G::prog
   474 where --{* allocating objects on the heap, cf. 12.5 *}
   474 where \<comment>\<open>allocating objects on the heap, cf. 12.5\<close>
   475 
   475 
   476   Abrupt: 
   476   Abrupt: 
   477   "G\<turnstile>(Some x,s) \<midarrow>halloc oi\<succ>undefined\<rightarrow> (Some x,s)"
   477   "G\<turnstile>(Some x,s) \<midarrow>halloc oi\<succ>undefined\<rightarrow> (Some x,s)"
   478 
   478 
   479 | New:    "\<lbrakk>new_Addr (heap s) = Some a; 
   479 | New:    "\<lbrakk>new_Addr (heap s) = Some a; 
   481                        else (Some (Xcpt (Loc a)),CInst (SXcpt OutOfMemory)))\<rbrakk>
   481                        else (Some (Xcpt (Loc a)),CInst (SXcpt OutOfMemory)))\<rbrakk>
   482             \<Longrightarrow>
   482             \<Longrightarrow>
   483             G\<turnstile>Norm s \<midarrow>halloc oi\<succ>a\<rightarrow> (x,init_obj G oi' (Heap a) s)"
   483             G\<turnstile>Norm s \<midarrow>halloc oi\<succ>a\<rightarrow> (x,init_obj G oi' (Heap a) s)"
   484 
   484 
   485 inductive sxalloc :: "[prog,state,state]\<Rightarrow>bool" ("_\<turnstile>_ \<midarrow>sxalloc\<rightarrow> _"[61,61,61]60) for G::prog
   485 inductive sxalloc :: "[prog,state,state]\<Rightarrow>bool" ("_\<turnstile>_ \<midarrow>sxalloc\<rightarrow> _"[61,61,61]60) for G::prog
   486 where --{* allocating exception objects for
   486 where \<comment>\<open>allocating exception objects for
   487   standard exceptions (other than OutOfMemory) *}
   487   standard exceptions (other than OutOfMemory)\<close>
   488 
   488 
   489   Norm:  "G\<turnstile> Norm              s   \<midarrow>sxalloc\<rightarrow>  Norm             s"
   489   Norm:  "G\<turnstile> Norm              s   \<midarrow>sxalloc\<rightarrow>  Norm             s"
   490 
   490 
   491 | Jmp:   "G\<turnstile>(Some (Jump j), s)  \<midarrow>sxalloc\<rightarrow> (Some (Jump j), s)"
   491 | Jmp:   "G\<turnstile>(Some (Jump j), s)  \<midarrow>sxalloc\<rightarrow> (Some (Jump j), s)"
   492 
   492 
   511   "G\<turnstile>s \<midarrow>c    \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In1r c\<succ>\<rightarrow> (\<diamondsuit>,  s')"
   511   "G\<turnstile>s \<midarrow>c    \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In1r c\<succ>\<rightarrow> (\<diamondsuit>,  s')"
   512 | "G\<turnstile>s \<midarrow>e-\<succ>v \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In1l e\<succ>\<rightarrow> (In1 v,  s')"
   512 | "G\<turnstile>s \<midarrow>e-\<succ>v \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In1l e\<succ>\<rightarrow> (In1 v,  s')"
   513 | "G\<turnstile>s \<midarrow>e=\<succ>vf\<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In2  e\<succ>\<rightarrow> (In2 vf, s')"
   513 | "G\<turnstile>s \<midarrow>e=\<succ>vf\<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In2  e\<succ>\<rightarrow> (In2 vf, s')"
   514 | "G\<turnstile>s \<midarrow>e\<doteq>\<succ>v \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In3  e\<succ>\<rightarrow> (In3 v,  s')"
   514 | "G\<turnstile>s \<midarrow>e\<doteq>\<succ>v \<rightarrow>     s' \<equiv> G\<turnstile>s \<midarrow>In3  e\<succ>\<rightarrow> (In3 v,  s')"
   515 
   515 
   516 --{* propagation of abrupt completion *}
   516 \<comment>\<open>propagation of abrupt completion\<close>
   517 
   517 
   518   --{* cf. 14.1, 15.5 *}
   518   \<comment>\<open>cf. 14.1, 15.5\<close>
   519 | Abrupt: 
   519 | Abrupt: 
   520    "G\<turnstile>(Some xc,s) \<midarrow>t\<succ>\<rightarrow> (undefined3 t, (Some xc, s))"
   520    "G\<turnstile>(Some xc,s) \<midarrow>t\<succ>\<rightarrow> (undefined3 t, (Some xc, s))"
   521 
   521 
   522 
   522 
   523 --{* execution of statements *}
   523 \<comment>\<open>execution of statements\<close>
   524 
   524 
   525   --{* cf. 14.5 *}
   525   \<comment>\<open>cf. 14.5\<close>
   526 | Skip:                             "G\<turnstile>Norm s \<midarrow>Skip\<rightarrow> Norm s"
   526 | Skip:                             "G\<turnstile>Norm s \<midarrow>Skip\<rightarrow> Norm s"
   527 
   527 
   528   --{* cf. 14.7 *}
   528   \<comment>\<open>cf. 14.7\<close>
   529 | Expr: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   529 | Expr: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   530                                   G\<turnstile>Norm s0 \<midarrow>Expr e\<rightarrow> s1"
   530                                   G\<turnstile>Norm s0 \<midarrow>Expr e\<rightarrow> s1"
   531 
   531 
   532 | Lab:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c \<rightarrow> s1\<rbrakk> \<Longrightarrow>
   532 | Lab:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c \<rightarrow> s1\<rbrakk> \<Longrightarrow>
   533                                 G\<turnstile>Norm s0 \<midarrow>l\<bullet> c\<rightarrow> abupd (absorb l) s1"
   533                                 G\<turnstile>Norm s0 \<midarrow>l\<bullet> c\<rightarrow> abupd (absorb l) s1"
   534   --{* cf. 14.2 *}
   534   \<comment>\<open>cf. 14.2\<close>
   535 | Comp: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1 \<rightarrow> s1;
   535 | Comp: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1 \<rightarrow> s1;
   536           G\<turnstile>     s1 \<midarrow>c2 \<rightarrow> s2\<rbrakk> \<Longrightarrow>
   536           G\<turnstile>     s1 \<midarrow>c2 \<rightarrow> s2\<rbrakk> \<Longrightarrow>
   537                                  G\<turnstile>Norm s0 \<midarrow>c1;; c2\<rightarrow> s2"
   537                                  G\<turnstile>Norm s0 \<midarrow>c1;; c2\<rightarrow> s2"
   538 
   538 
   539   --{* cf. 14.8.2 *}
   539   \<comment>\<open>cf. 14.8.2\<close>
   540 | If:   "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1;
   540 | If:   "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1;
   541           G\<turnstile>     s1\<midarrow>(if the_Bool b then c1 else c2)\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   541           G\<turnstile>     s1\<midarrow>(if the_Bool b then c1 else c2)\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   542                        G\<turnstile>Norm s0 \<midarrow>If(e) c1 Else c2 \<rightarrow> s2"
   542                        G\<turnstile>Norm s0 \<midarrow>If(e) c1 Else c2 \<rightarrow> s2"
   543 
   543 
   544   --{* cf. 14.10, 14.10.1 *}
   544   \<comment>\<open>cf. 14.10, 14.10.1\<close>
   545   
   545   
   546   --{* A continue jump from the while body @{term c} is handled by 
   546   \<comment>\<open>A continue jump from the while body @{term c} is handled by 
   547      this rule. If a continue jump with the proper label was invoked inside 
   547      this rule. If a continue jump with the proper label was invoked inside 
   548      @{term c} this label (Cont l) is deleted out of the abrupt component of 
   548      @{term c} this label (Cont l) is deleted out of the abrupt component of 
   549      the state before the iterative evaluation of the while statement.
   549      the state before the iterative evaluation of the while statement.
   550      A break jump is handled by the Lab Statement @{text "Lab l (while\<dots>)"}.
   550      A break jump is handled by the Lab Statement \<open>Lab l (while\<dots>)\<close>.
   551   *}
   551 \<close>
   552 | Loop: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1;
   552 | Loop: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1;
   553           if the_Bool b 
   553           if the_Bool b 
   554              then (G\<turnstile>s1 \<midarrow>c\<rightarrow> s2 \<and> 
   554              then (G\<turnstile>s1 \<midarrow>c\<rightarrow> s2 \<and> 
   555                    G\<turnstile>(abupd (absorb (Cont l)) s2) \<midarrow>l\<bullet> While(e) c\<rightarrow> s3)
   555                    G\<turnstile>(abupd (absorb (Cont l)) s2) \<midarrow>l\<bullet> While(e) c\<rightarrow> s3)
   556              else s3 = s1\<rbrakk> \<Longrightarrow>
   556              else s3 = s1\<rbrakk> \<Longrightarrow>
   557                               G\<turnstile>Norm s0 \<midarrow>l\<bullet> While(e) c\<rightarrow> s3"
   557                               G\<turnstile>Norm s0 \<midarrow>l\<bullet> While(e) c\<rightarrow> s3"
   558 
   558 
   559 | Jmp: "G\<turnstile>Norm s \<midarrow>Jmp j\<rightarrow> (Some (Jump j), s)"
   559 | Jmp: "G\<turnstile>Norm s \<midarrow>Jmp j\<rightarrow> (Some (Jump j), s)"
   560    
   560    
   561   --{* cf. 14.16 *}
   561   \<comment>\<open>cf. 14.16\<close>
   562 | Throw: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   562 | Throw: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   563                                  G\<turnstile>Norm s0 \<midarrow>Throw e\<rightarrow> abupd (throw a') s1"
   563                                  G\<turnstile>Norm s0 \<midarrow>Throw e\<rightarrow> abupd (throw a') s1"
   564 
   564 
   565   --{* cf. 14.18.1 *}
   565   \<comment>\<open>cf. 14.18.1\<close>
   566 | Try:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1; G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2; 
   566 | Try:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1; G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2; 
   567           if G,s2\<turnstile>catch C then G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<rightarrow> s3 else s3 = s2\<rbrakk> \<Longrightarrow>
   567           if G,s2\<turnstile>catch C then G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<rightarrow> s3 else s3 = s2\<rbrakk> \<Longrightarrow>
   568                   G\<turnstile>Norm s0 \<midarrow>Try c1 Catch(C vn) c2\<rightarrow> s3"
   568                   G\<turnstile>Norm s0 \<midarrow>Try c1 Catch(C vn) c2\<rightarrow> s3"
   569 
   569 
   570   --{* cf. 14.18.2 *}
   570   \<comment>\<open>cf. 14.18.2\<close>
   571 | Fin:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> (x1,s1);
   571 | Fin:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> (x1,s1);
   572           G\<turnstile>Norm s1 \<midarrow>c2\<rightarrow> s2;
   572           G\<turnstile>Norm s1 \<midarrow>c2\<rightarrow> s2;
   573           s3=(if (\<exists> err. x1=Some (Error err)) 
   573           s3=(if (\<exists> err. x1=Some (Error err)) 
   574               then (x1,s1) 
   574               then (x1,s1) 
   575               else abupd (abrupt_if (x1\<noteq>None) x1) s2) \<rbrakk> 
   575               else abupd (abrupt_if (x1\<noteq>None) x1) s2) \<rbrakk> 
   576           \<Longrightarrow>
   576           \<Longrightarrow>
   577           G\<turnstile>Norm s0 \<midarrow>c1 Finally c2\<rightarrow> s3"
   577           G\<turnstile>Norm s0 \<midarrow>c1 Finally c2\<rightarrow> s3"
   578   --{* cf. 12.4.2, 8.5 *}
   578   \<comment>\<open>cf. 12.4.2, 8.5\<close>
   579 | Init: "\<lbrakk>the (class G C) = c;
   579 | Init: "\<lbrakk>the (class G C) = c;
   580           if inited C (globs s0) then s3 = Norm s0
   580           if inited C (globs s0) then s3 = Norm s0
   581           else (G\<turnstile>Norm (init_class_obj G C s0) 
   581           else (G\<turnstile>Norm (init_class_obj G C s0) 
   582                   \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1 \<and>
   582                   \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1 \<and>
   583                G\<turnstile>set_lvars empty s1 \<midarrow>init c\<rightarrow> s2 \<and> s3 = restore_lvars s1 s2)\<rbrakk> 
   583                G\<turnstile>set_lvars empty s1 \<midarrow>init c\<rightarrow> s2 \<and> s3 = restore_lvars s1 s2)\<rbrakk> 
   584               \<Longrightarrow>
   584               \<Longrightarrow>
   585                  G\<turnstile>Norm s0 \<midarrow>Init C\<rightarrow> s3"
   585                  G\<turnstile>Norm s0 \<midarrow>Init C\<rightarrow> s3"
   586    --{* This class initialisation rule is a little bit inaccurate. Look at the
   586    \<comment>\<open>This class initialisation rule is a little bit inaccurate. Look at the
   587       exact sequence:
   587       exact sequence:
   588       (1) The current class object (the static fields) are initialised
   588       (1) The current class object (the static fields) are initialised
   589            (@{text init_class_obj}),
   589            (\<open>init_class_obj\<close>),
   590       (2) the superclasses are initialised,
   590       (2) the superclasses are initialised,
   591       (3) the static initialiser of the current class is invoked.
   591       (3) the static initialiser of the current class is invoked.
   592       More precisely we should expect another ordering, namely 2 1 3.
   592       More precisely we should expect another ordering, namely 2 1 3.
   593       But we can't just naively toggle 1 and 2. By calling 
   593       But we can't just naively toggle 1 and 2. By calling 
   594       @{text init_class_obj} 
   594       \<open>init_class_obj\<close> 
   595       before initialising the superclasses, we also implicitly record that
   595       before initialising the superclasses, we also implicitly record that
   596       we have started to initialise the current class (by setting an 
   596       we have started to initialise the current class (by setting an 
   597       value for the class object). This becomes 
   597       value for the class object). This becomes 
   598       crucial for the completeness proof of the axiomatic semantics 
   598       crucial for the completeness proof of the axiomatic semantics 
   599       @{text "AxCompl.thy"}. Static initialisation requires an induction on 
   599       \<open>AxCompl.thy\<close>. Static initialisation requires an induction on 
   600       the number of classes not yet initialised (or to be more precise, 
   600       the number of classes not yet initialised (or to be more precise, 
   601       classes were the initialisation has not yet begun). 
   601       classes were the initialisation has not yet begun). 
   602       So we could first assign a dummy value to the class before
   602       So we could first assign a dummy value to the class before
   603       superclass initialisation and afterwards set the correct values.
   603       superclass initialisation and afterwards set the correct values.
   604       But as long as we don't take memory overflow into account 
   604       But as long as we don't take memory overflow into account 
   605       when allocating class objects, we can leave things as they are for 
   605       when allocating class objects, we can leave things as they are for 
   606       convenience. 
   606       convenience. 
   607    *}
   607 \<close>
   608 --{* evaluation of expressions *}
   608 \<comment>\<open>evaluation of expressions\<close>
   609 
   609 
   610   --{* cf. 15.8.1, 12.4.1 *}
   610   \<comment>\<open>cf. 15.8.1, 12.4.1\<close>
   611 | NewC: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init C\<rightarrow> s1;
   611 | NewC: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init C\<rightarrow> s1;
   612           G\<turnstile>     s1 \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   612           G\<turnstile>     s1 \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   613                                   G\<turnstile>Norm s0 \<midarrow>NewC C-\<succ>Addr a\<rightarrow> s2"
   613                                   G\<turnstile>Norm s0 \<midarrow>NewC C-\<succ>Addr a\<rightarrow> s2"
   614 
   614 
   615   --{* cf. 15.9.1, 12.4.1 *}
   615   \<comment>\<open>cf. 15.9.1, 12.4.1\<close>
   616 | NewA: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>init_comp_ty T\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>i'\<rightarrow> s2; 
   616 | NewA: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>init_comp_ty T\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>i'\<rightarrow> s2; 
   617           G\<turnstile>abupd (check_neg i') s2 \<midarrow>halloc (Arr T (the_Intg i'))\<succ>a\<rightarrow> s3\<rbrakk> \<Longrightarrow>
   617           G\<turnstile>abupd (check_neg i') s2 \<midarrow>halloc (Arr T (the_Intg i'))\<succ>a\<rightarrow> s3\<rbrakk> \<Longrightarrow>
   618                                 G\<turnstile>Norm s0 \<midarrow>New T[e]-\<succ>Addr a\<rightarrow> s3"
   618                                 G\<turnstile>Norm s0 \<midarrow>New T[e]-\<succ>Addr a\<rightarrow> s3"
   619 
   619 
   620   --{* cf. 15.15 *}
   620   \<comment>\<open>cf. 15.15\<close>
   621 | Cast: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1;
   621 | Cast: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1;
   622           s2 = abupd (raise_if (\<not>G,store s1\<turnstile>v fits T) ClassCast) s1\<rbrakk> \<Longrightarrow>
   622           s2 = abupd (raise_if (\<not>G,store s1\<turnstile>v fits T) ClassCast) s1\<rbrakk> \<Longrightarrow>
   623                                 G\<turnstile>Norm s0 \<midarrow>Cast T e-\<succ>v\<rightarrow> s2"
   623                                 G\<turnstile>Norm s0 \<midarrow>Cast T e-\<succ>v\<rightarrow> s2"
   624 
   624 
   625   --{* cf. 15.19.2 *}
   625   \<comment>\<open>cf. 15.19.2\<close>
   626 | Inst: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1;
   626 | Inst: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1;
   627           b = (v\<noteq>Null \<and> G,store s1\<turnstile>v fits RefT T)\<rbrakk> \<Longrightarrow>
   627           b = (v\<noteq>Null \<and> G,store s1\<turnstile>v fits RefT T)\<rbrakk> \<Longrightarrow>
   628                               G\<turnstile>Norm s0 \<midarrow>e InstOf T-\<succ>Bool b\<rightarrow> s1"
   628                               G\<turnstile>Norm s0 \<midarrow>e InstOf T-\<succ>Bool b\<rightarrow> s1"
   629 
   629 
   630   --{* cf. 15.7.1 *}
   630   \<comment>\<open>cf. 15.7.1\<close>
   631 | Lit:  "G\<turnstile>Norm s \<midarrow>Lit v-\<succ>v\<rightarrow> Norm s"
   631 | Lit:  "G\<turnstile>Norm s \<midarrow>Lit v-\<succ>v\<rightarrow> Norm s"
   632 
   632 
   633 | UnOp: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1\<rbrakk> 
   633 | UnOp: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1\<rbrakk> 
   634          \<Longrightarrow> G\<turnstile>Norm s0 \<midarrow>UnOp unop e-\<succ>(eval_unop unop v)\<rightarrow> s1"
   634          \<Longrightarrow> G\<turnstile>Norm s0 \<midarrow>UnOp unop e-\<succ>(eval_unop unop v)\<rightarrow> s1"
   635  
   635  
   637           G\<turnstile>s1 \<midarrow>(if need_second_arg binop v1 then (In1l e2) else (In1r Skip))
   637           G\<turnstile>s1 \<midarrow>(if need_second_arg binop v1 then (In1l e2) else (In1r Skip))
   638                 \<succ>\<rightarrow> (In1 v2, s2)
   638                 \<succ>\<rightarrow> (In1 v2, s2)
   639           \<rbrakk> 
   639           \<rbrakk> 
   640          \<Longrightarrow> G\<turnstile>Norm s0 \<midarrow>BinOp binop e1 e2-\<succ>(eval_binop binop v1 v2)\<rightarrow> s2"
   640          \<Longrightarrow> G\<turnstile>Norm s0 \<midarrow>BinOp binop e1 e2-\<succ>(eval_binop binop v1 v2)\<rightarrow> s2"
   641    
   641    
   642   --{* cf. 15.10.2 *}
   642   \<comment>\<open>cf. 15.10.2\<close>
   643 | Super: "G\<turnstile>Norm s \<midarrow>Super-\<succ>val_this s\<rightarrow> Norm s"
   643 | Super: "G\<turnstile>Norm s \<midarrow>Super-\<succ>val_this s\<rightarrow> Norm s"
   644 
   644 
   645   --{* cf. 15.2 *}
   645   \<comment>\<open>cf. 15.2\<close>
   646 | Acc:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(v,f)\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   646 | Acc:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(v,f)\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   647                                   G\<turnstile>Norm s0 \<midarrow>Acc va-\<succ>v\<rightarrow> s1"
   647                                   G\<turnstile>Norm s0 \<midarrow>Acc va-\<succ>v\<rightarrow> s1"
   648 
   648 
   649   --{* cf. 15.25.1 *}
   649   \<comment>\<open>cf. 15.25.1\<close>
   650 | Ass:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(w,f)\<rightarrow> s1;
   650 | Ass:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(w,f)\<rightarrow> s1;
   651           G\<turnstile>     s1 \<midarrow>e-\<succ>v  \<rightarrow> s2\<rbrakk> \<Longrightarrow>
   651           G\<turnstile>     s1 \<midarrow>e-\<succ>v  \<rightarrow> s2\<rbrakk> \<Longrightarrow>
   652                                    G\<turnstile>Norm s0 \<midarrow>va:=e-\<succ>v\<rightarrow> assign f v s2"
   652                                    G\<turnstile>Norm s0 \<midarrow>va:=e-\<succ>v\<rightarrow> assign f v s2"
   653 
   653 
   654   --{* cf. 15.24 *}
   654   \<comment>\<open>cf. 15.24\<close>
   655 | Cond: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<rightarrow> s1;
   655 | Cond: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<rightarrow> s1;
   656           G\<turnstile>     s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   656           G\<turnstile>     s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   657                             G\<turnstile>Norm s0 \<midarrow>e0 ? e1 : e2-\<succ>v\<rightarrow> s2"
   657                             G\<turnstile>Norm s0 \<midarrow>e0 ? e1 : e2-\<succ>v\<rightarrow> s2"
   658 
   658 
   659 
   659 
   660 -- {* The interplay of  @{term Call}, @{term Methd} and @{term Body}:
   660 \<comment> \<open>The interplay of  @{term Call}, @{term Methd} and @{term Body}:
   661       Method invocation is split up into these three rules:
   661       Method invocation is split up into these three rules:
   662       \begin{itemize}
   662       \begin{itemize}
   663       \item [@{term Call}] Calculates the target address and evaluates the
   663       \item [@{term Call}] Calculates the target address and evaluates the
   664                            arguments of the method, and then performs dynamic
   664                            arguments of the method, and then performs dynamic
   665                            or static lookup of the method, corresponding to the
   665                            or static lookup of the method, corresponding to the
   672       \item [@{term Body}] An extra syntactic entity for the unfolded method
   672       \item [@{term Body}] An extra syntactic entity for the unfolded method
   673                            body was introduced to properly trigger class 
   673                            body was introduced to properly trigger class 
   674                            initialisation. Without class initialisation we 
   674                            initialisation. Without class initialisation we 
   675                            could just evaluate the body statement. 
   675                            could just evaluate the body statement. 
   676       \end{itemize}
   676       \end{itemize}
   677    *}
   677 \<close>
   678   --{* cf. 15.11.4.1, 15.11.4.2, 15.11.4.4, 15.11.4.5 *}
   678   \<comment>\<open>cf. 15.11.4.1, 15.11.4.2, 15.11.4.4, 15.11.4.5\<close>
   679 | Call: 
   679 | Call: 
   680   "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1; G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2;
   680   "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1; G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2;
   681     D = invocation_declclass G mode (store s2) a' statT \<lparr>name=mn,parTs=pTs\<rparr>;
   681     D = invocation_declclass G mode (store s2) a' statT \<lparr>name=mn,parTs=pTs\<rparr>;
   682     s3=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs s2;
   682     s3=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs s2;
   683     s3' = check_method_access G accC statT mode \<lparr>name=mn,parTs=pTs\<rparr> a' s3;
   683     s3' = check_method_access G accC statT mode \<lparr>name=mn,parTs=pTs\<rparr> a' s3;
   684     G\<turnstile>s3' \<midarrow>Methd D \<lparr>name=mn,parTs=pTs\<rparr>-\<succ>v\<rightarrow> s4\<rbrakk>
   684     G\<turnstile>s3' \<midarrow>Methd D \<lparr>name=mn,parTs=pTs\<rparr>-\<succ>v\<rightarrow> s4\<rbrakk>
   685    \<Longrightarrow>
   685    \<Longrightarrow>
   686        G\<turnstile>Norm s0 \<midarrow>{accC,statT,mode}e\<cdot>mn({pTs}args)-\<succ>v\<rightarrow> (restore_lvars s2 s4)"
   686        G\<turnstile>Norm s0 \<midarrow>{accC,statT,mode}e\<cdot>mn({pTs}args)-\<succ>v\<rightarrow> (restore_lvars s2 s4)"
   687 --{* The accessibility check is after @{term init_lvars}, to keep it simple. 
   687 \<comment>\<open>The accessibility check is after @{term init_lvars}, to keep it simple. 
   688    @{term init_lvars} already tests for the absence of a null-pointer 
   688    @{term init_lvars} already tests for the absence of a null-pointer 
   689    reference in case of an instance method invocation.
   689    reference in case of an instance method invocation.
   690 *}
   690 \<close>
   691 
   691 
   692 | Methd:        "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>body G D sig-\<succ>v\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   692 | Methd:        "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>body G D sig-\<succ>v\<rightarrow> s1\<rbrakk> \<Longrightarrow>
   693                                 G\<turnstile>Norm s0 \<midarrow>Methd D sig-\<succ>v\<rightarrow> s1"
   693                                 G\<turnstile>Norm s0 \<midarrow>Methd D sig-\<succ>v\<rightarrow> s1"
   694   
   694   
   695 | Body: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init D\<rightarrow> s1; G\<turnstile>s1 \<midarrow>c\<rightarrow> s2; 
   695 | Body: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init D\<rightarrow> s1; G\<turnstile>s1 \<midarrow>c\<rightarrow> s2; 
   697                          abrupt s2 = Some (Jump (Cont l)))
   697                          abrupt s2 = Some (Jump (Cont l)))
   698                   then abupd (\<lambda> x. Some (Error CrossMethodJump)) s2 
   698                   then abupd (\<lambda> x. Some (Error CrossMethodJump)) s2 
   699                   else s2)\<rbrakk> \<Longrightarrow>
   699                   else s2)\<rbrakk> \<Longrightarrow>
   700            G\<turnstile>Norm s0 \<midarrow>Body D c-\<succ>the (locals (store s2) Result)
   700            G\<turnstile>Norm s0 \<midarrow>Body D c-\<succ>the (locals (store s2) Result)
   701               \<rightarrow>abupd (absorb Ret) s3"
   701               \<rightarrow>abupd (absorb Ret) s3"
   702   --{* cf. 14.15, 12.4.1 *}
   702   \<comment>\<open>cf. 14.15, 12.4.1\<close>
   703   --{* We filter out a break/continue in @{term s2}, so that we can proof 
   703   \<comment>\<open>We filter out a break/continue in @{term s2}, so that we can proof 
   704      definite assignment
   704      definite assignment
   705      correct, without the need of conformance of the state. By this the
   705      correct, without the need of conformance of the state. By this the
   706      different parts of the typesafety proof can be disentangled a little. *}
   706      different parts of the typesafety proof can be disentangled a little.\<close>
   707 
   707 
   708 --{* evaluation of variables *}
   708 \<comment>\<open>evaluation of variables\<close>
   709 
   709 
   710   --{* cf. 15.13.1, 15.7.2 *}
   710   \<comment>\<open>cf. 15.13.1, 15.7.2\<close>
   711 | LVar: "G\<turnstile>Norm s \<midarrow>LVar vn=\<succ>lvar vn s\<rightarrow> Norm s"
   711 | LVar: "G\<turnstile>Norm s \<midarrow>LVar vn=\<succ>lvar vn s\<rightarrow> Norm s"
   712 
   712 
   713   --{* cf. 15.10.1, 12.4.1 *}
   713   \<comment>\<open>cf. 15.10.1, 12.4.1\<close>
   714 | FVar: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2;
   714 | FVar: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2;
   715           (v,s2') = fvar statDeclC stat fn a s2;
   715           (v,s2') = fvar statDeclC stat fn a s2;
   716           s3 = check_field_access G accC statDeclC fn stat a s2' \<rbrakk> \<Longrightarrow>
   716           s3 = check_field_access G accC statDeclC fn stat a s2' \<rbrakk> \<Longrightarrow>
   717           G\<turnstile>Norm s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>v\<rightarrow> s3"
   717           G\<turnstile>Norm s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>v\<rightarrow> s3"
   718  --{* The accessibility check is after @{term fvar}, to keep it simple. 
   718  \<comment>\<open>The accessibility check is after @{term fvar}, to keep it simple. 
   719     @{term fvar} already tests for the absence of a null-pointer reference 
   719     @{term fvar} already tests for the absence of a null-pointer reference 
   720     in case of an instance field
   720     in case of an instance field
   721   *}
   721 \<close>
   722 
   722 
   723   --{* cf. 15.12.1, 15.25.1 *}
   723   \<comment>\<open>cf. 15.12.1, 15.25.1\<close>
   724 | AVar: "\<lbrakk>G\<turnstile> Norm s0 \<midarrow>e1-\<succ>a\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e2-\<succ>i\<rightarrow> s2;
   724 | AVar: "\<lbrakk>G\<turnstile> Norm s0 \<midarrow>e1-\<succ>a\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e2-\<succ>i\<rightarrow> s2;
   725           (v,s2') = avar G i a s2\<rbrakk> \<Longrightarrow>
   725           (v,s2') = avar G i a s2\<rbrakk> \<Longrightarrow>
   726                       G\<turnstile>Norm s0 \<midarrow>e1.[e2]=\<succ>v\<rightarrow> s2'"
   726                       G\<turnstile>Norm s0 \<midarrow>e1.[e2]=\<succ>v\<rightarrow> s2'"
   727 
   727 
   728 
   728 
   729 --{* evaluation of expression lists *}
   729 \<comment>\<open>evaluation of expression lists\<close>
   730 
   730 
   731   --{* cf. 15.11.4.2 *}
   731   \<comment>\<open>cf. 15.11.4.2\<close>
   732 | Nil:
   732 | Nil:
   733                                     "G\<turnstile>Norm s0 \<midarrow>[]\<doteq>\<succ>[]\<rightarrow> Norm s0"
   733                                     "G\<turnstile>Norm s0 \<midarrow>[]\<doteq>\<succ>[]\<rightarrow> Norm s0"
   734 
   734 
   735   --{* cf. 15.6.4 *}
   735   \<comment>\<open>cf. 15.6.4\<close>
   736 | Cons: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e -\<succ> v \<rightarrow> s1;
   736 | Cons: "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e -\<succ> v \<rightarrow> s1;
   737           G\<turnstile>     s1 \<midarrow>es\<doteq>\<succ>vs\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   737           G\<turnstile>     s1 \<midarrow>es\<doteq>\<succ>vs\<rightarrow> s2\<rbrakk> \<Longrightarrow>
   738                                    G\<turnstile>Norm s0 \<midarrow>e#es\<doteq>\<succ>v#vs\<rightarrow> s2"
   738                                    G\<turnstile>Norm s0 \<midarrow>e#es\<doteq>\<succ>v#vs\<rightarrow> s2"
   739 
   739 
   740 (* Rearrangement of premisses:
   740 (* Rearrangement of premisses:
   742  17(Lit),18(UnOp),19(BinOp),20(Super),21(Acc),3(Expr),5(Comp),25(Methd),26(Body),23(Cond),6(If),
   742  17(Lit),18(UnOp),19(BinOp),20(Super),21(Acc),3(Expr),5(Comp),25(Methd),26(Body),23(Cond),6(If),
   743  7(Loop),11(Fin),9(Throw),13(NewC),14(NewA),12(Init),22(Ass),10(Try),28(FVar),
   743  7(Loop),11(Fin),9(Throw),13(NewC),14(NewA),12(Init),22(Ass),10(Try),28(FVar),
   744  29(AVar),24(Call)]
   744  29(AVar),24(Call)]
   745 *)
   745 *)
   746 
   746 
   747 ML {*
   747 ML \<open>
   748 ML_Thms.bind_thm ("eval_induct", rearrange_prems 
   748 ML_Thms.bind_thm ("eval_induct", rearrange_prems 
   749 [0,1,2,8,4,30,31,27,15,16,
   749 [0,1,2,8,4,30,31,27,15,16,
   750  17,18,19,20,21,3,5,25,26,23,6,
   750  17,18,19,20,21,3,5,25,26,23,6,
   751  7,11,9,13,14,12,22,10,28,
   751  7,11,9,13,14,12,22,10,28,
   752  29,24] @{thm eval.induct})
   752  29,24] @{thm eval.induct})
   753 *}
   753 \<close>
   754 
   754 
   755 
   755 
   756 declare split_if     [split del] split_if_asm     [split del] 
   756 declare split_if     [split del] split_if_asm     [split del] 
   757         option.split [split del] option.split_asm [split del]
   757         option.split [split del] option.split_asm [split del]
   758 inductive_cases halloc_elim_cases: 
   758 inductive_cases halloc_elim_cases: 
   778 apply blast+
   778 apply blast+
   779 done
   779 done
   780 
   780 
   781 declare not_None_eq [simp del] (* IntDef.Zero_def [simp del] *)
   781 declare not_None_eq [simp del] (* IntDef.Zero_def [simp del] *)
   782 declare split_paired_All [simp del] split_paired_Ex [simp del]
   782 declare split_paired_All [simp del] split_paired_Ex [simp del]
   783 setup {* map_theory_simpset (fn ctxt => ctxt delloop "split_all_tac") *}
   783 setup \<open>map_theory_simpset (fn ctxt => ctxt delloop "split_all_tac")\<close>
   784 
   784 
   785 inductive_cases eval_cases: "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (v, s')"
   785 inductive_cases eval_cases: "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (v, s')"
   786 
   786 
   787 inductive_cases eval_elim_cases [cases set]:
   787 inductive_cases eval_elim_cases [cases set]:
   788         "G\<turnstile>(Some xc,s) \<midarrow>t                              \<succ>\<rightarrow> (v, s')"
   788         "G\<turnstile>(Some xc,s) \<midarrow>t                              \<succ>\<rightarrow> (v, s')"
   816         "G\<turnstile>Norm s \<midarrow>In2  (e1.[e2])                      \<succ>\<rightarrow> (v, s')"
   816         "G\<turnstile>Norm s \<midarrow>In2  (e1.[e2])                      \<succ>\<rightarrow> (v, s')"
   817         "G\<turnstile>Norm s \<midarrow>In1l ({accC,statT,mode}e\<cdot>mn({pT}p)) \<succ>\<rightarrow> (v, s')"
   817         "G\<turnstile>Norm s \<midarrow>In1l ({accC,statT,mode}e\<cdot>mn({pT}p)) \<succ>\<rightarrow> (v, s')"
   818         "G\<turnstile>Norm s \<midarrow>In1r (Init C)                       \<succ>\<rightarrow> (x, s')"
   818         "G\<turnstile>Norm s \<midarrow>In1r (Init C)                       \<succ>\<rightarrow> (x, s')"
   819 declare not_None_eq [simp]  (* IntDef.Zero_def [simp] *)
   819 declare not_None_eq [simp]  (* IntDef.Zero_def [simp] *)
   820 declare split_paired_All [simp] split_paired_Ex [simp]
   820 declare split_paired_All [simp] split_paired_Ex [simp]
   821 declaration {* K (Simplifier.map_ss (fn ss => ss addloop ("split_all_tac", split_all_tac))) *}
   821 declaration \<open>K (Simplifier.map_ss (fn ss => ss addloop ("split_all_tac", split_all_tac)))\<close>
   822 declare split_if     [split] split_if_asm     [split] 
   822 declare split_if     [split] split_if_asm     [split] 
   823         option.split [split] option.split_asm [split]
   823         option.split [split] option.split_asm [split]
   824 
   824 
   825 lemma eval_Inj_elim: 
   825 lemma eval_Inj_elim: 
   826  "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w,s') 
   826  "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w,s') 
   835 apply (induct_tac "t")
   835 apply (induct_tac "t")
   836 apply (rename_tac a, induct_tac "a")
   836 apply (rename_tac a, induct_tac "a")
   837 apply auto
   837 apply auto
   838 done
   838 done
   839 
   839 
   840 text {* The following simplification procedures set up the proper injections of
   840 text \<open>The following simplification procedures set up the proper injections of
   841  terms and their corresponding values in the evaluation relation:
   841  terms and their corresponding values in the evaluation relation:
   842  E.g. an expression 
   842  E.g. an expression 
   843  (injection @{term In1l} into terms) always evaluates to ordinary values 
   843  (injection @{term In1l} into terms) always evaluates to ordinary values 
   844  (injection @{term In1} into generalised values @{term vals}). 
   844  (injection @{term In1} into generalised values @{term vals}). 
   845 *}
   845 \<close>
   846 
   846 
   847 lemma eval_expr_eq: "G\<turnstile>s \<midarrow>In1l t\<succ>\<rightarrow> (w, s') = (\<exists>v. w=In1 v \<and> G\<turnstile>s \<midarrow>t-\<succ>v \<rightarrow> s')"
   847 lemma eval_expr_eq: "G\<turnstile>s \<midarrow>In1l t\<succ>\<rightarrow> (w, s') = (\<exists>v. w=In1 v \<and> G\<turnstile>s \<midarrow>t-\<succ>v \<rightarrow> s')"
   848   by (auto, frule eval_Inj_elim, auto)
   848   by (auto, frule eval_Inj_elim, auto)
   849 
   849 
   850 lemma eval_var_eq: "G\<turnstile>s \<midarrow>In2 t\<succ>\<rightarrow> (w, s') = (\<exists>vf. w=In2 vf \<and> G\<turnstile>s \<midarrow>t=\<succ>vf\<rightarrow> s')"
   850 lemma eval_var_eq: "G\<turnstile>s \<midarrow>In2 t\<succ>\<rightarrow> (w, s') = (\<exists>vf. w=In2 vf \<and> G\<turnstile>s \<midarrow>t=\<succ>vf\<rightarrow> s')"
   854   by (auto, frule eval_Inj_elim, auto)
   854   by (auto, frule eval_Inj_elim, auto)
   855 
   855 
   856 lemma eval_stmt_eq: "G\<turnstile>s \<midarrow>In1r t\<succ>\<rightarrow> (w, s') = (w=\<diamondsuit> \<and> G\<turnstile>s \<midarrow>t \<rightarrow> s')"
   856 lemma eval_stmt_eq: "G\<turnstile>s \<midarrow>In1r t\<succ>\<rightarrow> (w, s') = (w=\<diamondsuit> \<and> G\<turnstile>s \<midarrow>t \<rightarrow> s')"
   857   by (auto, frule eval_Inj_elim, auto, frule eval_Inj_elim, auto)
   857   by (auto, frule eval_Inj_elim, auto, frule eval_Inj_elim, auto)
   858 
   858 
   859 simproc_setup eval_expr ("G\<turnstile>s \<midarrow>In1l t\<succ>\<rightarrow> (w, s')") = {*
   859 simproc_setup eval_expr ("G\<turnstile>s \<midarrow>In1l t\<succ>\<rightarrow> (w, s')") = \<open>
   860   fn _ => fn _ => fn ct =>
   860   fn _ => fn _ => fn ct =>
   861     (case Thm.term_of ct of
   861     (case Thm.term_of ct of
   862       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   862       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   863     | _ => SOME (mk_meta_eq @{thm eval_expr_eq})) *}
   863     | _ => SOME (mk_meta_eq @{thm eval_expr_eq}))\<close>
   864 
   864 
   865 simproc_setup eval_var ("G\<turnstile>s \<midarrow>In2 t\<succ>\<rightarrow> (w, s')") = {*
   865 simproc_setup eval_var ("G\<turnstile>s \<midarrow>In2 t\<succ>\<rightarrow> (w, s')") = \<open>
   866   fn _ => fn _ => fn ct =>
   866   fn _ => fn _ => fn ct =>
   867     (case Thm.term_of ct of
   867     (case Thm.term_of ct of
   868       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   868       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   869     | _ => SOME (mk_meta_eq @{thm eval_var_eq})) *}
   869     | _ => SOME (mk_meta_eq @{thm eval_var_eq}))\<close>
   870 
   870 
   871 simproc_setup eval_exprs ("G\<turnstile>s \<midarrow>In3 t\<succ>\<rightarrow> (w, s')") = {*
   871 simproc_setup eval_exprs ("G\<turnstile>s \<midarrow>In3 t\<succ>\<rightarrow> (w, s')") = \<open>
   872   fn _ => fn _ => fn ct =>
   872   fn _ => fn _ => fn ct =>
   873     (case Thm.term_of ct of
   873     (case Thm.term_of ct of
   874       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   874       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   875     | _ => SOME (mk_meta_eq @{thm eval_exprs_eq})) *}
   875     | _ => SOME (mk_meta_eq @{thm eval_exprs_eq}))\<close>
   876 
   876 
   877 simproc_setup eval_stmt ("G\<turnstile>s \<midarrow>In1r t\<succ>\<rightarrow> (w, s')") = {*
   877 simproc_setup eval_stmt ("G\<turnstile>s \<midarrow>In1r t\<succ>\<rightarrow> (w, s')") = \<open>
   878   fn _ => fn _ => fn ct =>
   878   fn _ => fn _ => fn ct =>
   879     (case Thm.term_of ct of
   879     (case Thm.term_of ct of
   880       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   880       (_ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
   881     | _ => SOME (mk_meta_eq @{thm eval_stmt_eq})) *}
   881     | _ => SOME (mk_meta_eq @{thm eval_stmt_eq}))\<close>
   882 
   882 
   883 ML {*
   883 ML \<open>
   884 ML_Thms.bind_thms ("AbruptIs", sum3_instantiate @{context} @{thm eval.Abrupt})
   884 ML_Thms.bind_thms ("AbruptIs", sum3_instantiate @{context} @{thm eval.Abrupt})
   885 *}
   885 \<close>
   886 
   886 
   887 declare halloc.Abrupt [intro!] eval.Abrupt [intro!]  AbruptIs [intro!]
   887 declare halloc.Abrupt [intro!] eval.Abrupt [intro!]  AbruptIs [intro!]
   888 
   888 
   889 text{* @{text Callee},@{text InsInitE}, @{text InsInitV}, @{text FinA} are only
   889 text\<open>\<open>Callee\<close>,\<open>InsInitE\<close>, \<open>InsInitV\<close>, \<open>FinA\<close> are only
   890 used in smallstep semantics, not in the bigstep semantics. So their is no
   890 used in smallstep semantics, not in the bigstep semantics. So their is no
   891 valid evaluation of these terms 
   891 valid evaluation of these terms 
   892 *}
   892 \<close>
   893 
   893 
   894 
   894 
   895 lemma eval_Callee: "G\<turnstile>Norm s\<midarrow>Callee l e-\<succ>v\<rightarrow> s' = False"
   895 lemma eval_Callee: "G\<turnstile>Norm s\<midarrow>Callee l e-\<succ>v\<rightarrow> s' = False"
   896 proof -
   896 proof -
   897   { fix s t v s'
   897   { fix s t v s'
   950         (x = None \<and> G\<turnstile>Norm s \<midarrow>t\<succ>\<rightarrow> (w,Norm s'))"
   950         (x = None \<and> G\<turnstile>Norm s \<midarrow>t\<succ>\<rightarrow> (w,Norm s'))"
   951 apply auto
   951 apply auto
   952 apply (frule eval_no_abrupt_lemma, auto)+
   952 apply (frule eval_no_abrupt_lemma, auto)+
   953 done
   953 done
   954 
   954 
   955 simproc_setup eval_no_abrupt ("G\<turnstile>(x,s) \<midarrow>e\<succ>\<rightarrow> (w,Norm s')") = {*
   955 simproc_setup eval_no_abrupt ("G\<turnstile>(x,s) \<midarrow>e\<succ>\<rightarrow> (w,Norm s')") = \<open>
   956   fn _ => fn _ => fn ct =>
   956   fn _ => fn _ => fn ct =>
   957     (case Thm.term_of ct of
   957     (case Thm.term_of ct of
   958       (_ $ _ $ (Const (@{const_name Pair}, _) $ (Const (@{const_name None}, _)) $ _) $ _  $ _ $ _) => NONE
   958       (_ $ _ $ (Const (@{const_name Pair}, _) $ (Const (@{const_name None}, _)) $ _) $ _  $ _ $ _) => NONE
   959     | _ => SOME (mk_meta_eq @{thm eval_no_abrupt}))
   959     | _ => SOME (mk_meta_eq @{thm eval_no_abrupt}))
   960 *}
   960 \<close>
   961 
   961 
   962 
   962 
   963 lemma eval_abrupt_lemma: 
   963 lemma eval_abrupt_lemma: 
   964   "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (v,s') \<Longrightarrow> abrupt s=Some xc \<longrightarrow> s'= s \<and> v = undefined3 t"
   964   "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (v,s') \<Longrightarrow> abrupt s=Some xc \<longrightarrow> s'= s \<and> v = undefined3 t"
   965 by (erule eval_cases, auto)
   965 by (erule eval_cases, auto)
   970      G\<turnstile>(Some xc,s) \<midarrow>t\<succ>\<rightarrow> (undefined3 t,(Some xc,s)))"
   970      G\<turnstile>(Some xc,s) \<midarrow>t\<succ>\<rightarrow> (undefined3 t,(Some xc,s)))"
   971 apply auto
   971 apply auto
   972 apply (frule eval_abrupt_lemma, auto)+
   972 apply (frule eval_abrupt_lemma, auto)+
   973 done
   973 done
   974 
   974 
   975 simproc_setup eval_abrupt ("G\<turnstile>(Some xc,s) \<midarrow>e\<succ>\<rightarrow> (w,s')") = {*
   975 simproc_setup eval_abrupt ("G\<turnstile>(Some xc,s) \<midarrow>e\<succ>\<rightarrow> (w,s')") = \<open>
   976   fn _ => fn _ => fn ct =>
   976   fn _ => fn _ => fn ct =>
   977     (case Thm.term_of ct of
   977     (case Thm.term_of ct of
   978       (_ $ _ $ _ $ _ $ _ $ (Const (@{const_name Pair}, _) $ (Const (@{const_name Some}, _) $ _)$ _)) => NONE
   978       (_ $ _ $ _ $ _ $ _ $ (Const (@{const_name Pair}, _) $ (Const (@{const_name Some}, _) $ _)$ _)) => NONE
   979     | _ => SOME (mk_meta_eq @{thm eval_abrupt}))
   979     | _ => SOME (mk_meta_eq @{thm eval_abrupt}))
   980 *}
   980 \<close>
   981 
   981 
   982 lemma LitI: "G\<turnstile>s \<midarrow>Lit v-\<succ>(if normal s then v else undefined)\<rightarrow> s"
   982 lemma LitI: "G\<turnstile>s \<midarrow>Lit v-\<succ>(if normal s then v else undefined)\<rightarrow> s"
   983 apply (case_tac "s", case_tac "a = None")
   983 apply (case_tac "s", case_tac "a = None")
   984 by (auto intro!: eval.Lit)
   984 by (auto intro!: eval.Lit)
   985 
   985 
  1160 
  1160 
  1161 
  1161 
  1162 lemma unique_eval [rule_format (no_asm)]: 
  1162 lemma unique_eval [rule_format (no_asm)]: 
  1163   "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w, s') \<Longrightarrow> (\<forall>w' s''. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w', s'') \<longrightarrow> w' = w \<and> s'' = s')"
  1163   "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w, s') \<Longrightarrow> (\<forall>w' s''. G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w', s'') \<longrightarrow> w' = w \<and> s'' = s')"
  1164 apply (erule eval_induct)
  1164 apply (erule eval_induct)
  1165 apply (tactic {* ALLGOALS (EVERY'
  1165 apply (tactic \<open>ALLGOALS (EVERY'
  1166       [strip_tac @{context}, rotate_tac ~1, eresolve_tac @{context} @{thms eval_elim_cases}]) *})
  1166       [strip_tac @{context}, rotate_tac ~1, eresolve_tac @{context} @{thms eval_elim_cases}])\<close>)
  1167 (* 31 subgoals *)
  1167 (* 31 subgoals *)
  1168 prefer 28 (* Try *) 
  1168 prefer 28 (* Try *) 
  1169 apply (simp (no_asm_use) only: split add: split_if_asm)
  1169 apply (simp (no_asm_use) only: split add: split_if_asm)
  1170 (* 34 subgoals *)
  1170 (* 34 subgoals *)
  1171 prefer 30 (* Init *)
  1171 prefer 30 (* Init *)