src/HOL/Bali/Trans.thy
author schirmer
Fri Feb 22 11:26:44 2002 +0100 (2002-02-22)
changeset 12925 99131847fb93
parent 12858 6214f03d6d27
child 13337 f75dfc606ac7
permissions -rw-r--r--
Added check for field/method access to operational semantics and proved the acesses valid.
wenzelm@12857
     1
(*  Title:      HOL/Bali/Trans.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
wenzelm@12858
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
schirmer@12854
     5
schirmer@12854
     6
Operational transition (small-step) semantics of the 
schirmer@12854
     7
execution of Java expressions and statements
schirmer@12854
     8
schirmer@12854
     9
PRELIMINARY!!!!!!!!
schirmer@12854
    10
schirmer@12925
    11
improvements over Java Specification 1.0 (cf. 15.11.4.4):
schirmer@12925
    12
* dynamic method lookup does not need to check the return type
schirmer@12925
    13
* throw raises a NullPointer exception if a null reference is given, and each
schirmer@12925
    14
  throw of a system exception yield a fresh exception object (was not specified)
schirmer@12925
    15
* if there is not enough memory even to allocate an OutOfMemory exception,
schirmer@12925
    16
  evaluation/execution fails, i.e. simply stops (was not specified)
schirmer@12925
    17
schirmer@12925
    18
design issues:
schirmer@12925
    19
* Lit expressions and Skip statements are considered completely evaluated.
schirmer@12925
    20
* the expr entry in rules is redundant in case of exceptions, but its full
schirmer@12925
    21
  inclusion helps to make the rule structure independent of exception occurence.
schirmer@12925
    22
* the rule format is such that the start state may contain an exception.
schirmer@12925
    23
  ++ faciliates exception handling (to be added later)
schirmer@12925
    24
  +  symmetry
schirmer@12925
    25
* the rules are defined carefully in order to be applicable even in not
schirmer@12925
    26
  type-correct situations (yielding undefined values),
schirmer@12925
    27
  e.g. the_Adr (Val (Bool b)) = arbitrary.
schirmer@12925
    28
  ++ fewer rules 
schirmer@12925
    29
  -  less readable because of auxiliary functions like the_Adr
schirmer@12925
    30
  Alternative: "defensive" evaluation throwing some InternalError exception
schirmer@12925
    31
               in case of (impossible, for correct programs) type mismatches
schirmer@12925
    32
schirmer@12925
    33
simplifications:
schirmer@12925
    34
* just simple handling (i.e. propagation) of exceptions so far
schirmer@12925
    35
* dynamic method lookup does not check return type (should not be necessary)
schirmer@12854
    36
*)
schirmer@12854
    37
schirmer@12854
    38
Trans = Eval +
schirmer@12854
    39
schirmer@12854
    40
consts
schirmer@12925
    41
  texpr_tstmt	:: "prog  (((expr  state)  (expr  state)) +
schirmer@12925
    42
		            ((stmt  state)  (stmt  state))) set"
schirmer@12854
    43
schirmer@12854
    44
syntax (symbols)
schirmer@12925
    45
  texpr :: "[prog, expr  state, expr  state]  bool "("__ 1 _"[61,82,82] 81)
schirmer@12925
    46
  tstmt :: "[prog, stmt  state, stmt  state]  bool "("__ 1 _"[61,82,82] 81)
schirmer@12925
    47
  Ref   :: "loc  expr"
schirmer@12854
    48
schirmer@12854
    49
translations
schirmer@12854
    50
schirmer@12925
    51
  "Ge_s 1 ex_s'" == "Inl (e_s, ex_s')  texpr_tstmt G"
schirmer@12925
    52
  "Gs_s 1 s'_s'" == "Inr (s_s, s'_s')  texpr_tstmt G"
schirmer@12854
    53
  "Ref a" == "Lit (Addr a)"
schirmer@12854
    54
schirmer@12925
    55
constdefs
schirmer@12925
    56
  
schirmer@12925
    57
  sub_expr_expr :: "(expr  expr)  prop"
schirmer@12925
    58
  "sub_expr_expr ef  (G e s e' s'. G(   e,s) 1 (   e',s') 
schirmer@12925
    59
				     G(ef e,s) 1 (ef e',s'))"
schirmer@12925
    60
schirmer@12854
    61
inductive "texpr_tstmt G" intrs 
schirmer@12854
    62
schirmer@12854
    63
(* evaluation of expression *)
schirmer@12854
    64
  (* cf. 15.5 *)
schirmer@12925
    65
  XcptE	"v. e  Lit v 
schirmer@12925
    66
				  G(e,Some xc,s) 1 (Lit arbitrary,Some xc,s)"
schirmer@12854
    67
schirmer@12925
    68
 CastXX "PROP sub_expr_expr (Cast T)"
schirmer@12925
    69
schirmer@12925
    70
(*
schirmer@12854
    71
  (* cf. 15.8.1 *)
schirmer@12925
    72
  NewC	"new_Addr (heap s) = Some (a,x);
schirmer@12925
    73
	  s' = assign (hupd[ainit_Obj G C]s) (x,s) 
schirmer@12925
    74
				G(NewC C,None,s) 1 (Ref a,s')"
schirmer@12854
    75
schirmer@12854
    76
  (* cf. 15.9.1 *)
schirmer@12925
    77
(*NewA1	"sub_expr_expr (NewA T)"*)
schirmer@12925
    78
  NewA1	"G(e,None,s) 1 (e',s') 
schirmer@12925
    79
			      G(New T[e],None,s) 1 (New T[e'],s')"
schirmer@12925
    80
  NewA	"i = the_Intg i'; new_Addr (heap s) = Some (a, x);
schirmer@12925
    81
	  s' = assign (hupd[ainit_Arr T i]s)(raise_if (i<#0) NegArrSize x,s) 
schirmer@12925
    82
			G(New T[Lit i'],None,s) 1 (Ref a,s')"
schirmer@12854
    83
  (* cf. 15.15 *)
schirmer@12925
    84
  Cast1	"G(e,None,s) 1 (e',s') 
schirmer@12925
    85
			      G(Cast T e,None,s) 1 (Cast T e',s')"
schirmer@12925
    86
  Cast	"x'= raise_if (\<questiondown>G,sv fits T) ClassCast None 
schirmer@12925
    87
		        G(Cast T (Lit v),None,s) 1 (Lit v,x',s)"
schirmer@12854
    88
schirmer@12854
    89
  (* cf. 15.7.1 *)
schirmer@12925
    90
(*Lit				"G(Lit v,None,s) 1 (Lit v,None,s)"*)
schirmer@12854
    91
schirmer@12854
    92
  (* cf. 15.13.1, 15.2 *)
schirmer@12925
    93
  LAcc	"v = the (locals s vn) 
schirmer@12925
    94
			       G(LAcc vn,None,s) 1 (Lit v,None,s)"
schirmer@12854
    95
schirmer@12854
    96
  (* cf. 15.25.1 *)
schirmer@12925
    97
  LAss1	"G(e,None,s) 1 (e',s') 
schirmer@12925
    98
				 G(f vn:=e,None,s) 1 (vn:=e',s')"
schirmer@12925
    99
  LAss			    "G(f vn:=Lit v,None,s) 1 (Lit v,None,lupd[vnv]s)"
schirmer@12854
   100
schirmer@12854
   101
  (* cf. 15.10.1, 15.2 *)
schirmer@12925
   102
  FAcc1	"G(e,None,s) 1 (e',s') 
schirmer@12925
   103
			       G({T}e..fn,None,s) 1 ({T}e'..fn,s')"
schirmer@12925
   104
  FAcc	"v = the (snd (the_Obj (heap s (the_Addr a'))) (fn,T)) 
schirmer@12925
   105
			  G({T}Lit a'..fn,None,s) 1 (Lit v,np a' None,s)"
schirmer@12854
   106
schirmer@12854
   107
  (* cf. 15.25.1 *)
schirmer@12925
   108
  FAss1	"G(e1,None,s) 1 (e1',s') 
schirmer@12925
   109
			  G(f ({T}e1..fn):=e2,None,s) 1 (f({T}e1'..fn):=e2,s')"
schirmer@12925
   110
  FAss2	"G(e2,np a' None,s) 1 (e2',s') 
schirmer@12925
   111
		      G(f({T}Lit a'..fn):=e2,None,s) 1 (f({T}Lit a'..fn):=e2',s')"
schirmer@12925
   112
  FAss	"a = the_Addr a'; (c,fs) = the_Obj (heap s a);
schirmer@12925
   113
	  s'= assign (hupd[aObj c (fs[(fn,T)v])]s) (None,s) 
schirmer@12925
   114
		   G(f({T}Lit a'..fn):=Lit v,None,s) 1 (Lit v,s')"
schirmer@12854
   115
schirmer@12854
   116
schirmer@12854
   117
schirmer@12854
   118
schirmer@12854
   119
schirmer@12854
   120
  (* cf. 15.12.1 *)
schirmer@12925
   121
  AAcc1	"G(e1,None,s) 1 (e1',s') 
schirmer@12925
   122
				G(e1[e2],None,s) 1 (e1'[e2],s')"
schirmer@12925
   123
  AAcc2	"G(e2,None,s) 1 (e2',s') 
schirmer@12925
   124
			    G(Lit a'[e2],None,s) 1 (Lit a'[e2'],s')"
schirmer@12925
   125
  AAcc	"vo = snd (the_Arr (heap s (the_Addr a'))) (the_Intg i');
schirmer@12925
   126
	  x' = raise_if (vo = None) IndOutBound (np a' None) 
schirmer@12925
   127
			G(Lit a'[Lit i'],None,s) 1 (Lit (the vo),x',s)"
schirmer@12854
   128
schirmer@12854
   129
schirmer@12854
   130
  (* cf. 15.11.4.1, 15.11.4.2, 15.11.4.4, 15.11.4.5, 14.15 *)
schirmer@12925
   131
  Call1	"G(e,None,s) 1 (e',s') 
schirmer@12925
   132
			  G(e..mn({pT}p),None,s) 1 (e'..mn({pT}p),s')"
schirmer@12925
   133
  Call2	"G(p,None,s) 1 (p',s') 
schirmer@12925
   134
		     G(Lit a'..mn({pT}p),None,s) 1 (Lit a'..mn({pT}p'),s')"
schirmer@12925
   135
  Call	"a = the_Addr a'; (md,(pn,rT),lvars,blk,res) = 
schirmer@12925
   136
 			   the (cmethd G (fst (the_Obj (h a))) (mn,pT)) 
schirmer@12925
   137
	    G(Lit a'..mn({pT}Lit pv),None,(h,l)) 1 
schirmer@12925
   138
      (Body blk res l,np a' x,(h,init_vals lvars[Thisa'][Supera'][pnpv]))"
schirmer@12925
   139
  Body1	"G(s0,None,s) 1 (s0',s') 
schirmer@12925
   140
		   G(Body s0    e      l,None,s) 1 (Body s0'  e  l,s')"
schirmer@12925
   141
  Body2	"G(e ,None,s) 1 (e',s') 
schirmer@12925
   142
		   G(Body Skip  e      l,None,s) 1 (Body Skip e' l,s')"
schirmer@12925
   143
  Body		  "G(Body Skip (Lit v) l,None,s) 1 (Lit v,None,(heap s,l))"
schirmer@12854
   144
schirmer@12854
   145
(* execution of statements *)
schirmer@12854
   146
schirmer@12854
   147
  (* cf. 14.1 *)
schirmer@12925
   148
  XcptS	"s0  Skip 
schirmer@12925
   149
				 G(s0,Some xc,s) 1 (Skip,Some xc,s)"
schirmer@12854
   150
schirmer@12854
   151
  (* cf. 14.5 *)
schirmer@12925
   152
(*Skip	 			 "G(Skip,None,s) 1 (Skip,None,s)"*)
schirmer@12854
   153
schirmer@12854
   154
  (* cf. 14.2 *)
schirmer@12925
   155
  Comp1	"G(s1,None,s) 1 (s1',s') 
schirmer@12925
   156
			       G(s1;; s2,None,s) 1 (s1';; s2,s')"
schirmer@12925
   157
  Comp			    "G(Skip;; s2,None,s) 1 (s2,None,s)"
schirmer@12854
   158
schirmer@12854
   159
schirmer@12854
   160
schirmer@12854
   161
schirmer@12854
   162
schirmer@12854
   163
schirmer@12854
   164
  (* cf. 14.7 *)
schirmer@12925
   165
  Expr1	"G(e ,None,s) 1 (e',s') 
schirmer@12925
   166
				G(Expr e,None,s) 1 (Expr e',s')"
schirmer@12925
   167
  Expr			 "G(Expr (Lit v),None,s) 1 (Skip,None,s)"
schirmer@12854
   168
schirmer@12854
   169
  (* cf. 14.8.2 *)
schirmer@12925
   170
  If1	"G(e ,None,s) 1 (e',s') 
schirmer@12925
   171
		      G(If(e) s1 Else s2,None,s) 1 (If(e') s1 Else s2,s')"
schirmer@12925
   172
  If		 "G(If(Lit v) s1 Else s2,None,s) 1 
schirmer@12854
   173
		    (if the_Bool v then s1 else s2,None,s)"
schirmer@12854
   174
schirmer@12854
   175
  (* cf. 14.10, 14.10.1 *)
schirmer@12925
   176
  Loop			  "G(While(e) s0,None,s) 1 
schirmer@12854
   177
			     (If(e) (s0;; While(e) s0) Else Skip,None,s)"
schirmer@12925
   178
*)
schirmer@12925
   179
  con_defs "[sub_expr_expr_def]"
schirmer@12854
   180
schirmer@12854
   181
end