src/HOL/MicroJava/J/State.thy
changeset 61361 8b5f00202e1a
parent 61169 4de9ff3ea29a
child 62042 6c6ccf573479
equal deleted inserted replaced
61360:a273bdac0934 61361:8b5f00202e1a
     1 (*  Title:      HOL/MicroJava/J/State.thy
     1 (*  Title:      HOL/MicroJava/J/State.thy
     2     Author:     David von Oheimb
     2     Author:     David von Oheimb
     3     Copyright   1999 Technische Universitaet Muenchen
     3     Copyright   1999 Technische Universitaet Muenchen
     4 *)
     4 *)
     5 
     5 
     6 section {* Program State *}
     6 section \<open>Program State\<close>
     7 
     7 
     8 theory State
     8 theory State
     9 imports TypeRel Value
     9 imports TypeRel Value
    10 begin
    10 begin
    11 
    11 
    19  "obj_ty obj  == Class (fst obj)"
    19  "obj_ty obj  == Class (fst obj)"
    20 
    20 
    21 definition init_vars :: "('a \<times> ty) list => ('a \<rightharpoonup> val)" where
    21 definition init_vars :: "('a \<times> ty) list => ('a \<rightharpoonup> val)" where
    22  "init_vars == map_of o map (\<lambda>(n,T). (n,default_val T))"
    22  "init_vars == map_of o map (\<lambda>(n,T). (n,default_val T))"
    23 
    23 
    24 type_synonym aheap = "loc \<rightharpoonup> obj"    -- {* "@{text heap}" used in a translation below *}
    24 type_synonym aheap = "loc \<rightharpoonup> obj"    -- \<open>"@{text heap}" used in a translation below\<close>
    25 type_synonym locals = "vname \<rightharpoonup> val"  -- "simple state, i.e. variable contents"
    25 type_synonym locals = "vname \<rightharpoonup> val"  -- "simple state, i.e. variable contents"
    26 
    26 
    27 type_synonym state = "aheap \<times> locals"      -- "heap, local parameter including This"
    27 type_synonym state = "aheap \<times> locals"      -- "heap, local parameter including This"
    28 type_synonym xstate = "val option \<times> state" -- "state including exception information"
    28 type_synonym xstate = "val option \<times> state" -- "state including exception information"
    29 
    29 
    50   where "lookup_obj s a' == the (heap s (the_Addr a'))"
    50   where "lookup_obj s a' == the (heap s (the_Addr a'))"
    51 
    51 
    52 definition raise_if :: "bool \<Rightarrow> xcpt \<Rightarrow> val option \<Rightarrow> val option" where
    52 definition raise_if :: "bool \<Rightarrow> xcpt \<Rightarrow> val option \<Rightarrow> val option" where
    53   "raise_if b x xo \<equiv> if b \<and>  (xo = None) then Some (Addr (XcptRef x)) else xo"
    53   "raise_if b x xo \<equiv> if b \<and>  (xo = None) then Some (Addr (XcptRef x)) else xo"
    54 
    54 
    55 text {* Make @{text new_Addr} completely specified (at least for the code generator) *}
    55 text \<open>Make @{text new_Addr} completely specified (at least for the code generator)\<close>
    56 (*
    56 (*
    57 definition new_Addr  :: "aheap => loc \<times> val option" where
    57 definition new_Addr  :: "aheap => loc \<times> val option" where
    58   "new_Addr h \<equiv> SOME (a,x). (h a = None \<and>  x = None) |  x = Some (Addr (XcptRef OutOfMemory))"
    58   "new_Addr h \<equiv> SOME (a,x). (h a = None \<and>  x = None) |  x = Some (Addr (XcptRef OutOfMemory))"
    59 *)
    59 *)
    60 consts nat_to_loc' :: "nat => loc'"
    60 consts nat_to_loc' :: "nat => loc'"
   152 done
   152 done
   153 
   153 
   154 lemma c_hupd_fst [simp]: "fst (c_hupd h (x, s)) = x"
   154 lemma c_hupd_fst [simp]: "fst (c_hupd h (x, s)) = x"
   155 by (simp add: c_hupd_def split_beta)
   155 by (simp add: c_hupd_def split_beta)
   156 
   156 
   157 text {* Naive implementation for @{term "new_Addr"} by exhaustive search *}
   157 text \<open>Naive implementation for @{term "new_Addr"} by exhaustive search\<close>
   158 
   158 
   159 definition gen_new_Addr :: "aheap => nat \<Rightarrow> loc \<times> val option" where
   159 definition gen_new_Addr :: "aheap => nat \<Rightarrow> loc \<times> val option" where
   160   "gen_new_Addr h n \<equiv> 
   160   "gen_new_Addr h n \<equiv> 
   161    if \<exists>a. a \<ge> n \<and> h (Loc (nat_to_loc' a)) = None 
   161    if \<exists>a. a \<ge> n \<and> h (Loc (nat_to_loc' a)) = None 
   162    then (Loc (nat_to_loc' (LEAST a. a \<ge> n \<and> h (Loc (nat_to_loc' a)) = None)), None)
   162    then (Loc (nat_to_loc' (LEAST a. a \<ge> n \<and> h (Loc (nat_to_loc' a)) = None)), None)