src/HOL/Bali/Trans.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 40945 b8703f63bfb2
child 47176 568fdc70e565
permissions -rw-r--r--
Quotient_Info stores only relation maps
wenzelm@12857
     1
(*  Title:      HOL/Bali/Trans.thy
schirmer@13688
     2
    Author:     David von Oheimb and Norbert Schirmer
schirmer@12854
     3
schirmer@12854
     4
Operational transition (small-step) semantics of the 
schirmer@12854
     5
execution of Java expressions and statements
schirmer@12854
     6
schirmer@12854
     7
PRELIMINARY!!!!!!!!
schirmer@12854
     8
*)
schirmer@12854
     9
haftmann@16417
    10
theory Trans imports Evaln begin
schirmer@13337
    11
wenzelm@37956
    12
definition
wenzelm@37956
    13
  groundVar :: "var \<Rightarrow> bool" where
wenzelm@37956
    14
  "groundVar v \<longleftrightarrow> (case v of
wenzelm@37956
    15
                     LVar ln \<Rightarrow> True
wenzelm@37956
    16
                   | {accC,statDeclC,stat}e..fn \<Rightarrow> \<exists> a. e=Lit a
wenzelm@37956
    17
                   | e1.[e2] \<Rightarrow> \<exists> a i. e1= Lit a \<and> e2 = Lit i
wenzelm@37956
    18
                   | InsInitV c v \<Rightarrow> False)"
schirmer@13337
    19
schirmer@13337
    20
lemma groundVar_cases [consumes 1, case_names LVar FVar AVar]:
schirmer@13337
    21
  assumes ground: "groundVar v" and
schirmer@13337
    22
          LVar: "\<And> ln. \<lbrakk>v=LVar ln\<rbrakk> \<Longrightarrow> P" and
schirmer@13337
    23
          FVar: "\<And> accC statDeclC stat a fn. 
schirmer@13337
    24
                    \<lbrakk>v={accC,statDeclC,stat}(Lit a)..fn\<rbrakk> \<Longrightarrow> P" and
schirmer@13337
    25
          AVar: "\<And> a i. \<lbrakk>v=(Lit a).[Lit i]\<rbrakk> \<Longrightarrow> P"
schirmer@13337
    26
  shows "P"
schirmer@13337
    27
proof -
schirmer@13337
    28
  from ground LVar FVar AVar
schirmer@13337
    29
  show ?thesis
schirmer@13337
    30
    apply (cases v)
schirmer@13337
    31
    apply (simp add: groundVar_def)
schirmer@13337
    32
    apply (simp add: groundVar_def,blast)
schirmer@13337
    33
    apply (simp add: groundVar_def,blast)
schirmer@13337
    34
    apply (simp add: groundVar_def)
schirmer@13337
    35
    done
schirmer@13337
    36
qed
schirmer@13337
    37
wenzelm@37956
    38
definition
wenzelm@37956
    39
  groundExprs :: "expr list \<Rightarrow> bool"
wenzelm@37956
    40
  where "groundExprs es \<longleftrightarrow> (\<forall>e \<in> set es. \<exists>v. e = Lit v)"
schirmer@13337
    41
  
wenzelm@37956
    42
primrec the_val:: "expr \<Rightarrow> val"
wenzelm@37956
    43
  where "the_val (Lit v) = v"
schirmer@13337
    44
haftmann@37597
    45
primrec the_var:: "prog \<Rightarrow> state \<Rightarrow> var \<Rightarrow> (vvar \<times> state)" where
wenzelm@37956
    46
  "the_var G s (LVar ln) = (lvar ln (store s),s)"
haftmann@37597
    47
| the_var_FVar_def: "the_var G s ({accC,statDeclC,stat}a..fn) =fvar statDeclC stat fn (the_val a) s"
haftmann@37597
    48
| the_var_AVar_def: "the_var G s(a.[i])                       =avar G (the_val i) (the_val a) s"
schirmer@13337
    49
schirmer@13337
    50
lemma the_var_FVar_simp[simp]:
schirmer@13337
    51
"the_var G s ({accC,statDeclC,stat}(Lit a)..fn) = fvar statDeclC stat fn a s"
schirmer@13337
    52
by (simp)
schirmer@13337
    53
declare the_var_FVar_def [simp del]
schirmer@13337
    54
schirmer@13337
    55
lemma the_var_AVar_simp:
schirmer@13337
    56
"the_var G s ((Lit a).[Lit i]) = avar G i a s"
schirmer@13337
    57
by (simp)
schirmer@13337
    58
declare the_var_AVar_def [simp del]
schirmer@12854
    59
wenzelm@35067
    60
abbreviation
wenzelm@35067
    61
  Ref :: "loc \<Rightarrow> expr"
wenzelm@35067
    62
  where "Ref a == Lit (Addr a)"
schirmer@12854
    63
wenzelm@35067
    64
abbreviation
wenzelm@35067
    65
  SKIP :: "expr"
wenzelm@35067
    66
  where "SKIP == Lit Unit"
schirmer@12854
    67
berghofe@23747
    68
inductive
berghofe@21765
    69
  step :: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>1 _"[61,82,82] 81)
berghofe@21765
    70
  for G :: prog
berghofe@21765
    71
where
schirmer@12854
    72
schirmer@12854
    73
(* evaluation of expression *)
schirmer@12854
    74
  (* cf. 15.5 *)
berghofe@21765
    75
  Abrupt:       "\<lbrakk>\<forall>v. t \<noteq> \<langle>Lit v\<rangle>;
schirmer@13337
    76
                  \<forall> t. t \<noteq> \<langle>l\<bullet> Skip\<rangle>;
schirmer@13337
    77
                  \<forall> C vn c.  t \<noteq> \<langle>Try Skip Catch(C vn) c\<rangle>;
schirmer@13337
    78
                  \<forall> x c. t \<noteq> \<langle>Skip Finally c\<rangle> \<and> xc \<noteq> Xcpt x;
schirmer@13337
    79
                  \<forall> a c. t \<noteq> \<langle>FinA a c\<rangle>\<rbrakk> 
schirmer@13337
    80
                \<Longrightarrow> 
haftmann@28524
    81
                  G\<turnstile>(t,Some xc,s) \<mapsto>1 (\<langle>Lit undefined\<rangle>,Some xc,s)"
schirmer@12854
    82
berghofe@21765
    83
| InsInitE: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>, s')\<rbrakk>
berghofe@21765
    84
             \<Longrightarrow> 
berghofe@21765
    85
             G\<turnstile>(\<langle>InsInitE c e\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE c' e\<rangle>, s')"
schirmer@12854
    86
schirmer@13337
    87
(* SeqE: "G\<turnstile>(\<langle>Seq Skip e\<rangle>,Norm s) \<mapsto>1 (\<langle>e\<rangle>, Norm s)" *)
schirmer@13337
    88
(* Specialised rules to evaluate: 
schirmer@13337
    89
   InsInitE Skip (NewC C), InisInitE Skip (NewA T[e]) *)
schirmer@13337
    90
 
schirmer@13337
    91
  (* cf. 15.8.1 *)
berghofe@21765
    92
| NewC: "G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init C) (NewC C)\<rangle>, Norm s)"
berghofe@21765
    93
| NewCInited: "\<lbrakk>G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> 
berghofe@21765
    94
               \<Longrightarrow> 
berghofe@21765
    95
               G\<turnstile>(\<langle>InsInitE Skip (NewC C)\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')"
schirmer@12854
    96
schirmer@12854
    97
schirmer@12854
    98
schirmer@13337
    99
(* Alternative when rule SeqE is present 
schirmer@13337
   100
NewCInited: "\<lbrakk>inited C (globs s); 
schirmer@13337
   101
              G\<turnstile> Norm s \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s'\<rbrakk> 
schirmer@13337
   102
             \<Longrightarrow> 
schirmer@13337
   103
              G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>, s')"
schirmer@13337
   104
schirmer@13337
   105
NewC:
schirmer@13337
   106
     "\<lbrakk>\<not> inited C (globs s)\<rbrakk> 
schirmer@13337
   107
     \<Longrightarrow> 
schirmer@13337
   108
      G\<turnstile>(\<langle>NewC C\<rangle>,Norm s) \<mapsto>1 (\<langle>Seq (Init C) (NewC C)\<rangle>, Norm s)"
schirmer@13337
   109
schirmer@13337
   110
*)
schirmer@13337
   111
  (* cf. 15.9.1 *)
berghofe@21765
   112
| NewA: 
schirmer@13337
   113
   "G\<turnstile>(\<langle>New T[e]\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (init_comp_ty T) (New T[e])\<rangle>,Norm s)"
berghofe@21765
   114
| InsInitNewAIdx: 
schirmer@13337
   115
   "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>, s')\<rbrakk>
schirmer@13337
   116
    \<Longrightarrow>  
schirmer@13337
   117
    G\<turnstile>(\<langle>InsInitE Skip (New T[e])\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE Skip (New T[e'])\<rangle>,s')"
berghofe@21765
   118
| InsInitNewA: 
schirmer@13337
   119
   "\<lbrakk>G\<turnstile>abupd (check_neg i) (Norm s) \<midarrow>halloc (Arr T (the_Intg i))\<succ>a\<rightarrow> s' \<rbrakk>
schirmer@13337
   120
    \<Longrightarrow>
schirmer@13337
   121
    G\<turnstile>(\<langle>InsInitE Skip (New T[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Ref a\<rangle>,s')"
schirmer@13337
   122
 
schirmer@13337
   123
  (* cf. 15.15 *)
wenzelm@32960
   124
| CastE:
schirmer@13337
   125
   "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
schirmer@13337
   126
    \<Longrightarrow>
schirmer@13337
   127
    G\<turnstile>(\<langle>Cast T e\<rangle>,None,s) \<mapsto>1 (\<langle>Cast T e'\<rangle>,s')" 
wenzelm@32960
   128
| Cast:
schirmer@13337
   129
   "\<lbrakk>s' = abupd (raise_if (\<not>G,s\<turnstile>v fits T)  ClassCast) (Norm s)\<rbrakk> 
schirmer@13337
   130
    \<Longrightarrow> 
schirmer@13337
   131
    G\<turnstile>(\<langle>Cast T (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
schirmer@13337
   132
  (* can be written without abupd, since we know Norm s *)
schirmer@12854
   133
schirmer@12854
   134
berghofe@21765
   135
| InstE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> 
schirmer@13337
   136
        \<Longrightarrow> 
schirmer@13337
   137
        G\<turnstile>(\<langle>e InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')" 
berghofe@21765
   138
| Inst:  "\<lbrakk>b = (v\<noteq>Null \<and> G,s\<turnstile>v fits RefT T)\<rbrakk> 
berghofe@21765
   139
          \<Longrightarrow> 
berghofe@21765
   140
          G\<turnstile>(\<langle>(Lit v) InstOf T\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (Bool b)\<rangle>,s')"
schirmer@13337
   141
schirmer@13337
   142
  (* cf. 15.7.1 *)
wenzelm@32960
   143
(*Lit                           "G\<turnstile>(Lit v,None,s) \<mapsto>1 (Lit v,None,s)"*)
schirmer@13337
   144
berghofe@21765
   145
| UnOpE:  "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s') \<rbrakk>
schirmer@13337
   146
           \<Longrightarrow> 
berghofe@21765
   147
           G\<turnstile>(\<langle>UnOp unop e\<rangle>,Norm s) \<mapsto>1 (\<langle>UnOp unop e'\<rangle>,s')"
berghofe@21765
   148
| UnOp:   "G\<turnstile>(\<langle>UnOp unop (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (eval_unop unop v)\<rangle>,Norm s)"
berghofe@21765
   149
berghofe@21765
   150
| BinOpE1:  "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s') \<rbrakk>
berghofe@21765
   151
             \<Longrightarrow> 
berghofe@21765
   152
             G\<turnstile>(\<langle>BinOp binop e1 e2\<rangle>,Norm s) \<mapsto>1 (\<langle>BinOp binop e1' e2\<rangle>,s')"
berghofe@21765
   153
| BinOpE2:  "\<lbrakk>need_second_arg binop v1; G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') \<rbrakk>
schirmer@13384
   154
             \<Longrightarrow> 
schirmer@13384
   155
             G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) 
berghofe@21765
   156
              \<mapsto>1 (\<langle>BinOp binop (Lit v1) e2'\<rangle>,s')"
berghofe@21765
   157
| BinOpTerm:  "\<lbrakk>\<not> need_second_arg binop v1\<rbrakk>
berghofe@21765
   158
               \<Longrightarrow> 
berghofe@21765
   159
               G\<turnstile>(\<langle>BinOp binop (Lit v1) e2\<rangle>,Norm s) 
berghofe@21765
   160
                \<mapsto>1 (\<langle>Lit v1\<rangle>,Norm s)"
berghofe@21765
   161
| BinOp:    "G\<turnstile>(\<langle>BinOp binop (Lit v1) (Lit v2)\<rangle>,Norm s) 
berghofe@21765
   162
              \<mapsto>1 (\<langle>Lit (eval_binop binop v1 v2)\<rangle>,Norm s)"
schirmer@13384
   163
(* Maybe its more convenient to add: need_second_arg as precondition to BinOp 
schirmer@13384
   164
   to make the choice between BinOpTerm and BinOp deterministic *)
schirmer@13384
   165
   
berghofe@21765
   166
| Super: "G\<turnstile>(\<langle>Super\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (val_this s)\<rangle>,Norm s)"
schirmer@13337
   167
berghofe@21765
   168
| AccVA: "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s') \<rbrakk>
berghofe@21765
   169
          \<Longrightarrow> 
berghofe@21765
   170
          G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Acc va'\<rangle>,s')"
berghofe@21765
   171
| Acc:  "\<lbrakk>groundVar va; ((v,vf),s') = the_var G (Norm s) va\<rbrakk>
berghofe@21765
   172
         \<Longrightarrow>  
berghofe@21765
   173
         G\<turnstile>(\<langle>Acc va\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
schirmer@13337
   174
schirmer@13337
   175
(*
schirmer@13337
   176
AccLVar: "G\<turnstile>(\<langle>Acc (LVar vn)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit (fst (lvar vn s))\<rangle>,Norm s)"
schirmer@13337
   177
AccFVar: "\<lbrakk>((v,vf),s') = fvar statDeclC stat fn a (Norm s)\<rbrakk>
schirmer@13337
   178
          \<Longrightarrow>  
schirmer@13337
   179
          G\<turnstile>(\<langle>Acc ({accC,statDeclC,stat}(Lit a)..fn)\<rangle>,Norm s) 
schirmer@13337
   180
           \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
schirmer@13337
   181
AccAVar: "\<lbrakk>((v,vf),s') = avar G i a (Norm s)\<rbrakk>
schirmer@13337
   182
          \<Longrightarrow>  
schirmer@13337
   183
          G\<turnstile>(\<langle>Acc ((Lit a).[Lit i])\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,s')"
schirmer@13337
   184
*) 
berghofe@21765
   185
| AssVA:  "\<lbrakk>G\<turnstile>(\<langle>va\<rangle>,Norm s) \<mapsto>1 (\<langle>va'\<rangle>,s')\<rbrakk> 
berghofe@21765
   186
           \<Longrightarrow> 
berghofe@21765
   187
           G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va':=e\<rangle>,s')"
berghofe@21765
   188
| AssE:   "\<lbrakk>groundVar va; G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
berghofe@21765
   189
           \<Longrightarrow> 
berghofe@21765
   190
           G\<turnstile>(\<langle>va:=e\<rangle>,Norm s) \<mapsto>1 (\<langle>va:=e'\<rangle>,s')"
berghofe@21765
   191
| Ass:    "\<lbrakk>groundVar va; ((w,f),s') = the_var G (Norm s) va\<rbrakk> 
berghofe@21765
   192
           \<Longrightarrow> 
berghofe@21765
   193
           G\<turnstile>(\<langle>va:=(Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit v\<rangle>,assign f v s')"
schirmer@13337
   194
berghofe@21765
   195
| CondC: "\<lbrakk>G\<turnstile>(\<langle>e0\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'\<rangle>,s')\<rbrakk> 
berghofe@21765
   196
          \<Longrightarrow> 
berghofe@21765
   197
          G\<turnstile>(\<langle>e0? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e0'? e1:e2\<rangle>,s')"
berghofe@21765
   198
| Cond:  "G\<turnstile>(\<langle>Lit b? e1:e2\<rangle>,Norm s) \<mapsto>1 (\<langle>if the_Bool b then e1 else e2\<rangle>,Norm s)"
schirmer@13337
   199
schirmer@13337
   200
berghofe@21765
   201
| CallTarget: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
berghofe@21765
   202
               \<Longrightarrow>
berghofe@21765
   203
               G\<turnstile>(\<langle>{accC,statT,mode}e\<cdot>mn({pTs}args)\<rangle>,Norm s) 
berghofe@21765
   204
                \<mapsto>1 (\<langle>{accC,statT,mode}e'\<cdot>mn({pTs}args)\<rangle>,s')"
berghofe@21765
   205
| CallArgs:   "\<lbrakk>G\<turnstile>(\<langle>args\<rangle>,Norm s) \<mapsto>1 (\<langle>args'\<rangle>,s')\<rbrakk> 
berghofe@21765
   206
               \<Longrightarrow>
berghofe@21765
   207
               G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) 
berghofe@21765
   208
                \<mapsto>1 (\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args')\<rangle>,s')"
berghofe@21765
   209
| Call:       "\<lbrakk>groundExprs args; vs = map the_val args;
berghofe@21765
   210
                D = invocation_declclass G mode s a statT \<lparr>name=mn,parTs=pTs\<rparr>;
berghofe@21765
   211
                s'=init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs (Norm s)\<rbrakk> 
berghofe@21765
   212
               \<Longrightarrow> 
berghofe@21765
   213
               G\<turnstile>(\<langle>{accC,statT,mode}Lit a\<cdot>mn({pTs}args)\<rangle>,Norm s) 
berghofe@21765
   214
                \<mapsto>1 (\<langle>Callee (locals s) (Methd D \<lparr>name=mn,parTs=pTs\<rparr>)\<rangle>,s')"
schirmer@13337
   215
           
berghofe@21765
   216
| Callee:     "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk>
berghofe@21765
   217
               \<Longrightarrow> 
berghofe@21765
   218
               G\<turnstile>(\<langle>Callee lcls_caller e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')"
schirmer@13337
   219
berghofe@21765
   220
| CalleeRet:   "G\<turnstile>(\<langle>Callee lcls_caller (Lit v)\<rangle>,Norm s) 
berghofe@21765
   221
                 \<mapsto>1 (\<langle>Lit v\<rangle>,(set_lvars lcls_caller (Norm s)))"
schirmer@13337
   222
berghofe@21765
   223
| Methd: "G\<turnstile>(\<langle>Methd D sig\<rangle>,Norm s) \<mapsto>1 (\<langle>body G D sig\<rangle>,Norm s)"
schirmer@13337
   224
berghofe@21765
   225
| Body: "G\<turnstile>(\<langle>Body D c\<rangle>,Norm s) \<mapsto>1 (\<langle>InsInitE (Init D) (Body D c)\<rangle>,Norm s)"
schirmer@13337
   226
berghofe@21765
   227
| InsInitBody: 
schirmer@13337
   228
    "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk>
schirmer@13337
   229
     \<Longrightarrow> 
schirmer@13337
   230
     G\<turnstile>(\<langle>InsInitE Skip (Body D c)\<rangle>,Norm s) \<mapsto>1(\<langle>InsInitE Skip (Body D c')\<rangle>,s')"
berghofe@21765
   231
| InsInitBodyRet: 
schirmer@13337
   232
     "G\<turnstile>(\<langle>InsInitE Skip (Body D Skip)\<rangle>,Norm s)
schirmer@13337
   233
       \<mapsto>1 (\<langle>Lit (the ((locals s) Result))\<rangle>,abupd (absorb Ret) (Norm s))"
schirmer@13337
   234
schirmer@13337
   235
(*   LVar: "G\<turnstile>(LVar vn,Norm s)" is already evaluated *)
schirmer@13337
   236
  
berghofe@21765
   237
| FVar: "\<lbrakk>\<not> inited statDeclC (globs s)\<rbrakk>
berghofe@21765
   238
         \<Longrightarrow> 
berghofe@21765
   239
         G\<turnstile>(\<langle>{accC,statDeclC,stat}e..fn\<rangle>,Norm s) 
berghofe@21765
   240
          \<mapsto>1 (\<langle>InsInitV (Init statDeclC) ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s)"
berghofe@21765
   241
| InsInitFVarE:
schirmer@13337
   242
      "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk>
schirmer@13337
   243
       \<Longrightarrow>
schirmer@13337
   244
       G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}e..fn)\<rangle>,Norm s) 
schirmer@13337
   245
        \<mapsto>1 (\<langle>InsInitV Skip ({accC,statDeclC,stat}e'..fn)\<rangle>,s')"
berghofe@21765
   246
| InsInitFVar:
schirmer@13337
   247
      "G\<turnstile>(\<langle>InsInitV Skip ({accC,statDeclC,stat}Lit a..fn)\<rangle>,Norm s) 
schirmer@13337
   248
        \<mapsto>1 (\<langle>{accC,statDeclC,stat}Lit a..fn\<rangle>,Norm s)"
schirmer@13337
   249
--  {* Notice, that we do not have literal values for @{text vars}. 
schirmer@13337
   250
The rules for accessing variables (@{text Acc}) and assigning to variables 
schirmer@13337
   251
(@{text Ass}), test this with the predicate @{text groundVar}.  After 
schirmer@13337
   252
initialisation is done and the @{text FVar} is evaluated, we can't just 
schirmer@13337
   253
throw away the @{text InsInitFVar} term and return a literal value, as in the 
schirmer@13337
   254
cases of @{text New}  or @{text NewC}. Instead we just return the evaluated 
schirmer@13337
   255
@{text FVar} and test for initialisation in the rule @{text FVar}. 
schirmer@13337
   256
*}
schirmer@13337
   257
schirmer@13337
   258
berghofe@21765
   259
| AVarE1: "\<lbrakk>G\<turnstile>(\<langle>e1\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'\<rangle>,s')\<rbrakk> 
berghofe@21765
   260
           \<Longrightarrow> 
berghofe@21765
   261
           G\<turnstile>(\<langle>e1.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>e1'.[e2]\<rangle>,s')"
schirmer@13337
   262
berghofe@21765
   263
| AVarE2: "G\<turnstile>(\<langle>e2\<rangle>,Norm s) \<mapsto>1 (\<langle>e2'\<rangle>,s') 
berghofe@21765
   264
           \<Longrightarrow> 
berghofe@21765
   265
           G\<turnstile>(\<langle>Lit a.[e2]\<rangle>,Norm s) \<mapsto>1 (\<langle>Lit a.[e2']\<rangle>,s')"
schirmer@13337
   266
schirmer@13337
   267
(* AVar: \<langle>(Lit a).[Lit i]\<rangle> is fully evaluated *)
schirmer@13337
   268
schirmer@13337
   269
(* evaluation of expression lists *)
schirmer@13337
   270
schirmer@13337
   271
  -- {* @{text Nil}  is fully evaluated *}
schirmer@13337
   272
berghofe@21765
   273
| ConsHd: "\<lbrakk>G\<turnstile>(\<langle>e::expr\<rangle>,Norm s) \<mapsto>1 (\<langle>e'::expr\<rangle>,s')\<rbrakk> 
berghofe@21765
   274
           \<Longrightarrow>
berghofe@21765
   275
           G\<turnstile>(\<langle>e#es\<rangle>,Norm s) \<mapsto>1 (\<langle>e'#es\<rangle>,s')"
schirmer@13337
   276
  
berghofe@21765
   277
| ConsTl: "\<lbrakk>G\<turnstile>(\<langle>es\<rangle>,Norm s) \<mapsto>1 (\<langle>es'\<rangle>,s')\<rbrakk> 
berghofe@21765
   278
           \<Longrightarrow>
berghofe@21765
   279
           G\<turnstile>(\<langle>(Lit v)#es\<rangle>,Norm s) \<mapsto>1 (\<langle>(Lit v)#es'\<rangle>,s')"
schirmer@12854
   280
schirmer@12854
   281
(* execution of statements *)
schirmer@12854
   282
schirmer@12854
   283
  (* cf. 14.5 *)
berghofe@21765
   284
| Skip: "G\<turnstile>(\<langle>Skip\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)"
schirmer@12854
   285
berghofe@21765
   286
| ExprE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
berghofe@21765
   287
          \<Longrightarrow> 
berghofe@21765
   288
          G\<turnstile>(\<langle>Expr e\<rangle>,Norm s) \<mapsto>1 (\<langle>Expr e'\<rangle>,s')"
berghofe@21765
   289
| Expr:  "G\<turnstile>(\<langle>Expr (Lit v)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)"
schirmer@12854
   290
schirmer@12854
   291
berghofe@21765
   292
| LabC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,Norm s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk> 
berghofe@21765
   293
         \<Longrightarrow>  
berghofe@21765
   294
         G\<turnstile>(\<langle>l\<bullet> c\<rangle>,Norm s) \<mapsto>1 (\<langle>l\<bullet> c'\<rangle>,s')"
berghofe@21765
   295
| Lab:  "G\<turnstile>(\<langle>l\<bullet> Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>, abupd (absorb l) s)"
schirmer@13337
   296
schirmer@13337
   297
  (* cf. 14.2 *)
berghofe@21765
   298
| CompC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
berghofe@21765
   299
           \<Longrightarrow> 
berghofe@21765
   300
           G\<turnstile>(\<langle>c1;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1';; c2\<rangle>,s')"
schirmer@13337
   301
berghofe@21765
   302
| Comp:   "G\<turnstile>(\<langle>Skip;; c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c2\<rangle>,Norm s)"
schirmer@12854
   303
schirmer@12854
   304
  (* cf. 14.8.2 *)
berghofe@21765
   305
| IfE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle> ,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
berghofe@21765
   306
        \<Longrightarrow>
berghofe@21765
   307
        G\<turnstile>(\<langle>If(e) s1 Else s2\<rangle>,Norm s) \<mapsto>1 (\<langle>If(e') s1 Else s2\<rangle>,s')"
berghofe@21765
   308
| If:  "G\<turnstile>(\<langle>If(Lit v) s1 Else s2\<rangle>,Norm s) 
berghofe@21765
   309
         \<mapsto>1 (\<langle>if the_Bool v then s1 else s2\<rangle>,Norm s)"
schirmer@12854
   310
schirmer@12854
   311
  (* cf. 14.10, 14.10.1 *)
berghofe@21765
   312
| Loop: "G\<turnstile>(\<langle>l\<bullet> While(e) c\<rangle>,Norm s) 
berghofe@21765
   313
          \<mapsto>1 (\<langle>If(e) (Cont l\<bullet>c;; l\<bullet> While(e) c) Else Skip\<rangle>,Norm s)"
schirmer@13337
   314
berghofe@21765
   315
| Jmp: "G\<turnstile>(\<langle>Jmp j\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,(Some (Jump j), s))"
schirmer@13337
   316
berghofe@21765
   317
| ThrowE: "\<lbrakk>G\<turnstile>(\<langle>e\<rangle>,Norm s) \<mapsto>1 (\<langle>e'\<rangle>,s')\<rbrakk> 
berghofe@21765
   318
           \<Longrightarrow>
berghofe@21765
   319
           G\<turnstile>(\<langle>Throw e\<rangle>,Norm s) \<mapsto>1 (\<langle>Throw e'\<rangle>,s')"
berghofe@21765
   320
| Throw:  "G\<turnstile>(\<langle>Throw (Lit a)\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (throw a) (Norm s))"
schirmer@13337
   321
berghofe@21765
   322
| TryC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
berghofe@21765
   323
          \<Longrightarrow>
berghofe@21765
   324
          G\<turnstile>(\<langle>Try c1 Catch(C vn) c2\<rangle>, Norm s) \<mapsto>1 (\<langle>Try c1' Catch(C vn) c2\<rangle>,s')"
berghofe@21765
   325
| Try:   "\<lbrakk>G\<turnstile>s \<midarrow>sxalloc\<rightarrow> s'\<rbrakk>
berghofe@21765
   326
          \<Longrightarrow>
berghofe@21765
   327
          G\<turnstile>(\<langle>Try Skip Catch(C vn) c2\<rangle>, s) 
berghofe@21765
   328
           \<mapsto>1 (if G,s'\<turnstile>catch C then (\<langle>c2\<rangle>,new_xcpt_var vn s')
berghofe@21765
   329
                                else (\<langle>Skip\<rangle>,s'))"
schirmer@13337
   330
berghofe@21765
   331
| FinC1: "\<lbrakk>G\<turnstile>(\<langle>c1\<rangle>,Norm s) \<mapsto>1 (\<langle>c1'\<rangle>,s')\<rbrakk> 
berghofe@21765
   332
          \<Longrightarrow>
berghofe@21765
   333
          G\<turnstile>(\<langle>c1 Finally c2\<rangle>,Norm s) \<mapsto>1 (\<langle>c1' Finally c2\<rangle>,s')"
schirmer@13337
   334
berghofe@21765
   335
| Fin:    "G\<turnstile>(\<langle>Skip Finally c2\<rangle>,(a,s)) \<mapsto>1 (\<langle>FinA a c2\<rangle>,Norm s)"
schirmer@13337
   336
berghofe@21765
   337
| FinAC: "\<lbrakk>G\<turnstile>(\<langle>c\<rangle>,s) \<mapsto>1 (\<langle>c'\<rangle>,s')\<rbrakk>
berghofe@21765
   338
          \<Longrightarrow>
berghofe@21765
   339
          G\<turnstile>(\<langle>FinA a c\<rangle>,s) \<mapsto>1 (\<langle>FinA a c'\<rangle>,s')"
berghofe@21765
   340
| FinA: "G\<turnstile>(\<langle>FinA a Skip\<rangle>,s) \<mapsto>1 (\<langle>Skip\<rangle>,abupd (abrupt_if (a\<noteq>None) a) s)"
schirmer@13337
   341
schirmer@13337
   342
berghofe@21765
   343
| Init1: "\<lbrakk>inited C (globs s)\<rbrakk> 
berghofe@21765
   344
          \<Longrightarrow> 
berghofe@21765
   345
          G\<turnstile>(\<langle>Init C\<rangle>,Norm s) \<mapsto>1 (\<langle>Skip\<rangle>,Norm s)"
berghofe@21765
   346
| Init: "\<lbrakk>the (class G C)=c; \<not> inited C (globs s)\<rbrakk>  
berghofe@21765
   347
         \<Longrightarrow> 
berghofe@21765
   348
         G\<turnstile>(\<langle>Init C\<rangle>,Norm s) 
berghofe@21765
   349
          \<mapsto>1 (\<langle>(if C = Object then Skip else (Init (super c)));;
berghofe@21765
   350
                Expr (Callee (locals s) (InsInitE (init c) SKIP))\<rangle>
berghofe@21765
   351
               ,Norm (init_class_obj G C s))"
schirmer@13337
   352
-- {* @{text InsInitE} is just used as trick to embed the statement 
schirmer@13337
   353
@{text "init c"} into an expression*} 
berghofe@21765
   354
| InsInitESKIP:
berghofe@21765
   355
    "G\<turnstile>(\<langle>InsInitE Skip SKIP\<rangle>,Norm s) \<mapsto>1 (\<langle>SKIP\<rangle>,Norm s)"
berghofe@21765
   356
berghofe@21765
   357
abbreviation
berghofe@21765
   358
  stepn:: "[prog, term \<times> state,nat,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>_ _"[61,82,82] 81)
haftmann@30952
   359
  where "G\<turnstile>p \<mapsto>n p' \<equiv> (p,p') \<in> {(x, y). step G x y}^^n"
berghofe@21765
   360
berghofe@21765
   361
abbreviation
berghofe@21765
   362
  steptr:: "[prog,term \<times> state,term \<times> state] \<Rightarrow> bool" ("_\<turnstile>_ \<mapsto>* _"[61,82,82] 81)
berghofe@21765
   363
  where "G\<turnstile>p \<mapsto>* p' \<equiv> (p,p') \<in> {(x, y). step G x y}\<^sup>*"
schirmer@13337
   364
         
schirmer@13337
   365
(* Equivalenzen:
schirmer@13337
   366
  Bigstep zu Smallstep komplett.
wenzelm@40945
   367
  Smallstep zu Bigstep, nur wenn nicht die Ausdrücke Callee, FinA ,\<dots>
schirmer@12925
   368
*)
schirmer@12854
   369
schirmer@13337
   370
(*
schirmer@13337
   371
lemma imp_eval_trans:
schirmer@13337
   372
  assumes eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" 
schirmer@13337
   373
    shows trans: "G\<turnstile>(t,s0) \<mapsto>* (\<langle>Lit v\<rangle>,s1)"
schirmer@13337
   374
*)
wenzelm@40945
   375
(* Jetzt muss man bei trans natürlich wieder unterscheiden: Stmt, Expr, Var!
wenzelm@40945
   376
   Sowas blödes:
schirmer@13337
   377
   Am besten den Terminus ground auf Var,Stmt,Expr hochziehen und dann
schirmer@13337
   378
   the_vals definieren\<dots>
schirmer@13337
   379
  G\<turnstile>(t,s0) \<mapsto>* (t',s1) \<and> the_vals t' = v
schirmer@13337
   380
*)
schirmer@13337
   381
schirmer@13337
   382
schirmer@13337
   383
end