src/HOL/MicroJava/J/State.thy
changeset 13672 b95d12325b51
parent 12911 704713ca07ea
child 14134 0fdf5708c7a8
equal deleted inserted replaced
13671:eec2582923f6 13672:b95d12325b51
    23 
    23 
    24 types aheap  = "loc \<leadsto> obj"    -- {* "@{text heap}" used in a translation below *}
    24 types aheap  = "loc \<leadsto> obj"    -- {* "@{text heap}" used in a translation below *}
    25       locals = "vname \<leadsto> val"  -- "simple state, i.e. variable contents"
    25       locals = "vname \<leadsto> val"  -- "simple state, i.e. variable contents"
    26 
    26 
    27       state  = "aheap \<times> locals"      -- "heap, local parameter including This"
    27       state  = "aheap \<times> locals"      -- "heap, local parameter including This"
    28       xstate = "xcpt option \<times> state" -- "state including exception information"
    28       xstate = "val option \<times> state" -- "state including exception information"
    29 
    29 
    30 syntax
    30 syntax
    31   heap    :: "state => aheap"
    31   heap    :: "state => aheap"
    32   locals  :: "state => locals"
    32   locals  :: "state => locals"
    33   Norm    :: "state => xstate"
    33   Norm    :: "state => xstate"
       
    34   abrupt  :: "xstate \<Rightarrow> val option"
       
    35   store   :: "xstate \<Rightarrow> state"
       
    36   lookup_obj   :: "state \<Rightarrow> val \<Rightarrow> obj"
    34 
    37 
    35 translations
    38 translations
    36   "heap"   => "fst"
    39   "heap"   => "fst"
    37   "locals" => "snd"
    40   "locals" => "snd"
    38   "Norm s" == "(None,s)"
    41   "Norm s" == "(None,s)"
       
    42   "abrupt"     => "fst"
       
    43   "store"      => "snd"
       
    44  "lookup_obj s a'"  == "the (heap s (the_Addr a'))"
       
    45 
    39 
    46 
    40 constdefs
    47 constdefs
    41   new_Addr  :: "aheap => loc \<times> xcpt option"
    48   raise_if :: "bool \<Rightarrow> xcpt \<Rightarrow> val option \<Rightarrow> val option"
    42  "new_Addr h == SOME (a,x). (h a = None \<and>  x = None) |  x = Some OutOfMemory"
    49   "raise_if b x xo \<equiv> if b \<and>  (xo = None) then Some (Addr (XcptRef x)) else xo"
    43 
    50 
    44   raise_if  :: "bool => xcpt => xcpt option => xcpt option"
    51   new_Addr  :: "aheap => loc \<times> val option"
    45  "raise_if c x xo == if c \<and>  (xo = None) then Some x else xo"
    52   "new_Addr h \<equiv> SOME (a,x). (h a = None \<and>  x = None) |  x = Some (Addr (XcptRef OutOfMemory))"
    46 
    53 
    47   np    :: "val => xcpt option => xcpt option"
    54   np    :: "val => val option => val option"
    48  "np v == raise_if (v = Null) NullPointer"
    55  "np v == raise_if (v = Null) NullPointer"
    49 
    56 
    50   c_hupd  :: "aheap => xstate => xstate"
    57   c_hupd  :: "aheap => xstate => xstate"
    51  "c_hupd h'== \<lambda>(xo,(h,l)). if xo = None then (None,(h',l)) else (xo,(h,l))"
    58  "c_hupd h'== \<lambda>(xo,(h,l)). if xo = None then (None,(h',l)) else (xo,(h,l))"
    52 
    59 
    56 lemma obj_ty_def2 [simp]: "obj_ty (C,fs) = Class C"
    63 lemma obj_ty_def2 [simp]: "obj_ty (C,fs) = Class C"
    57 apply (unfold obj_ty_def)
    64 apply (unfold obj_ty_def)
    58 apply (simp (no_asm))
    65 apply (simp (no_asm))
    59 done
    66 done
    60 
    67 
    61 lemma new_AddrD: 
    68 
    62 "(a,x) = new_Addr h ==> h a = None \<and> x = None | x = Some OutOfMemory"
    69 lemma new_AddrD: "new_Addr hp = (ref, xcp) \<Longrightarrow>
       
    70   hp ref = None \<and> xcp = None \<or> xcp = Some (Addr (XcptRef OutOfMemory))"
       
    71 apply (drule sym)
    63 apply (unfold new_Addr_def)
    72 apply (unfold new_Addr_def)
    64 apply(simp add: Pair_fst_snd_eq Eps_split)
    73 apply(simp add: Pair_fst_snd_eq Eps_split)
    65 apply(rule someI)
    74 apply(rule someI)
    66 apply(rule disjI2)
    75 apply(rule disjI2)
    67 apply(rule_tac "r" = "snd (?a,Some OutOfMemory)" in trans)
    76 apply(rule_tac "r" = "snd (?a,Some (Addr (XcptRef OutOfMemory)))" in trans)
    68 apply auto
    77 apply auto
    69 done
    78 done
    70 
       
    71 
    79 
    72 lemma raise_if_True [simp]: "raise_if True x y \<noteq> None"
    80 lemma raise_if_True [simp]: "raise_if True x y \<noteq> None"
    73 apply (unfold raise_if_def)
    81 apply (unfold raise_if_def)
    74 apply auto
    82 apply auto
    75 done
    83 done
    90 apply(induct_tac "x")
    98 apply(induct_tac "x")
    91 apply auto
    99 apply auto
    92 done
   100 done
    93 
   101 
    94 lemma raise_if_SomeD [rule_format (no_asm)]: 
   102 lemma raise_if_SomeD [rule_format (no_asm)]: 
    95   "raise_if c x y = Some z \<longrightarrow> c \<and>  Some z = Some x |  y = Some z"
   103   "raise_if c x y = Some z \<longrightarrow> c \<and>  Some z = Some (Addr (XcptRef x)) |  y = Some z"
    96 apply (unfold raise_if_def)
   104 apply (unfold raise_if_def)
    97 apply auto
   105 apply auto
    98 done
   106 done
    99 
   107 
   100 lemma raise_if_NoneD [rule_format (no_asm)]: 
   108 lemma raise_if_NoneD [rule_format (no_asm)]: 
   117 lemma np_Some [simp]: "np a' (Some xc) = Some xc"
   125 lemma np_Some [simp]: "np a' (Some xc) = Some xc"
   118 apply (unfold np_def raise_if_def)
   126 apply (unfold np_def raise_if_def)
   119 apply auto
   127 apply auto
   120 done
   128 done
   121 
   129 
   122 lemma np_Null [simp]: "np Null None = Some NullPointer"
   130 lemma np_Null [simp]: "np Null None = Some (Addr (XcptRef NullPointer))"
   123 apply (unfold np_def raise_if_def)
   131 apply (unfold np_def raise_if_def)
   124 apply auto
   132 apply auto
   125 done
   133 done
   126 
   134 
   127 lemma np_Addr [simp]: "np (Addr a) None = None"
   135 lemma np_Addr [simp]: "np (Addr a) None = None"
   128 apply (unfold np_def raise_if_def)
   136 apply (unfold np_def raise_if_def)
   129 apply auto
   137 apply auto
   130 done
   138 done
   131 
   139 
   132 lemma np_raise_if [simp]: "(np Null (raise_if c xc None)) =  
   140 lemma np_raise_if [simp]: "(np Null (raise_if c xc None)) =  
   133   Some (if c then xc else NullPointer)"
   141   Some (Addr (XcptRef (if c then  xc else NullPointer)))"
   134 apply (unfold raise_if_def)
   142 apply (unfold raise_if_def)
   135 apply (simp (no_asm))
   143 apply (simp (no_asm))
   136 done
   144 done
   137 
   145 
   138 end
   146 end