src/HOL/MicroJava/J/State.thy
author kleing
Thu, 21 Feb 2002 09:54:08 +0100
changeset 12911 704713ca07ea
parent 12545 7319d384d0d3
child 13672 b95d12325b51
permissions -rw-r--r--
new document
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/J/State.thy
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     2
    ID:         $Id$
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     3
    Author:     David von Oheimb
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     4
    Copyright   1999 Technische Universitaet Muenchen
11070
cc421547e744 improved document (added headers etc)
oheimb
parents: 11026
diff changeset
     5
*)
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     6
12911
704713ca07ea new document
kleing
parents: 12545
diff changeset
     7
header {* \isaheader{Program State} *}
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
     8
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
     9
theory State = TypeRel + Value:
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    10
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    11
types 
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    12
  fields_ = "(vname \<times> cname \<leadsto> val)"  -- "field name, defining class, value"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    13
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    14
  obj = "cname \<times> fields_"    -- "class instance with class name and fields"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    15
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    16
constdefs
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    17
  obj_ty  :: "obj => ty"
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9348
diff changeset
    18
 "obj_ty obj  == Class (fst obj)"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    19
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    20
  init_vars :: "('a \<times> ty) list => ('a \<leadsto> val)"
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    21
 "init_vars == map_of o map (\<lambda>(n,T). (n,default_val T))"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    22
  
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    23
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    24
types aheap  = "loc \<leadsto> obj"    -- {* "@{text heap}" used in a translation below *}
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    25
      locals = "vname \<leadsto> val"  -- "simple state, i.e. variable contents"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    26
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    27
      state  = "aheap \<times> locals"      -- "heap, local parameter including This"
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    28
      xstate = "xcpt option \<times> state" -- "state including exception information"
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    29
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    30
syntax
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    31
  heap    :: "state => aheap"
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    32
  locals  :: "state => locals"
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    33
  Norm    :: "state => xstate"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    34
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    35
translations
10061
fe82134773dc added HTML syntax; added spaces in normal syntax for better documents
kleing
parents: 10042
diff changeset
    36
  "heap"   => "fst"
fe82134773dc added HTML syntax; added spaces in normal syntax for better documents
kleing
parents: 10042
diff changeset
    37
  "locals" => "snd"
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    38
  "Norm s" == "(None,s)"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    39
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    40
constdefs
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    41
  new_Addr  :: "aheap => loc \<times> xcpt option"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    42
 "new_Addr h == SOME (a,x). (h a = None \<and>  x = None) |  x = Some OutOfMemory"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    43
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    44
  raise_if  :: "bool => xcpt => xcpt option => xcpt option"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    45
 "raise_if c x xo == if c \<and>  (xo = None) then Some x else xo"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    46
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    47
  np    :: "val => xcpt option => xcpt option"
10042
7164dc0d24d8 unsymbolized
kleing
parents: 9348
diff changeset
    48
 "np v == raise_if (v = Null) NullPointer"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    49
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    50
  c_hupd  :: "aheap => xstate => xstate"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    51
 "c_hupd h'== \<lambda>(xo,(h,l)). if xo = None then (None,(h',l)) else (xo,(h,l))"
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
    52
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    53
  cast_ok :: "'c prog => cname => aheap => val => bool"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    54
 "cast_ok G C h v == v = Null \<or> G\<turnstile>obj_ty (the (h (the_Addr v)))\<preceq> Class C"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    55
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    56
lemma obj_ty_def2 [simp]: "obj_ty (C,fs) = Class C"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    57
apply (unfold obj_ty_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    58
apply (simp (no_asm))
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    59
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    60
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    61
lemma new_AddrD: 
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    62
"(a,x) = new_Addr h ==> h a = None \<and> x = None | x = Some OutOfMemory"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    63
apply (unfold new_Addr_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    64
apply(simp add: Pair_fst_snd_eq Eps_split)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    65
apply(rule someI)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    66
apply(rule disjI2)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    67
apply(rule_tac "r" = "snd (?a,Some OutOfMemory)" in trans)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    68
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    69
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    70
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    71
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    72
lemma raise_if_True [simp]: "raise_if True x y \<noteq> None"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    73
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    74
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    75
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    76
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    77
lemma raise_if_False [simp]: "raise_if False x y = y"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    78
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    79
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    80
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    81
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    82
lemma raise_if_Some [simp]: "raise_if c x (Some y) \<noteq> None"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    83
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    84
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    85
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    86
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    87
lemma raise_if_Some2 [simp]: 
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
    88
  "raise_if c z (if x = None then Some y else x) \<noteq> None"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    89
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    90
apply(induct_tac "x")
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    91
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    92
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    93
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    94
lemma raise_if_SomeD [rule_format (no_asm)]: 
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    95
  "raise_if c x y = Some z \<longrightarrow> c \<and>  Some z = Some x |  y = Some z"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    96
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    97
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    98
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
    99
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
   100
lemma raise_if_NoneD [rule_format (no_asm)]: 
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
   101
  "raise_if c x y = None --> \<not> c \<and>  y = None"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   102
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   103
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   104
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   105
12517
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
   106
lemma np_NoneD [rule_format (no_asm)]: 
360e3215f029 exception merge, cleanup, tuned
kleing
parents: 11372
diff changeset
   107
  "np a' x' = None --> x' = None \<and>  a' \<noteq> Null"
11026
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   108
apply (unfold np_def raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   109
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   110
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   111
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   112
lemma np_None [rule_format (no_asm), simp]: "a' \<noteq> Null --> np a' x' = x'"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   113
apply (unfold np_def raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   114
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   115
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   116
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   117
lemma np_Some [simp]: "np a' (Some xc) = Some xc"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   118
apply (unfold np_def raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   119
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   120
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   121
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   122
lemma np_Null [simp]: "np Null None = Some NullPointer"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   123
apply (unfold np_def raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   124
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   125
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   126
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   127
lemma np_Addr [simp]: "np (Addr a) None = None"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   128
apply (unfold np_def raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   129
apply auto
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   130
done
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   131
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   132
lemma np_raise_if [simp]: "(np Null (raise_if c xc None)) =  
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   133
  Some (if c then xc else NullPointer)"
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   134
apply (unfold raise_if_def)
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   135
apply (simp (no_asm))
a50365d21144 converted to Isar, simplifying recursion on class hierarchy
oheimb
parents: 10061
diff changeset
   136
done
8011
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
   137
d14c4e9e9c8e *** empty log message ***
nipkow
parents:
diff changeset
   138
end