src/HOL/MicroJava/J/Example.thy
changeset 12517 360e3215f029
parent 11908 82f68fd05094
child 12911 704713ca07ea
equal deleted inserted replaced
12516:d09d0f160888 12517:360e3215f029
     1 (*  Title:      isabelle/Bali/Example.thy
     1 (*  Title:      HOL/MicroJava/J/Example.thy
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     David von Oheimb
     3     Author:     David von Oheimb
     4     Copyright   1999 Technische Universitaet Muenchen
     4     Copyright   1999 Technische Universitaet Muenchen
     5 *)
     5 *)
     6 
     6 
    39 
    39 
    40 datatype cnam_ = Base_ | Ext_
    40 datatype cnam_ = Base_ | Ext_
    41 datatype vnam_ = vee_ | x_ | e_
    41 datatype vnam_ = vee_ | x_ | e_
    42 
    42 
    43 consts
    43 consts
    44 
       
    45   cnam_ :: "cnam_ => cname"
    44   cnam_ :: "cnam_ => cname"
    46   vnam_ :: "vnam_ => vnam"
    45   vnam_ :: "vnam_ => vnam"
    47 
    46 
    48 axioms (* cnam_ and vnam_ are intended to be isomorphic to cnam and vnam *)
    47 -- "@{text cnam_} and @{text vnam_} are intended to be isomorphic 
    49 
    48     to @{text cnam} and @{text vnam}"
       
    49 axioms 
    50   inj_cnam_:  "(cnam_ x = cnam_ y) = (x = y)"
    50   inj_cnam_:  "(cnam_ x = cnam_ y) = (x = y)"
    51   inj_vnam_:  "(vnam_ x = vnam_ y) = (x = y)"
    51   inj_vnam_:  "(vnam_ x = vnam_ y) = (x = y)"
    52 
    52 
    53   surj_cnam_: "\<exists>m. n = cnam_ m"
    53   surj_cnam_: "\<exists>m. n = cnam_ m"
    54   surj_vnam_: "\<exists>m. n = vnam_ m"
    54   surj_vnam_: "\<exists>m. n = vnam_ m"
    55 
    55 
    56 declare inj_cnam_ [simp] inj_vnam_ [simp]
    56 declare inj_cnam_ [simp] inj_vnam_ [simp]
    57 
    57 
    58 syntax
    58 syntax
    59 
       
    60   Base :: cname
    59   Base :: cname
    61   Ext  :: cname
    60   Ext  :: cname
    62   vee  :: vname
    61   vee  :: vname
    63   x    :: vname
    62   x    :: vname
    64   e    :: vname
    63   e    :: vname
    65 
    64 
    66 translations
    65 translations
    67 
       
    68   "Base" == "cnam_ Base_"
    66   "Base" == "cnam_ Base_"
    69   "Ext"	 == "cnam_ Ext_"
    67   "Ext"  == "cnam_ Ext_"
    70   "vee"  == "VName (vnam_ vee_)"
    68   "vee"  == "VName (vnam_ vee_)"
    71   "x"	 == "VName (vnam_ x_)"
    69   "x"  == "VName (vnam_ x_)"
    72   "e"	 == "VName (vnam_ e_)"
    70   "e"  == "VName (vnam_ e_)"
    73 
    71 
    74 axioms
    72 axioms
    75 
       
    76   Base_not_Object: "Base \<noteq> Object"
    73   Base_not_Object: "Base \<noteq> Object"
    77   Ext_not_Object:  "Ext  \<noteq> Object"
    74   Ext_not_Object:  "Ext  \<noteq> Object"
    78   e_not_This:      "e \<noteq> This"
    75   e_not_This:      "e \<noteq> This"
    79 
    76 
    80 declare Base_not_Object [simp] Ext_not_Object [simp]
    77 declare Base_not_Object [simp] Ext_not_Object [simp]
    81 declare e_not_This [simp]
    78 declare e_not_This [simp]
    82 declare Base_not_Object [THEN not_sym, simp]
    79 declare Base_not_Object [THEN not_sym, simp]
    83 declare Ext_not_Object  [THEN not_sym, simp]
    80 declare Ext_not_Object  [THEN not_sym, simp]
    84 
    81 
    85 consts
    82 consts
    86 
       
    87   foo_Base::  java_mb
    83   foo_Base::  java_mb
    88   foo_Ext ::  java_mb
    84   foo_Ext ::  java_mb
    89   BaseC   :: "java_mb cdecl"
    85   BaseC   :: "java_mb cdecl"
    90   ExtC    :: "java_mb cdecl"
    86   ExtC    :: "java_mb cdecl"
    91   test	  ::  stmt
    87   test    ::  stmt
    92   foo	  ::  mname
    88   foo   ::  mname
    93   a	  ::  loc
    89   a   ::  loc
    94   b       ::  loc
    90   b       ::  loc
    95 
    91 
    96 defs
    92 defs
    97 
       
    98   foo_Base_def:"foo_Base == ([x],[],Skip,LAcc x)"
    93   foo_Base_def:"foo_Base == ([x],[],Skip,LAcc x)"
    99   BaseC_def:"BaseC == (Base, (Object, 
    94   BaseC_def:"BaseC == (Base, (Object, 
   100 			     [(vee, PrimT Boolean)], 
    95            [(vee, PrimT Boolean)], 
   101 			     [((foo,[Class Base]),Class Base,foo_Base)]))"
    96            [((foo,[Class Base]),Class Base,foo_Base)]))"
   102   foo_Ext_def:"foo_Ext == ([x],[],Expr( {Ext}Cast Ext
    97   foo_Ext_def:"foo_Ext == ([x],[],Expr( {Ext}Cast Ext
   103 				       (LAcc x)..vee:=Lit (Intg 1)),
    98                (LAcc x)..vee:=Lit (Intg Numeral1)),
   104 				   Lit Null)"
    99            Lit Null)"
   105   ExtC_def: "ExtC  == (Ext,  (Base  , 
   100   ExtC_def: "ExtC  == (Ext,  (Base  , 
   106 			     [(vee, PrimT Integer)], 
   101            [(vee, PrimT Integer)], 
   107 			     [((foo,[Class Base]),Class Ext,foo_Ext)]))"
   102            [((foo,[Class Base]),Class Ext,foo_Ext)]))"
   108 
   103 
   109   test_def:"test == Expr(e::=NewC Ext);; 
   104   test_def:"test == Expr(e::=NewC Ext);; 
   110                     Expr({Base}LAcc e..foo({[Class Base]}[Lit Null]))"
   105                     Expr({Base}LAcc e..foo({[Class Base]}[Lit Null]))"
   111 
   106 
   112 
   107 
   113 syntax
   108 syntax
   114 
   109 
   115   NP	:: xcpt
   110   NP  :: xcpt
   116   tprg 	::"java_mb prog"
   111   tprg  ::"java_mb prog"
   117   obj1	:: obj
   112   obj1  :: obj
   118   obj2	:: obj
   113   obj2  :: obj
   119   s0 	:: state
   114   s0  :: state
   120   s1 	:: state
   115   s1  :: state
   121   s2 	:: state
   116   s2  :: state
   122   s3 	:: state
   117   s3  :: state
   123   s4 	:: state
   118   s4  :: state
   124 
   119 
   125 translations
   120 translations
   126 
       
   127   "NP"   == "NullPointer"
   121   "NP"   == "NullPointer"
   128   "tprg" == "[ObjectC, BaseC, ExtC]"
   122   "tprg" == "[ObjectC, BaseC, ExtC]"
   129   "obj1"    <= "(Ext, empty((vee, Base)\<mapsto>Bool False)
   123   "obj1"    <= "(Ext, empty((vee, Base)\<mapsto>Bool False)
   130 			   ((vee, Ext )\<mapsto>Intg 0))"
   124          ((vee, Ext )\<mapsto>Intg 0))"
   131   "s0" == " Norm    (empty, empty)"
   125   "s0" == " Norm    (empty, empty)"
   132   "s1" == " Norm    (empty(a\<mapsto>obj1),empty(e\<mapsto>Addr a))"
   126   "s1" == " Norm    (empty(a\<mapsto>obj1),empty(e\<mapsto>Addr a))"
   133   "s2" == " Norm    (empty(a\<mapsto>obj1),empty(x\<mapsto>Null)(This\<mapsto>Addr a))"
   127   "s2" == " Norm    (empty(a\<mapsto>obj1),empty(x\<mapsto>Null)(This\<mapsto>Addr a))"
   134   "s3" == "(Some NP, empty(a\<mapsto>obj1),empty(e\<mapsto>Addr a))"
   128   "s3" == "(Some NP, empty(a\<mapsto>obj1),empty(e\<mapsto>Addr a))"
   135 
   129 
   139 apply (simp (no_asm))
   133 apply (simp (no_asm))
   140 done
   134 done
   141 lemma map_of_Cons2 [simp]: "aa\<noteq>k ==> map_of ((k,bb)#ps) aa = map_of ps aa"
   135 lemma map_of_Cons2 [simp]: "aa\<noteq>k ==> map_of ((k,bb)#ps) aa = map_of ps aa"
   142 apply (simp (no_asm_simp))
   136 apply (simp (no_asm_simp))
   143 done
   137 done
   144 declare map_of_Cons [simp del]; (* sic! *)
   138 declare map_of_Cons [simp del] -- "sic!"
   145 
   139 
   146 lemma class_tprg_Object [simp]: "class tprg Object = Some (arbitrary, [], [])"
   140 lemma class_tprg_Object [simp]: "class tprg Object = Some (arbitrary, [], [])"
   147 apply (unfold ObjectC_def class_def)
   141 apply (unfold ObjectC_def class_def)
   148 apply (simp (no_asm))
   142 apply (simp (no_asm))
   149 done
   143 done
   150 
   144 
   151 lemma class_tprg_Base [simp]: 
   145 lemma class_tprg_Base [simp]: 
   152 "class tprg Base = Some (Object,  
   146 "class tprg Base = Some (Object,  
   153 	  [(vee, PrimT Boolean)],  
   147     [(vee, PrimT Boolean)],  
   154           [((foo, [Class Base]), Class Base, foo_Base)])"
   148           [((foo, [Class Base]), Class Base, foo_Base)])"
   155 apply (unfold ObjectC_def BaseC_def ExtC_def class_def)
   149 apply (unfold ObjectC_def BaseC_def ExtC_def class_def)
   156 apply (simp (no_asm))
   150 apply (simp (no_asm))
   157 done
   151 done
   158 
   152 
   159 lemma class_tprg_Ext [simp]: 
   153 lemma class_tprg_Ext [simp]: 
   160 "class tprg Ext = Some (Base,  
   154 "class tprg Ext = Some (Base,  
   161 	  [(vee, PrimT Integer)],  
   155     [(vee, PrimT Integer)],  
   162           [((foo, [Class Base]), Class Ext, foo_Ext)])"
   156           [((foo, [Class Base]), Class Ext, foo_Ext)])"
   163 apply (unfold ObjectC_def BaseC_def ExtC_def class_def)
   157 apply (unfold ObjectC_def BaseC_def ExtC_def class_def)
   164 apply (simp (no_asm))
   158 apply (simp (no_asm))
   165 done
   159 done
   166 
   160 
   326 done
   320 done
   327 
   321 
   328 ML {* fun t thm = resolve_tac (thms "ty_expr_ty_exprs_wt_stmt.intros") 1 thm *}
   322 ML {* fun t thm = resolve_tac (thms "ty_expr_ty_exprs_wt_stmt.intros") 1 thm *}
   329 lemma wt_test: "(tprg, empty(e\<mapsto>Class Base))\<turnstile>  
   323 lemma wt_test: "(tprg, empty(e\<mapsto>Class Base))\<turnstile>  
   330   Expr(e::=NewC Ext);; Expr({Base}LAcc e..foo({?pTs'}[Lit Null]))\<surd>"
   324   Expr(e::=NewC Ext);; Expr({Base}LAcc e..foo({?pTs'}[Lit Null]))\<surd>"
   331 apply (tactic t) (* ;; *)
   325 apply (tactic t) -- ";;"
   332 apply  (tactic t) (* Expr *)
   326 apply  (tactic t) -- "Expr"
   333 apply  (tactic t) (* LAss *)
   327 apply  (tactic t) -- "LAss"
   334 apply    simp (* e \<noteq> This *)
   328 apply    simp -- {* @{text "e \<noteq> This"} *}
   335 apply    (tactic t) (* LAcc *)
   329 apply    (tactic t) -- "LAcc"
   336 apply     (simp (no_asm))
   330 apply     (simp (no_asm))
   337 apply    (simp (no_asm))
   331 apply    (simp (no_asm))
   338 apply   (tactic t) (* NewC *)
   332 apply   (tactic t) -- "NewC"
   339 apply   (simp (no_asm))
   333 apply   (simp (no_asm))
   340 apply  (simp (no_asm))
   334 apply  (simp (no_asm))
   341 apply (tactic t) (* Expr *)
   335 apply (tactic t) -- "Expr"
   342 apply (tactic t) (* Call *)
   336 apply (tactic t) -- "Call"
   343 apply   (tactic t) (* LAcc *)
   337 apply   (tactic t) -- "LAcc"
   344 apply    (simp (no_asm))
   338 apply    (simp (no_asm))
   345 apply   (simp (no_asm))
   339 apply   (simp (no_asm))
   346 apply  (tactic t) (* Cons *)
   340 apply  (tactic t) -- "Cons"
   347 apply   (tactic t) (* Lit *)
   341 apply   (tactic t) -- "Lit"
   348 apply   (simp (no_asm))
   342 apply   (simp (no_asm))
   349 apply  (tactic t) (* Nil *)
   343 apply  (tactic t) -- "Nil"
   350 apply (simp (no_asm))
   344 apply (simp (no_asm))
   351 apply (rule max_spec_foo_Base)
   345 apply (rule max_spec_foo_Base)
   352 done
   346 done
   353 
   347 
   354 ML {* fun e t = resolve_tac (thm "NewCI"::thms "eval_evals_exec.intros") 1 t *}
   348 ML {* fun e t = resolve_tac (thm "NewCI"::thms "eval_evals_exec.intros") 1 t *}
   357 declare init_vars_def [simp] c_hupd_def [simp] cast_ok_def [simp]
   351 declare init_vars_def [simp] c_hupd_def [simp] cast_ok_def [simp]
   358 lemma exec_test: 
   352 lemma exec_test: 
   359 " [|new_Addr (heap (snd s0)) = (a, None)|] ==>  
   353 " [|new_Addr (heap (snd s0)) = (a, None)|] ==>  
   360   tprg\<turnstile>s0 -test-> ?s"
   354   tprg\<turnstile>s0 -test-> ?s"
   361 apply (unfold test_def)
   355 apply (unfold test_def)
   362 (* ?s = s3 *)
   356 -- "?s = s3 "
   363 apply (tactic e) (* ;; *)
   357 apply (tactic e) -- ";;"
   364 apply  (tactic e) (* Expr *)
   358 apply  (tactic e) -- "Expr"
   365 apply  (tactic e) (* LAss *)
   359 apply  (tactic e) -- "LAss"
   366 apply   (tactic e) (* NewC *)
   360 apply   (tactic e) -- "NewC"
   367 apply    force
   361 apply    force
   368 apply   force
   362 apply   force
   369 apply  (simp (no_asm))
   363 apply  (simp (no_asm))
   370 apply (erule thin_rl)
   364 apply (erule thin_rl)
   371 apply (tactic e) (* Expr *)
   365 apply (tactic e) -- "Expr"
   372 apply (tactic e) (* Call *)
   366 apply (tactic e) -- "Call"
   373 apply       (tactic e) (* LAcc *)
   367 apply       (tactic e) -- "LAcc"
   374 apply      force
   368 apply      force
   375 apply     (tactic e) (* Cons *)
   369 apply     (tactic e) -- "Cons"
   376 apply      (tactic e) (* Lit *)
   370 apply      (tactic e) -- "Lit"
   377 apply     (tactic e) (* Nil *)
   371 apply     (tactic e) -- "Nil"
   378 apply    (simp (no_asm))
   372 apply    (simp (no_asm))
   379 apply   (force simp add: foo_Ext_def)
   373 apply   (force simp add: foo_Ext_def)
   380 apply  (simp (no_asm))
   374 apply  (simp (no_asm))
   381 apply  (tactic e) (* Expr *)
   375 apply  (tactic e) -- "Expr"
   382 apply  (tactic e) (* FAss *)
   376 apply  (tactic e) -- "FAss"
   383 apply       (tactic e) (* Cast *)
   377 apply       (tactic e) -- "Cast"
   384 apply        (tactic e) (* LAcc *)
   378 apply        (tactic e) -- "LAcc"
   385 apply       (simp (no_asm))
   379 apply       (simp (no_asm))
   386 apply      (simp (no_asm))
   380 apply      (simp (no_asm))
   387 apply     (simp (no_asm))
   381 apply     (simp (no_asm))
   388 apply     (tactic e) (* XcptE *)
   382 apply     (tactic e) -- "XcptE"
   389 apply    (simp (no_asm))
   383 apply    (simp (no_asm))
   390 apply   (rule surjective_pairing [THEN sym, THEN[2]trans], subst Pair_eq, force)
   384 apply   (rule surjective_pairing [THEN sym, THEN[2]trans], subst Pair_eq, force)
   391 apply  (simp (no_asm))
   385 apply  (simp (no_asm))
   392 apply (simp (no_asm))
   386 apply (simp (no_asm))
   393 apply (tactic e) (* XcptE *)
   387 apply (tactic e) -- "XcptE"
   394 done
   388 done
   395 
   389 
   396 end
   390 end