1 (* Title: HOL/Bali/State.thy |
1 (* Title: HOL/Bali/State.thy |
2 Author: David von Oheimb |
2 Author: David von Oheimb |
3 *) |
3 *) |
4 subsection {* State for evaluation of Java expressions and statements *} |
4 subsection \<open>State for evaluation of Java expressions and statements\<close> |
5 |
5 |
6 theory State |
6 theory State |
7 imports DeclConcepts |
7 imports DeclConcepts |
8 begin |
8 begin |
9 |
9 |
10 text {* |
10 text \<open> |
11 design issues: |
11 design issues: |
12 \begin{itemize} |
12 \begin{itemize} |
13 \item all kinds of objects (class instances, arrays, and class objects) |
13 \item all kinds of objects (class instances, arrays, and class objects) |
14 are handeled via a general object abstraction |
14 are handeled via a general object abstraction |
15 \item the heap and the map for class objects are combined into a single table |
15 \item the heap and the map for class objects are combined into a single table |
16 @{text "(recall (loc, obj) table \<times> (qtname, obj) table ~= (loc + qtname, obj) table)"} |
16 \<open>(recall (loc, obj) table \<times> (qtname, obj) table ~= (loc + qtname, obj) table)\<close> |
17 \end{itemize} |
17 \end{itemize} |
18 *} |
18 \<close> |
19 |
19 |
20 subsubsection "objects" |
20 subsubsection "objects" |
21 |
21 |
22 datatype obj_tag = --{* tag for generic object *} |
22 datatype obj_tag = \<comment>\<open>tag for generic object\<close> |
23 CInst qtname --{* class instance *} |
23 CInst qtname \<comment>\<open>class instance\<close> |
24 | Arr ty int --{* array with component type and length *} |
24 | Arr ty int \<comment>\<open>array with component type and length\<close> |
25 --{* | CStat qtname the tag is irrelevant for a class object, |
25 \<comment>\<open>| CStat qtname the tag is irrelevant for a class object, |
26 i.e. the static fields of a class, |
26 i.e. the static fields of a class, |
27 since its type is given already by the reference to |
27 since its type is given already by the reference to |
28 it (see below) *} |
28 it (see below)\<close> |
29 |
29 |
30 type_synonym vn = "fspec + int" --{* variable name *} |
30 type_synonym vn = "fspec + int" \<comment>\<open>variable name\<close> |
31 record obj = |
31 record obj = |
32 tag :: "obj_tag" --{* generalized object *} |
32 tag :: "obj_tag" \<comment>\<open>generalized object\<close> |
33 "values" :: "(vn, val) table" |
33 "values" :: "(vn, val) table" |
34 |
34 |
35 translations |
35 translations |
36 (type) "fspec" <= (type) "vname \<times> qtname" |
36 (type) "fspec" <= (type) "vname \<times> qtname" |
37 (type) "vn" <= (type) "fspec + int" |
37 (type) "vn" <= (type) "fspec + int" |
128 apply (auto dest: widen_Array_Class) |
128 apply (auto dest: widen_Array_Class) |
129 done |
129 done |
130 |
130 |
131 subsubsection "object references" |
131 subsubsection "object references" |
132 |
132 |
133 type_synonym oref = "loc + qtname" --{* generalized object reference *} |
133 type_synonym oref = "loc + qtname" \<comment>\<open>generalized object reference\<close> |
134 syntax |
134 syntax |
135 Heap :: "loc \<Rightarrow> oref" |
135 Heap :: "loc \<Rightarrow> oref" |
136 Stat :: "qtname \<Rightarrow> oref" |
136 Stat :: "qtname \<Rightarrow> oref" |
137 |
137 |
138 translations |
138 translations |
211 done |
211 done |
212 |
212 |
213 |
213 |
214 subsubsection "stores" |
214 subsubsection "stores" |
215 |
215 |
216 type_synonym globs --{* global variables: heap and static variables *} |
216 type_synonym globs \<comment>\<open>global variables: heap and static variables\<close> |
217 = "(oref , obj) table" |
217 = "(oref , obj) table" |
218 type_synonym heap |
218 type_synonym heap |
219 = "(loc , obj) table" |
219 = "(loc , obj) table" |
220 (* type_synonym locals |
220 (* type_synonym locals |
221 = "(lname, val) table" *) (* defined in Value.thy local variables *) |
221 = "(lname, val) table" *) (* defined in Value.thy local variables *) |
725 lemma initd_def2 [simp]: "initd C s = inited C (globs (store s))" |
725 lemma initd_def2 [simp]: "initd C s = inited C (globs (store s))" |
726 apply (unfold initd_def) |
726 apply (unfold initd_def) |
727 apply (simp (no_asm)) |
727 apply (simp (no_asm)) |
728 done |
728 done |
729 |
729 |
730 subsubsection {* @{text error_free} *} |
730 subsubsection \<open>\<open>error_free\<close>\<close> |
731 |
731 |
732 definition |
732 definition |
733 error_free :: "state \<Rightarrow> bool" |
733 error_free :: "state \<Rightarrow> bool" |
734 where "error_free s = (\<not> (\<exists> err. abrupt s = Some (Error err)))" |
734 where "error_free s = (\<not> (\<exists> err. abrupt s = Some (Error err)))" |
735 |
735 |