src/HOL/MicroJava/BV/Correct.thy
changeset 35416 d8d7d1b785af
parent 33954 1bc3b688548c
child 35417 47ee18b6ae32
equal deleted inserted replaced
35342:4dc65845eab3 35416:d8d7d1b785af
     7 
     7 
     8 theory Correct
     8 theory Correct
     9 imports BVSpec "../JVM/JVMExec"
     9 imports BVSpec "../JVM/JVMExec"
    10 begin
    10 begin
    11 
    11 
    12 constdefs
    12 definition approx_val :: "[jvm_prog,aheap,val,ty err] \<Rightarrow> bool" where
    13   approx_val :: "[jvm_prog,aheap,val,ty err] \<Rightarrow> bool"
       
    14   "approx_val G h v any == case any of Err \<Rightarrow> True | OK T \<Rightarrow> G,h\<turnstile>v::\<preceq>T"
    13   "approx_val G h v any == case any of Err \<Rightarrow> True | OK T \<Rightarrow> G,h\<turnstile>v::\<preceq>T"
    15 
    14 
    16   approx_loc :: "[jvm_prog,aheap,val list,locvars_type] \<Rightarrow> bool"
    15 definition approx_loc :: "[jvm_prog,aheap,val list,locvars_type] \<Rightarrow> bool" where
    17   "approx_loc G hp loc LT == list_all2 (approx_val G hp) loc LT"
    16   "approx_loc G hp loc LT == list_all2 (approx_val G hp) loc LT"
    18 
    17 
    19   approx_stk :: "[jvm_prog,aheap,opstack,opstack_type] \<Rightarrow> bool"
    18 definition approx_stk :: "[jvm_prog,aheap,opstack,opstack_type] \<Rightarrow> bool" where
    20   "approx_stk G hp stk ST == approx_loc G hp stk (map OK ST)"
    19   "approx_stk G hp stk ST == approx_loc G hp stk (map OK ST)"
    21 
    20 
    22   correct_frame  :: "[jvm_prog,aheap,state_type,nat,bytecode] \<Rightarrow> frame \<Rightarrow> bool"
    21 definition correct_frame  :: "[jvm_prog,aheap,state_type,nat,bytecode] \<Rightarrow> frame \<Rightarrow> bool" where
    23   "correct_frame G hp == \<lambda>(ST,LT) maxl ins (stk,loc,C,sig,pc).
    22   "correct_frame G hp == \<lambda>(ST,LT) maxl ins (stk,loc,C,sig,pc).
    24                          approx_stk G hp stk ST  \<and> approx_loc G hp loc LT \<and> 
    23                          approx_stk G hp stk ST  \<and> approx_loc G hp loc LT \<and> 
    25                          pc < length ins \<and> length loc=length(snd sig)+maxl+1"
    24                          pc < length ins \<and> length loc=length(snd sig)+maxl+1"
    26 
    25 
    27 
    26 primrec correct_frames  :: "[jvm_prog,aheap,prog_type,ty,sig,frame list] \<Rightarrow> bool" where
    28 consts
    27   "correct_frames G hp phi rT0 sig0 [] = True"
    29  correct_frames  :: "[jvm_prog,aheap,prog_type,ty,sig,frame list] \<Rightarrow> bool"
    28 | "correct_frames G hp phi rT0 sig0 (f#frs) =
    30 primrec
    29     (let (stk,loc,C,sig,pc) = f in
    31 "correct_frames G hp phi rT0 sig0 [] = True"
    30     (\<exists>ST LT rT maxs maxl ins et.
    32 
    31       phi C sig ! pc = Some (ST,LT) \<and> is_class G C \<and> 
    33 "correct_frames G hp phi rT0 sig0 (f#frs) =
    32       method (G,C) sig = Some(C,rT,(maxs,maxl,ins,et)) \<and>
    34   (let (stk,loc,C,sig,pc) = f in
    33     (\<exists>C' mn pTs. ins!pc = (Invoke C' mn pTs) \<and> 
    35   (\<exists>ST LT rT maxs maxl ins et.
    34            (mn,pTs) = sig0 \<and> 
    36     phi C sig ! pc = Some (ST,LT) \<and> is_class G C \<and> 
    35            (\<exists>apTs D ST' LT'.
    37     method (G,C) sig = Some(C,rT,(maxs,maxl,ins,et)) \<and>
    36            (phi C sig)!pc = Some ((rev apTs) @ (Class D) # ST', LT') \<and>
    38   (\<exists>C' mn pTs. ins!pc = (Invoke C' mn pTs) \<and> 
    37            length apTs = length pTs \<and>
    39          (mn,pTs) = sig0 \<and> 
    38            (\<exists>D' rT' maxs' maxl' ins' et'.
    40          (\<exists>apTs D ST' LT'.
    39              method (G,D) sig0 = Some(D',rT',(maxs',maxl',ins',et')) \<and>
    41          (phi C sig)!pc = Some ((rev apTs) @ (Class D) # ST', LT') \<and>
    40              G \<turnstile> rT0 \<preceq> rT') \<and>
    42          length apTs = length pTs \<and>
    41      correct_frame G hp (ST, LT) maxl ins f \<and> 
    43          (\<exists>D' rT' maxs' maxl' ins' et'.
    42      correct_frames G hp phi rT sig frs))))"
    44            method (G,D) sig0 = Some(D',rT',(maxs',maxl',ins',et')) \<and>
    43 
    45            G \<turnstile> rT0 \<preceq> rT') \<and>
    44 definition correct_state :: "[jvm_prog,prog_type,jvm_state] \<Rightarrow> bool"
    46    correct_frame G hp (ST, LT) maxl ins f \<and> 
    45                   ("_,_ |-JVM _ [ok]"  [51,51] 50) where
    47    correct_frames G hp phi rT sig frs))))"
       
    48 
       
    49 
       
    50 constdefs
       
    51  correct_state :: "[jvm_prog,prog_type,jvm_state] \<Rightarrow> bool"
       
    52                   ("_,_ |-JVM _ [ok]"  [51,51] 50)
       
    53 "correct_state G phi == \<lambda>(xp,hp,frs).
    46 "correct_state G phi == \<lambda>(xp,hp,frs).
    54    case xp of
    47    case xp of
    55      None \<Rightarrow> (case frs of
    48      None \<Rightarrow> (case frs of
    56              [] \<Rightarrow> True
    49              [] \<Rightarrow> True
    57              | (f#fs) \<Rightarrow> G\<turnstile>h hp\<surd> \<and> preallocated hp \<and> 
    50              | (f#fs) \<Rightarrow> G\<turnstile>h hp\<surd> \<and> preallocated hp \<and>