author | oheimb |
Fri, 14 Jul 2000 16:32:51 +0200 | |
changeset 9346 | 297dcbf64526 |
parent 8038 | a13c3b80d3d4 |
child 9348 | f495dba0cb07 |
permissions | -rw-r--r-- |
8011 | 1 |
(* Title: HOL/MicroJava/JVM/Object.thy |
2 |
ID: $Id$ |
|
3 |
Author: Cornelia Pusch |
|
4 |
Copyright 1999 Technische Universitaet Muenchen |
|
5 |
||
6 |
Get and putfield instructions |
|
7 |
*) |
|
8 |
||
9 |
Object = JVMState + |
|
10 |
||
11 |
datatype |
|
12 |
create_object = New cname |
|
13 |
||
14 |
consts |
|
15 |
exec_co :: "[create_object,'code prog,aheap,opstack,p_count] \\<Rightarrow> |
|
16 |
(xcpt option \\<times> aheap \\<times> opstack \\<times> p_count)" |
|
17 |
||
18 |
||
19 |
primrec |
|
20 |
"exec_co (New C) G hp stk pc = |
|
21 |
(let xp' = raise_xcpt (\\<forall>x. hp x \\<noteq> None) OutOfMemory; |
|
22 |
oref = newref hp; |
|
23 |
fs = init_vars (fields(G,C)); |
|
8034
6fc37b5c5e98
Various little changes like cmethd -> method and cfield -> field.
nipkow
parents:
8011
diff
changeset
|
24 |
hp' = if xp'=None then hp(oref \\<mapsto> (C,fs)) else hp; |
6fc37b5c5e98
Various little changes like cmethd -> method and cfield -> field.
nipkow
parents:
8011
diff
changeset
|
25 |
stk' = if xp'=None then (Addr oref)#stk else stk |
8011 | 26 |
in (xp' , hp' , stk' , pc+1))" |
27 |
||
28 |
||
29 |
datatype |
|
30 |
manipulate_object = |
|
31 |
Getfield vname cname (* Fetch field from object *) |
|
32 |
| Putfield vname cname (* Set field in object *) |
|
33 |
||
34 |
consts |
|
35 |
exec_mo :: "[manipulate_object,aheap,opstack,p_count] \\<Rightarrow> |
|
36 |
(xcpt option \\<times> aheap \\<times> opstack \\<times> p_count)" |
|
37 |
||
38 |
primrec |
|
39 |
"exec_mo (Getfield F C) hp stk pc = |
|
40 |
(let oref = hd stk; |
|
41 |
xp' = raise_xcpt (oref=Null) NullPointer; |
|
8038 | 42 |
(oc,fs) = the(hp(the_Addr oref)); |
43 |
stk' = if xp'=None then the(fs(F,C))#(tl stk) else tl stk |
|
8011 | 44 |
in |
45 |
(xp' , hp , stk' , pc+1))" |
|
46 |
||
47 |
"exec_mo (Putfield F C) hp stk pc = |
|
48 |
(let (fval,oref)= (hd stk, hd(tl stk)); |
|
49 |
xp' = raise_xcpt (oref=Null) NullPointer; |
|
50 |
a = the_Addr oref; |
|
8038 | 51 |
(oc,fs) = the(hp a); |
8034
6fc37b5c5e98
Various little changes like cmethd -> method and cfield -> field.
nipkow
parents:
8011
diff
changeset
|
52 |
hp' = if xp'=None then hp(a \\<mapsto> (oc, fs((F,C) \\<mapsto> fval))) else hp |
8011 | 53 |
in |
54 |
(xp' , hp' , tl (tl stk), pc+1))" |
|
55 |
||
56 |
||
57 |
datatype |
|
58 |
check_object = |
|
59 |
Checkcast cname (* Check whether object is of given type *) |
|
60 |
||
61 |
consts |
|
62 |
exec_ch :: "[check_object,'code prog,aheap,opstack,p_count] |
|
63 |
\\<Rightarrow> (xcpt option \\<times> opstack \\<times> p_count)" |
|
64 |
||
65 |
primrec |
|
66 |
"exec_ch (Checkcast C) G hp stk pc = |
|
67 |
(let oref = hd stk; |
|
9346
297dcbf64526
re-structuring MicroJava; added Example; corrected := syntax; simplfied cast
oheimb
parents:
8038
diff
changeset
|
68 |
xp' = raise_xcpt (\\<not> cast_ok G (ClassT C) hp oref) ClassCast; |
8034
6fc37b5c5e98
Various little changes like cmethd -> method and cfield -> field.
nipkow
parents:
8011
diff
changeset
|
69 |
stk' = if xp'=None then stk else tl stk |
8011 | 70 |
in |
71 |
(xp' , stk' , pc+1))" |
|
72 |
||
73 |
end |