author | oheimb |
Tue, 04 Jul 2000 10:54:32 +0200 | |
changeset 9240 | f4d76cb26433 |
parent 8082 | 381716a86fcb |
child 9346 | 297dcbf64526 |
permissions | -rw-r--r-- |
8011 | 1 |
(* Title: HOL/MicroJava/J/Eval.thy |
2 |
ID: $Id$ |
|
3 |
Author: David von Oheimb |
|
4 |
Copyright 1999 Technische Universitaet Muenchen |
|
5 |
||
6 |
Operational evaluation (big-step) semantics of the |
|
7 |
execution of Java expressions and statements |
|
8 |
*) |
|
9 |
||
10 |
Eval = State + |
|
11 |
||
12 |
consts |
|
8082 | 13 |
eval :: "java_mb prog \\<Rightarrow> (xstate \\<times> expr \\<times> val \\<times> xstate) set" |
14 |
evals :: "java_mb prog \\<Rightarrow> (xstate \\<times> expr list \\<times> val list \\<times> xstate) set" |
|
15 |
exec :: "java_mb prog \\<Rightarrow> (xstate \\<times> stmt \\<times> xstate) set" |
|
8011 | 16 |
|
17 |
syntax |
|
8082 | 18 |
eval :: "[java_mb prog,xstate,expr,val,xstate] \\<Rightarrow> bool "("_\\<turnstile>_ -_\\<succ>_\\<rightarrow> _"[51,82,82,82,82]81) |
19 |
evals:: "[java_mb prog,xstate,expr list, |
|
8011 | 20 |
val list,xstate] \\<Rightarrow> bool "("_\\<turnstile>_ -_[\\<succ>]_\\<rightarrow> _"[51,82,51,51,82]81) |
8082 | 21 |
exec :: "[java_mb prog,xstate,stmt, xstate] \\<Rightarrow> bool "("_\\<turnstile>_ -_\\<rightarrow> _" [51,82,82, 82]81) |
8011 | 22 |
|
23 |
translations |
|
24 |
"G\\<turnstile>s -e \\<succ> v\\<rightarrow> (x,s')" == "(s, e, v, _args x s') \\<in> eval G" |
|
25 |
"G\\<turnstile>s -e \\<succ> v\\<rightarrow> s' " == "(s, e, v, s') \\<in> eval G" |
|
26 |
"G\\<turnstile>s -e[\\<succ>]v\\<rightarrow> (x,s')" == "(s, e, v, _args x s') \\<in> evals G" |
|
27 |
"G\\<turnstile>s -e[\\<succ>]v\\<rightarrow> s' " == "(s, e, v, s') \\<in> evals G" |
|
28 |
"G\\<turnstile>s -c \\<rightarrow> (x,s')" == "(s, c, _args x s') \\<in> exec G" |
|
29 |
"G\\<turnstile>s -c \\<rightarrow> s' " == "(s, c, s') \\<in> exec G" |
|
30 |
||
31 |
inductive "eval G" "evals G" "exec G" intrs |
|
32 |
||
33 |
(* evaluation of expressions *) |
|
34 |
||
35 |
(* cf. 15.5 *) |
|
36 |
XcptE "G\\<turnstile>(Some xc,s) -e\\<succ>arbitrary\\<rightarrow> (Some xc,s)" |
|
37 |
||
38 |
(* cf. 15.8.1 *) |
|
39 |
NewC "\\<lbrakk>h = heap s; (a,x) = new_Addr h; |
|
40 |
h'= h(a\\<mapsto>(C,init_vars (fields (G,C))))\\<rbrakk> \\<Longrightarrow> |
|
41 |
G\\<turnstile>Norm s -NewC C\\<succ>Addr a\\<rightarrow> c_hupd h' (x,s)" |
|
42 |
||
43 |
(* cf. 15.15 *) |
|
44 |
Cast "\\<lbrakk>G\\<turnstile>Norm s0 -e\\<succ>v\\<rightarrow> (x1,s1); |
|
45 |
x2=raise_if (\\<not> cast_ok G T (heap s1) v) ClassCast x1\\<rbrakk> \\<Longrightarrow> |
|
46 |
G\\<turnstile>Norm s0 -Cast T e\\<succ>v\\<rightarrow> (x2,s1)" |
|
47 |
||
48 |
(* cf. 15.7.1 *) |
|
49 |
Lit "G\\<turnstile>Norm s -Lit v\\<succ>v\\<rightarrow> Norm s" |
|
50 |
||
9240 | 51 |
BinOp "\\<lbrakk>G\\<turnstile>Norm s -e1\\<succ>v1\\<rightarrow> s1; |
52 |
G\\<turnstile>s1 -e1\\<succ>v2\\<rightarrow> s2; |
|
53 |
v = (case bop of Eq \\<Rightarrow> Bool (v1 = v2) |
|
54 |
| Add \\<Rightarrow> Intg (the_Intg v1 + the_Intg v2))\\<rbrakk> \\<Longrightarrow> |
|
55 |
G\\<turnstile>Norm s -BinOp bop e1 e2\\<succ>v\\<rightarrow> s2" |
|
56 |
||
8011 | 57 |
(* cf. 15.13.1, 15.2 *) |
58 |
LAcc "G\\<turnstile>Norm s -LAcc v\\<succ>the (locals s v)\\<rightarrow> Norm s" |
|
59 |
||
60 |
(* cf. 15.25.1 *) |
|
61 |
LAss "\\<lbrakk>G\\<turnstile>Norm s -e\\<succ>v\\<rightarrow> (x,(h,l)); |
|
62 |
l' = (if x = None then l(va\\<mapsto>v) else l)\\<rbrakk> \\<Longrightarrow> |
|
63 |
G\\<turnstile>Norm s -va\\<Colon>=e\\<succ>v\\<rightarrow> (x,(h,l'))" |
|
64 |
||
65 |
||
66 |
(* cf. 15.10.1, 15.2 *) |
|
67 |
FAcc "\\<lbrakk>G\\<turnstile>Norm s0 -e\\<succ>a'\\<rightarrow> (x1,s1); |
|
68 |
v = the (snd (the (heap s1 (the_Addr a'))) (fn,T))\\<rbrakk> \\<Longrightarrow> |
|
69 |
G\\<turnstile>Norm s0 -{T}e..fn\\<succ>v\\<rightarrow> (np a' x1,s1)" |
|
70 |
||
71 |
(* cf. 15.25.1 *) |
|
72 |
FAss "\\<lbrakk>G\\<turnstile> Norm s0 -e1\\<succ>a'\\<rightarrow> (x1,s1); a = the_Addr a'; |
|
73 |
G\\<turnstile>(np a' x1,s1) -e2\\<succ>v \\<rightarrow> (x2,s2); |
|
74 |
h = heap s2; (c,fs) = the (h a); |
|
75 |
h' = h(a\\<mapsto>(c,(fs((fn,T)\\<mapsto>v))))\\<rbrakk> \\<Longrightarrow> |
|
76 |
G\\<turnstile>Norm s0 -{T}e1..fn\\<in>=e2\\<succ>v\\<rightarrow> c_hupd h' (x2,s2)" |
|
77 |
||
78 |
(* cf. 15.11.4.1, 15.11.4.2, 15.11.4.4, 15.11.4.5, 14.15 *) |
|
79 |
Call "\\<lbrakk>G\\<turnstile>Norm s0 -e\\<succ>a'\\<rightarrow> s1; a = the_Addr a'; |
|
80 |
G\\<turnstile>s1 -ps[\\<succ>]pvs\\<rightarrow> (x,(h,l)); dynT = fst (the (h a)); |
|
8034
6fc37b5c5e98
Various little changes like cmethd -> method and cfield -> field.
nipkow
parents:
8011
diff
changeset
|
81 |
(md,rT,pns,lvars,blk,res) = the (method (G,dynT) (mn,pTs)); |
8011 | 82 |
G\\<turnstile>(np a' x,(h,(init_vars lvars)(pns[\\<mapsto>]pvs)(This\\<mapsto>a'))) -blk\\<rightarrow> s3; |
83 |
G\\<turnstile> s3 -res\\<succ>v \\<rightarrow> (x4,s4)\\<rbrakk> \\<Longrightarrow> |
|
84 |
G\\<turnstile>Norm s0 -e..mn({pTs}ps)\\<succ>v\\<rightarrow> (x4,(heap s4,l))" |
|
85 |
||
86 |
||
87 |
(* evaluation of expression lists *) |
|
88 |
||
89 |
(* cf. 15.5 *) |
|
90 |
XcptEs "G\\<turnstile>(Some xc,s) -e[\\<succ>]arbitrary\\<rightarrow> (Some xc,s)" |
|
91 |
||
92 |
(* cf. 15.11.??? *) |
|
93 |
Nil |
|
94 |
"G\\<turnstile>Norm s0 -[][\\<succ>][]\\<rightarrow> Norm s0" |
|
95 |
||
96 |
(* cf. 15.6.4 *) |
|
97 |
Cons "\\<lbrakk>G\\<turnstile>Norm s0 -e \\<succ> v \\<rightarrow> s1; |
|
98 |
G\\<turnstile> s1 -es[\\<succ>]vs\\<rightarrow> s2\\<rbrakk> \\<Longrightarrow> |
|
99 |
G\\<turnstile>Norm s0 -e#es[\\<succ>]v#vs\\<rightarrow> s2" |
|
100 |
||
101 |
(* execution of statements *) |
|
102 |
||
103 |
(* cf. 14.1 *) |
|
104 |
XcptS "G\\<turnstile>(Some xc,s) -s0\\<rightarrow> (Some xc,s)" |
|
105 |
||
106 |
(* cf. 14.5 *) |
|
107 |
Skip "G\\<turnstile>Norm s -Skip\\<rightarrow> Norm s" |
|
108 |
||
109 |
(* cf. 14.7 *) |
|
110 |
Expr "\\<lbrakk>G\\<turnstile>Norm s0 -e\\<succ>v\\<rightarrow> s1\\<rbrakk> \\<Longrightarrow> |
|
111 |
G\\<turnstile>Norm s0 -Expr e\\<rightarrow> s1" |
|
112 |
||
113 |
(* cf. 14.2 *) |
|
114 |
Comp "\\<lbrakk>G\\<turnstile>Norm s0 -s \\<rightarrow> s1; |
|
115 |
G\\<turnstile> s1 -t \\<rightarrow> s2\\<rbrakk> \\<Longrightarrow> |
|
116 |
G\\<turnstile>Norm s0 -(s;; t)\\<rightarrow> s2" |
|
117 |
||
118 |
(* cf. 14.8.2 *) |
|
119 |
Cond "\\<lbrakk>G\\<turnstile>Norm s0 -e \\<succ>v\\<rightarrow> s1; |
|
120 |
G\\<turnstile> s1 -(if the_Bool v then s else t)\\<rightarrow> s2\\<rbrakk> \\<Longrightarrow> |
|
121 |
G\\<turnstile>Norm s0 -(If(e) s Else t)\\<rightarrow> s2" |
|
122 |
||
123 |
(* cf. 14.10, 14.10.1 *) |
|
124 |
Loop "\\<lbrakk>G\\<turnstile>Norm s0 -(If(e) (s;; While(e) s) Else Skip)\\<rightarrow> s1\\<rbrakk> \\<Longrightarrow> |
|
125 |
G\\<turnstile>Norm s0 -(While(e) s)\\<rightarrow> s1" |
|
126 |
||
127 |
end |