author | wenzelm |
Sun, 30 Sep 2007 21:55:15 +0200 | |
changeset 24783 | 5a3e336a2e37 |
parent 24340 | 811f78424efc |
child 28408 | e26aac53723d |
permissions | -rw-r--r-- |
12442 | 1 |
(* Title: HOL/MicroJava/JVM/JVMListExample.thy |
2 |
ID: $Id$ |
|
3 |
Author: Stefan Berghofer |
|
4 |
*) |
|
5 |
||
12973 | 6 |
header {* \isaheader{Example for generating executable code from JVM semantics}\label{sec:JVMListExample} *} |
12442 | 7 |
|
24340 | 8 |
theory JVMListExample imports "../J/SystemClasses" JVMExec begin |
12442 | 9 |
|
10 |
consts |
|
12951 | 11 |
list_nam :: cnam |
12 |
test_nam :: cnam |
|
12442 | 13 |
append_name :: mname |
14 |
makelist_name :: mname |
|
15 |
val_nam :: vnam |
|
16 |
next_nam :: vnam |
|
17 |
||
18 |
constdefs |
|
12951 | 19 |
list_name :: cname |
20 |
"list_name == Cname list_nam" |
|
21 |
||
22 |
test_name :: cname |
|
23 |
"test_name == Cname test_nam" |
|
24 |
||
12442 | 25 |
val_name :: vname |
26 |
"val_name == VName val_nam" |
|
27 |
||
28 |
next_name :: vname |
|
29 |
"next_name == VName next_nam" |
|
30 |
||
12951 | 31 |
append_ins :: bytecode |
32 |
"append_ins == |
|
12442 | 33 |
[Load 0, |
34 |
Getfield next_name list_name, |
|
35 |
Dup, |
|
36 |
LitPush Null, |
|
37 |
Ifcmpeq 4, |
|
12951 | 38 |
Load 1, |
39 |
Invoke list_name append_name [Class list_name], |
|
12442 | 40 |
Return, |
41 |
Pop, |
|
42 |
Load 0, |
|
43 |
Load 1, |
|
44 |
Putfield next_name list_name, |
|
45 |
LitPush Unit, |
|
12951 | 46 |
Return]" |
12442 | 47 |
|
12951 | 48 |
list_class :: "jvm_method class" |
49 |
"list_class == |
|
50 |
(Object, |
|
51 |
[(val_name, PrimT Integer), (next_name, Class list_name)], |
|
52 |
[((append_name, [Class list_name]), PrimT Void, |
|
53 |
(3, 0, append_ins,[(1,2,8,Xcpt NullPointer)]))])" |
|
54 |
||
55 |
make_list_ins :: bytecode |
|
56 |
"make_list_ins == |
|
12442 | 57 |
[New list_name, |
58 |
Dup, |
|
59 |
Store 0, |
|
60 |
LitPush (Intg 1), |
|
61 |
Putfield val_name list_name, |
|
62 |
New list_name, |
|
63 |
Dup, |
|
64 |
Store 1, |
|
65 |
LitPush (Intg 2), |
|
66 |
Putfield val_name list_name, |
|
67 |
New list_name, |
|
68 |
Dup, |
|
69 |
Store 2, |
|
70 |
LitPush (Intg 3), |
|
71 |
Putfield val_name list_name, |
|
72 |
Load 0, |
|
73 |
Load 1, |
|
12951 | 74 |
Invoke list_name append_name [Class list_name], |
13101 | 75 |
Pop, |
12442 | 76 |
Load 0, |
77 |
Load 2, |
|
12951 | 78 |
Invoke list_name append_name [Class list_name], |
79 |
Return]" |
|
80 |
||
81 |
test_class :: "jvm_method class" |
|
82 |
"test_class == |
|
83 |
(Object, [], |
|
84 |
[((makelist_name, []), PrimT Void, (3, 2, make_list_ins,[]))])" |
|
12442 | 85 |
|
12951 | 86 |
E :: jvm_prog |
87 |
"E == SystemClasses @ [(list_name, list_class), (test_name, test_class)]" |
|
88 |
||
12442 | 89 |
|
90 |
types_code |
|
12951 | 91 |
cnam ("string") |
12442 | 92 |
vnam ("string") |
93 |
mname ("string") |
|
24783 | 94 |
loc' ("int") |
12442 | 95 |
|
96 |
consts_code |
|
16770
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
97 |
"new_Addr" ("\<module>new'_addr {* %x. case x of None => True | Some y => False *}/ {* None *}/ {* Loc *}") |
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
98 |
attach {* |
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
99 |
fun new_addr p none loc hp = |
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
100 |
let fun nr i = if p (hp (loc i)) then (loc i, none) else nr (i+1); |
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
101 |
in nr 0 end; |
1f1b1fae30e4
Auxiliary functions to be used in generated code are now defined using "attach".
berghofe
parents:
16644
diff
changeset
|
102 |
*} |
12442 | 103 |
|
18679 | 104 |
"arbitrary" ("(raise Match)") |
22921
475ff421a6a3
consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents:
21404
diff
changeset
|
105 |
"arbitrary :: val" ("{* Unit *}") |
475ff421a6a3
consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents:
21404
diff
changeset
|
106 |
"arbitrary :: cname" ("{* Object *}") |
12442 | 107 |
|
12951 | 108 |
"list_nam" ("\"list\"") |
109 |
"test_nam" ("\"test\"") |
|
12442 | 110 |
"append_name" ("\"append\"") |
111 |
"makelist_name" ("\"makelist\"") |
|
112 |
"val_nam" ("\"val\"") |
|
113 |
"next_nam" ("\"next\"") |
|
114 |
||
20971 | 115 |
definition |
116 |
"test = exec (E, start_state E test_name makelist_name)" |
|
117 |
||
118 |
||
12442 | 119 |
subsection {* Single step execution *} |
120 |
||
17145 | 121 |
code_module JVM |
122 |
contains |
|
24225 | 123 |
exec = exec |
124 |
test = test |
|
12442 | 125 |
|
24074 | 126 |
ML {* |
127 |
JVM.test; |
|
128 |
JVM.exec (JVM.E, JVM.the it); |
|
129 |
JVM.exec (JVM.E, JVM.the it); |
|
130 |
JVM.exec (JVM.E, JVM.the it); |
|
131 |
JVM.exec (JVM.E, JVM.the it); |
|
132 |
JVM.exec (JVM.E, JVM.the it); |
|
133 |
JVM.exec (JVM.E, JVM.the it); |
|
134 |
JVM.exec (JVM.E, JVM.the it); |
|
135 |
JVM.exec (JVM.E, JVM.the it); |
|
136 |
JVM.exec (JVM.E, JVM.the it); |
|
137 |
JVM.exec (JVM.E, JVM.the it); |
|
138 |
JVM.exec (JVM.E, JVM.the it); |
|
139 |
JVM.exec (JVM.E, JVM.the it); |
|
140 |
JVM.exec (JVM.E, JVM.the it); |
|
141 |
JVM.exec (JVM.E, JVM.the it); |
|
142 |
JVM.exec (JVM.E, JVM.the it); |
|
143 |
JVM.exec (JVM.E, JVM.the it); |
|
144 |
JVM.exec (JVM.E, JVM.the it); |
|
145 |
JVM.exec (JVM.E, JVM.the it); |
|
146 |
JVM.exec (JVM.E, JVM.the it); |
|
147 |
JVM.exec (JVM.E, JVM.the it); |
|
148 |
JVM.exec (JVM.E, JVM.the it); |
|
149 |
JVM.exec (JVM.E, JVM.the it); |
|
150 |
JVM.exec (JVM.E, JVM.the it); |
|
151 |
JVM.exec (JVM.E, JVM.the it); |
|
152 |
JVM.exec (JVM.E, JVM.the it); |
|
153 |
JVM.exec (JVM.E, JVM.the it); |
|
154 |
JVM.exec (JVM.E, JVM.the it); |
|
155 |
JVM.exec (JVM.E, JVM.the it); |
|
156 |
JVM.exec (JVM.E, JVM.the it); |
|
157 |
JVM.exec (JVM.E, JVM.the it); |
|
158 |
JVM.exec (JVM.E, JVM.the it); |
|
159 |
JVM.exec (JVM.E, JVM.the it); |
|
160 |
JVM.exec (JVM.E, JVM.the it); |
|
161 |
JVM.exec (JVM.E, JVM.the it); |
|
162 |
JVM.exec (JVM.E, JVM.the it); |
|
163 |
JVM.exec (JVM.E, JVM.the it); |
|
164 |
JVM.exec (JVM.E, JVM.the it); |
|
165 |
JVM.exec (JVM.E, JVM.the it); |
|
166 |
JVM.exec (JVM.E, JVM.the it); |
|
167 |
JVM.exec (JVM.E, JVM.the it); |
|
168 |
JVM.exec (JVM.E, JVM.the it); |
|
169 |
JVM.exec (JVM.E, JVM.the it); |
|
170 |
JVM.exec (JVM.E, JVM.the it); |
|
171 |
JVM.exec (JVM.E, JVM.the it); |
|
172 |
JVM.exec (JVM.E, JVM.the it); |
|
173 |
JVM.exec (JVM.E, JVM.the it); |
|
174 |
JVM.exec (JVM.E, JVM.the it); |
|
175 |
JVM.exec (JVM.E, JVM.the it); |
|
176 |
JVM.exec (JVM.E, JVM.the it); |
|
177 |
JVM.exec (JVM.E, JVM.the it); |
|
178 |
JVM.exec (JVM.E, JVM.the it); |
|
179 |
JVM.exec (JVM.E, JVM.the it); |
|
180 |
JVM.exec (JVM.E, JVM.the it); |
|
181 |
*} |
|
12442 | 182 |
|
12973 | 183 |
end |