1 (* Title: HOL/MicroJava/JVM/JVMExecInstr.thy |
1 (* Title: HOL/MicroJava/JVM/JVMExecInstr.thy |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Cornelia Pusch, Gerwin Klein |
3 Author: Cornelia Pusch, Gerwin Klein |
4 Copyright 1999 Technische Universitaet Muenchen |
4 Copyright 1999 Technische Universitaet Muenchen |
5 |
|
6 Semantics of JVM instructions |
|
7 *) |
5 *) |
8 |
6 |
9 JVMExecInstr = JVMInstructions + JVMState + |
7 |
|
8 header {* JVM Instruction Semantics *} |
|
9 |
|
10 |
|
11 theory JVMExecInstr = JVMInstructions + JVMState: |
|
12 |
10 |
13 |
11 consts |
14 consts |
12 exec_instr :: "[instr, jvm_prog, aheap, opstack, locvars, |
15 exec_instr :: "[instr, jvm_prog, aheap, opstack, locvars, |
13 cname, sig, p_count, frame list] => jvm_state" |
16 cname, sig, p_count, frame list] => jvm_state" |
14 primrec |
17 primrec |
23 |
26 |
24 "exec_instr Aconst_null G hp stk vars Cl sig pc frs = |
27 "exec_instr Aconst_null G hp stk vars Cl sig pc frs = |
25 (None, hp, (Null # stk, vars, Cl, sig, pc+1)#frs)" |
28 (None, hp, (Null # stk, vars, Cl, sig, pc+1)#frs)" |
26 |
29 |
27 "exec_instr (New C) G hp stk vars Cl sig pc frs = |
30 "exec_instr (New C) G hp stk vars Cl sig pc frs = |
28 (let xp' = raise_xcpt (\\<forall>x. hp x \\<noteq> None) OutOfMemory; |
31 (let xp' = raise_xcpt (\<forall>x. hp x \<noteq> None) OutOfMemory; |
29 oref = newref hp; |
32 oref = newref hp; |
30 fs = init_vars (fields(G,C)); |
33 fs = init_vars (fields(G,C)); |
31 hp' = if xp'=None then hp(oref \\<mapsto> (C,fs)) else hp; |
34 hp' = if xp'=None then hp(oref \<mapsto> (C,fs)) else hp; |
32 stk' = if xp'=None then (Addr oref)#stk else stk |
35 stk' = if xp'=None then (Addr oref)#stk else stk |
33 in |
36 in |
34 (xp', hp', (stk', vars, Cl, sig, pc+1)#frs))" |
37 (xp', hp', (stk', vars, Cl, sig, pc+1)#frs))" |
35 |
38 |
36 "exec_instr (Getfield F C) G hp stk vars Cl sig pc frs = |
39 "exec_instr (Getfield F C) G hp stk vars Cl sig pc frs = |
44 "exec_instr (Putfield F C) G hp stk vars Cl sig pc frs = |
47 "exec_instr (Putfield F C) G hp stk vars Cl sig pc frs = |
45 (let (fval,oref)= (hd stk, hd(tl stk)); |
48 (let (fval,oref)= (hd stk, hd(tl stk)); |
46 xp' = raise_xcpt (oref=Null) NullPointer; |
49 xp' = raise_xcpt (oref=Null) NullPointer; |
47 a = the_Addr oref; |
50 a = the_Addr oref; |
48 (oc,fs) = the(hp a); |
51 (oc,fs) = the(hp a); |
49 hp' = if xp'=None then hp(a \\<mapsto> (oc, fs((F,C) \\<mapsto> fval))) else hp |
52 hp' = if xp'=None then hp(a \<mapsto> (oc, fs((F,C) \<mapsto> fval))) else hp |
50 in |
53 in |
51 (xp', hp', (tl (tl stk), vars, Cl, sig, pc+1)#frs))" |
54 (xp', hp', (tl (tl stk), vars, Cl, sig, pc+1)#frs))" |
52 |
55 |
53 "exec_instr (Checkcast C) G hp stk vars Cl sig pc frs = |
56 "exec_instr (Checkcast C) G hp stk vars Cl sig pc frs = |
54 (let oref = hd stk; |
57 (let oref = hd stk; |
55 xp' = raise_xcpt (\\<not> cast_ok G C hp oref) ClassCast; |
58 xp' = raise_xcpt (\<not> cast_ok G C hp oref) ClassCast; |
56 stk' = if xp'=None then stk else tl stk |
59 stk' = if xp'=None then stk else tl stk |
57 in |
60 in |
58 (xp', hp, (stk', vars, Cl, sig, pc+1)#frs))" |
61 (xp', hp, (stk', vars, Cl, sig, pc+1)#frs))" |
59 |
62 |
60 "exec_instr (Invoke C mn ps) G hp stk vars Cl sig pc frs = |
63 "exec_instr (Invoke C mn ps) G hp stk vars Cl sig pc frs = |