author | haftmann |
Tue, 11 Aug 2009 10:05:16 +0200 | |
changeset 32356 | e11cd88e6ade |
parent 30235 | 58d147683393 |
child 32359 | bc1e123295f5 |
permissions | -rw-r--r-- |
8011 | 1 |
(* Title: HOL/MicroJava/J/State.thy |
2 |
Author: David von Oheimb |
|
3 |
Copyright 1999 Technische Universitaet Muenchen |
|
11070 | 4 |
*) |
8011 | 5 |
|
12911 | 6 |
header {* \isaheader{Program State} *} |
8011 | 7 |
|
32356
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
8 |
theory State |
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
9 |
imports TypeRel Value |
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
10 |
begin |
8011 | 11 |
|
12517 | 12 |
types |
24783 | 13 |
fields' = "(vname \<times> cname \<rightharpoonup> val)" -- "field name, defining class, value" |
8011 | 14 |
|
24783 | 15 |
obj = "cname \<times> fields'" -- "class instance with class name and fields" |
8011 | 16 |
|
17 |
constdefs |
|
12517 | 18 |
obj_ty :: "obj => ty" |
10042 | 19 |
"obj_ty obj == Class (fst obj)" |
8011 | 20 |
|
14134 | 21 |
init_vars :: "('a \<times> ty) list => ('a \<rightharpoonup> val)" |
12517 | 22 |
"init_vars == map_of o map (\<lambda>(n,T). (n,default_val T))" |
32356
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
23 |
|
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
24 |
lemma [code] (*manual eta expansion*): |
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
25 |
"init_vars xs = map_of (map (\<lambda>(n, T). (n, default_val T)) xs)" |
e11cd88e6ade
temporary adjustment to dubious state of eta expansion in recfun_codegen
haftmann
parents:
30235
diff
changeset
|
26 |
by (simp add: init_vars_def) |
12517 | 27 |
|
14134 | 28 |
types aheap = "loc \<rightharpoonup> obj" -- {* "@{text heap}" used in a translation below *} |
29 |
locals = "vname \<rightharpoonup> val" -- "simple state, i.e. variable contents" |
|
8011 | 30 |
|
12517 | 31 |
state = "aheap \<times> locals" -- "heap, local parameter including This" |
13672 | 32 |
xstate = "val option \<times> state" -- "state including exception information" |
12517 | 33 |
|
8011 | 34 |
syntax |
12517 | 35 |
heap :: "state => aheap" |
36 |
locals :: "state => locals" |
|
37 |
Norm :: "state => xstate" |
|
13672 | 38 |
abrupt :: "xstate \<Rightarrow> val option" |
39 |
store :: "xstate \<Rightarrow> state" |
|
40 |
lookup_obj :: "state \<Rightarrow> val \<Rightarrow> obj" |
|
8011 | 41 |
|
42 |
translations |
|
10061
fe82134773dc
added HTML syntax; added spaces in normal syntax for better documents
kleing
parents:
10042
diff
changeset
|
43 |
"heap" => "fst" |
fe82134773dc
added HTML syntax; added spaces in normal syntax for better documents
kleing
parents:
10042
diff
changeset
|
44 |
"locals" => "snd" |
12517 | 45 |
"Norm s" == "(None,s)" |
13672 | 46 |
"abrupt" => "fst" |
47 |
"store" => "snd" |
|
30235
58d147683393
Made Option a separate theory and renamed option_map to Option.map
nipkow
parents:
24783
diff
changeset
|
48 |
"lookup_obj s a'" == "CONST the (heap s (the_Addr a'))" |
13672 | 49 |
|
8011 | 50 |
|
51 |
constdefs |
|
13672 | 52 |
raise_if :: "bool \<Rightarrow> xcpt \<Rightarrow> val option \<Rightarrow> val option" |
53 |
"raise_if b x xo \<equiv> if b \<and> (xo = None) then Some (Addr (XcptRef x)) else xo" |
|
8011 | 54 |
|
13672 | 55 |
new_Addr :: "aheap => loc \<times> val option" |
56 |
"new_Addr h \<equiv> SOME (a,x). (h a = None \<and> x = None) | x = Some (Addr (XcptRef OutOfMemory))" |
|
8011 | 57 |
|
13672 | 58 |
np :: "val => val option => val option" |
10042 | 59 |
"np v == raise_if (v = Null) NullPointer" |
8011 | 60 |
|
12517 | 61 |
c_hupd :: "aheap => xstate => xstate" |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
62 |
"c_hupd h'== \<lambda>(xo,(h,l)). if xo = None then (None,(h',l)) else (xo,(h,l))" |
8011 | 63 |
|
12517 | 64 |
cast_ok :: "'c prog => cname => aheap => val => bool" |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
65 |
"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
|
66 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
67 |
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
|
68 |
apply (unfold obj_ty_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
69 |
apply (simp (no_asm)) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
70 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
71 |
|
13672 | 72 |
|
73 |
lemma new_AddrD: "new_Addr hp = (ref, xcp) \<Longrightarrow> |
|
74 |
hp ref = None \<and> xcp = None \<or> xcp = Some (Addr (XcptRef OutOfMemory))" |
|
75 |
apply (drule sym) |
|
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
76 |
apply (unfold new_Addr_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
77 |
apply(simp add: Pair_fst_snd_eq Eps_split) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
78 |
apply(rule someI) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
79 |
apply(rule disjI2) |
14174
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
ballarin
parents:
14144
diff
changeset
|
80 |
apply(rule_tac r = "snd (?a,Some (Addr (XcptRef OutOfMemory)))" in trans) |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
81 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
82 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
83 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
84 |
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
|
85 |
apply (unfold raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
86 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
87 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
88 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
89 |
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
|
90 |
apply (unfold raise_if_def) |
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_Some [simp]: "raise_if c x (Some y) \<noteq> None" |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
95 |
apply (unfold raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
96 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
97 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
98 |
|
12517 | 99 |
lemma raise_if_Some2 [simp]: |
100 |
"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
|
101 |
apply (unfold raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
102 |
apply(induct_tac "x") |
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 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
106 |
lemma raise_if_SomeD [rule_format (no_asm)]: |
13672 | 107 |
"raise_if c x y = Some z \<longrightarrow> c \<and> Some z = Some (Addr (XcptRef x)) | y = Some z" |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
108 |
apply (unfold 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 |
|
12517 | 112 |
lemma raise_if_NoneD [rule_format (no_asm)]: |
113 |
"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
|
114 |
apply (unfold raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
115 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
116 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
117 |
|
12517 | 118 |
lemma np_NoneD [rule_format (no_asm)]: |
119 |
"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
|
120 |
apply (unfold np_def raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
121 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
122 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
123 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
124 |
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
|
125 |
apply (unfold np_def raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
126 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
127 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
128 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
129 |
lemma np_Some [simp]: "np a' (Some xc) = Some xc" |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
130 |
apply (unfold np_def raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
131 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
132 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
133 |
|
13672 | 134 |
lemma np_Null [simp]: "np Null None = Some (Addr (XcptRef NullPointer))" |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
135 |
apply (unfold np_def raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
136 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
137 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
138 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
139 |
lemma np_Addr [simp]: "np (Addr a) None = None" |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
140 |
apply (unfold np_def raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
141 |
apply auto |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
142 |
done |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
143 |
|
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
144 |
lemma np_raise_if [simp]: "(np Null (raise_if c xc None)) = |
13672 | 145 |
Some (Addr (XcptRef (if c then xc else NullPointer)))" |
11026
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
146 |
apply (unfold raise_if_def) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
147 |
apply (simp (no_asm)) |
a50365d21144
converted to Isar, simplifying recursion on class hierarchy
oheimb
parents:
10061
diff
changeset
|
148 |
done |
8011 | 149 |
|
14144 | 150 |
lemma c_hupd_fst [simp]: "fst (c_hupd h (x, s)) = x" |
151 |
by (simp add: c_hupd_def split_beta) |
|
152 |
||
8011 | 153 |
end |