-
Notifications
You must be signed in to change notification settings - Fork 0
/
operational.ml
executable file
·1630 lines (1446 loc) · 64.9 KB
/
operational.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(***********************************************************************)
(* Event Spaces *)
(* *)
(* Néstor CATAÑO, Lemme project *)
(* INRIA Sophia Antipolis *)
(* 2004 route des Lucioles-B.P. 93 *)
(* 06902 Sophia Antipolis Cedex (France) *)
(* *)
(***********************************************************************)
open Javasyntax
open Display
module type OPERATIONAL =
sig
type config
type mterm
type objset
type disp
exception Not_Applicable of string * string
exception Rewrite of string * string
exception Event_Space_Error of string * string
exception Initialization_Error
val isPopOutContext: Store.t -> aterm -> bool
val disp_objectset: string -> objset -> displevel -> string
val disp_mterm: string -> mterm -> displevel -> string
val disp_config: string -> config -> displevel -> string
val rew_store: (mterm * config) -> (mterm * config)
val rew_write: (mterm * config) -> (mterm * config)
val rew_read: (mterm * config) -> (mterm * config)
val rew_load: (mterm * config) -> (mterm * config)
val rew_one_step: (mterm * config) -> (mterm * config)
val rew_n_steps: (mterm * config * out_channel) -> (mterm * config * out_channel)
val run: compilunit -> compilunit list -> string -> displevel -> (mterm * config)
end
module Make: OPERATIONAL =
struct
module Evtspace = Event_space.Make;;
module Mterm = Set.Make(struct type t = thread * aterm * staterecord * Stack_of_env.t
let compare = function (th1,_,_,_) -> function (th2,_,_,_) ->
match th1,th2 with
|(Nullobj,Nullobj) -> 0
|(Nonnull(o1),Nonnull(o2)) -> compare o1 o2
|(Nonnull(o1),Nullobj) -> 1
|(Nullobj,Nonnull(o2)) -> -1
end
);;
type mterm = Mterm.t
module Objset = Set.Make(struct type t = obj let compare=compare end);;
type objset = Objset.t
type config = (Mterm.elt * Objset.t * Evtspace.t * Store.t)
type disp = {mutable prf: string; mutable res: string}
exception Not_Applicable of string * string
exception Rewrite of string * string
exception Event_Space_Error of string * string
exception Initialization_Error
(********************* Auxiliary functions **************************)
(** establishes whether 'str' is a pop out context **)
let isPopOutContext str = function
| StatT(ReturnStmt(None)) -> true
| ExprT(StmtExp(Ass(Field(StmtExp(ValS(Oref(Nonnull(_)))),_),e)))
| ExprT(StmtExp(Ass(Field(e,_),_)))
| ExprT(StmtExp(Ass(Var(_),e)))
| ExprT(InstOf(e,_))
| ExprT(UnOp(_,e))
| ExprT(BinOp(StmtExp(ValS(_)),_,e))
| ExprT(BinOp(e,_,_))
| ExprT(Acc(Field(e,_)))
| ExprT(StmtExp(MCall(e,_,_)))
| StatT(VarDeclStmtE(_,_,e))
| StatT(IfStmt(e,_))
| StatT(ReturnStmt(Some e))
| StatT(ThrowStmt(e))
| StatT(SyncStmt(e,_)) ->
begin match e with
| StmtExp(ReturnSE(_))
| StmtExp(ThrowSE(_)) -> true
| _ -> false
end
| StatT(BlockStmt(BlockIt(s::_,_)))
| StatT(TryFinStmt(BlockIt([],_),_,BlockIt(s::_,_)))
| StatT(TryFinStmt(BlockIt((ExpStmt(ThrowSE(_)))::_,_),[],BlockIt(s::_,_)))
| StatT(TryFinStmt(BlockIt((ExpStmt(ReturnSE(_)))::_,_),_,BlockIt(s::_,_))) ->
begin match s with
| ExpStmt(ReturnSE(_))
| ExpStmt(ThrowSE(_)) -> true
| _ -> false
end
| StatT(TryFinStmt(BlockIt((ExpStmt(ThrowSE(Throw(Nonnull(p)))))::_,_),
(CC(ClType(ct),_,BlockIt(s::_,_)))::_,BlockIt([],_)))
| StatT(TryFinStmt(BlockIt((ExpStmt(ThrowSE(Throw(Nonnull(p)))))::_,_),
(CC(ClType(ct),_,BlockIt((ExpStmt(ThrowSE(_)))::_,_)))::_,BlockIt(s::_,_)))
| StatT(TryFinStmt(BlockIt((ExpStmt(ThrowSE(Throw(Nonnull(p)))))::_,_),
(CC(ClType(ct),_,BlockIt((ExpStmt(ReturnSE(_)))::_,_)))::_,BlockIt(s::_,_))) ->
begin match s with
| ExpStmt(ReturnSE(_))
| ExpStmt(ThrowSE(_)) -> if Store.belongs str (Nonnull(p)) ct then true else false
| _ -> false
end
| StatT(s) ->
begin match s with
| ExpStmt(ReturnSE(_))
| ExpStmt(ThrowSE(_)) -> true
| _ -> false
end
| _ -> false
(** to display the objectset 'objs' **)
let disp_objectset pfix objs swt =
let r = {prf=pfix; res="\n"} in
let () = r.res <- r.res ^ r.prf
and () = r.res <- r.res ^"|--"
and () = r.prf <- r.prf ^"| "
and () = r.res <- r.res ^"OBJECT_SET" in
let () =
( Objset.fold
(function o -> function a ->
let () = r.res <- r.res ^(disp_obj r.prf o swt) in
()
)
objs
()
) in r.res
(** to display the mterm 'mt' **)
let disp_mterm pfix mt swt =
let r = {prf=pfix; res="\n"} in
let () = r.res <- r.res ^ r.prf
and () = r.res <- r.res ^"|--"
and () = r.prf <- r.prf ^"| "
and () = r.res <- r.res ^"MTERM" in
let () =
( Mterm.fold
(function mm -> function a ->
match mm with
| (th,at,sr,soe) ->
let () = r.res <- r.res ^ r.prf
and () = r.res <- r.res ^"|--"
and () = r.prf <- r.prf ^"| "
and () = r.res <- r.res ^(disp_thread r.prf th swt)
and () = r.res <- r.res ^(disp_aterm r.prf at swt)
and () = r.res <- r.res ^(disp_staterecord r.prf sr swt)
and () = r.res <- r.res ^(Stack_of_env.display soe r.prf swt) in
()
)
mt
()
) in r.res
(** to display the configuration 'cnf' **)
let disp_config pfix cnf swt =
let r = {prf=pfix; res="\n"} in
match cnf with
| ((th,at,sr,soe),objs,evs,str) ->
let () = r.res <- r.res ^ r.prf
and () = r.res <- r.res ^"|--"
and () = r.prf <- r.prf ^"| "
and () = r.res <- r.res ^"CONFIGURATION"
and () = r.res <- r.res ^(disp_thread r.prf th Plenty)
and () = r.res <- r.res ^(disp_aterm r.prf at Plenty)
and () = r.res <- r.res ^(disp_staterecord r.prf sr Plenty)
and () = r.res <- r.res ^(Stack_of_env.display soe r.prf Plenty)
and () = r.res <- r.res ^(disp_objectset r.prf objs Plenty)
and () = r.res <- r.res ^(Evtspace.display evs r.prf swt)
and () = r.res <- r.res ^(Store.display str r.prf swt)
in r.res
(*****************************************************************)
(*-* pick up a configuration from a set of 'mterm *-*)
let pickup_conf (mt,cnf) =
match cnf with
| ((_,_,z,_),objset,evsp,str) ->
if z=D then
begin try
let mt2 = (Mterm.filter (function (_,_,z,_) -> z<>D) mt) in
(Mterm.choose mt2,objset,evsp,str)
with
Not_found -> cnf
end
else cnf
(*****************************************************************)
(* store *)
let rew_store = function
| (mt,((th,e,R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *store*\n" in**)
begin match Evtspace.getLastAssign evsp th with
| Some (Assign(_,l,v)) ->
begin match Evtspace.plusE evsp (Store(th,l,v)) with
| Some evs -> (mt, ((th,e,R,stck),objs,evs,str))
| None -> raise (Event_Space_Error("<rew_store,Event_space.plusE>",(disp_event ":" (Store(th,l,v)) Plenty )))
end
| _ -> raise (Event_Space_Error("<rew_store,Event_space.getLastAssign>",""))
end
| _ -> raise (Event_Space_Error("<rew_store,Event_space.getLastAssign>",""))
(* write *)
let rew_write = function
| (mt,((th,e,R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *write*\n" in **)
begin match Evtspace.getLastStore evsp th with
| Some (Store(_,l,v)) ->
begin match Evtspace.plusE evsp (Write(th,l,v)) with
| Some evs -> (mt, ((th,e,R,stck),objs,evs,(Store.update str l v)))
| None -> raise (Event_Space_Error("<rew_write,Event_Space.plusE>",(disp_event ":" (Write(th,l,v)) Plenty)))
end
| _ -> raise (Event_Space_Error("<rew_write,Event_Space.getLastStore>",""))
end
| _ -> raise (Event_Space_Error("<rew_write,Event_Space.getLastStore>",""))
(* read *)
let rew_read = function
| (mt,((th,e,R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *read*\n" in**)
let evsp3 =
( List.fold_left
( function evsp1 -> function
| Write(t,l,v) ->
begin match Evtspace.plusE evsp1 (Read(th,l,v)) with
| Some evsp2 -> evsp2
| None -> evsp1
end
| _ -> evsp1
)
evsp
(Evtspace.getLastWriteList evsp)
) in (mt, ((th,e,R,stck),objs,evsp3,str))
| _ -> raise (Event_Space_Error("<rew_read>",""))
(* load *)
let rew_load = function
| (mt,((th,e,R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *load*\n" in**)
let evsp3 =
( List.fold_left
( function evsp1 -> function
| Read(t,l,v) ->
begin match Evtspace.plusE evsp1 (Load(th,l,v)) with
| Some evsp2 -> evsp2
| None -> evsp1
end
| _ -> evsp1
)
evsp
(Evtspace.getLastReadList evsp)
) in (mt, ((th,e,R,stck),objs,evsp3,str))
| _ -> raise (Event_Space_Error("<rew_load>",""))
(** one rewriting step. **)
let rec rew_one_step = function
(* assign4 *)
| (mt,((th,ExprT(StmtExp(Ass(Var(i),StmtExp(ValS(v))))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *assign4*\n" in**)
begin match (Stack_of_env.assign stck (Ident(i)) v) with
| Some s -> (*-* The store should be also modified, otherwise the
the next time a method is reached, it will use
non updated values.
*-*)
begin match (Stack_of_env.lookTop stck ThisExp) with
| Some Oref(Nonnull(o)) ->
let elterm = (th,ExprT(StmtExp(ValS(v))),R,s) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,(Store.update str (Lval(o,FId(i,ClType("")))) v)))
| _ -> raise (Rewrite("<rew_one_step,assign4,Stack_of_env.lookTop>",
(Stack_of_env.display stck "s:" Plenty)
^(disp_identifier "i:" i Plenty)))
end
| None -> raise (Rewrite("<rew_one_step,assign4,Stack_of_env.assign>",
(Stack_of_env.display stck "s:" Plenty)
^(disp_identifier "i:" i Plenty)
^(disp_rval "v:" v Plenty)))
end
(* assign2 *)
| (mt1,((th,ExprT(StmtExp(Ass(Var(i),e1))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *assign2*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(StmtExp(Ass(Var(i),e2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,assign2>",(disp_aterm ":" ee Plenty)))
end
(* assign3 *) (* assign1 *) (* assign5 *)
| (mt1,((th,ExprT(StmtExp(Ass(le,e))),R,stck1),objs1,evsp1,str1)) ->
begin match lhsLval le with
| Some l -> (** assign5 **) (** assign3 **)
begin match e with
| StmtExp(ValS(v)) -> (** assign5 **)
(**let () = Printf.printf "Rule *assign5*\n" in**)
begin match Evtspace.plusE evsp1 (Assign(th,l,v)) with
| Some evs ->
let elterm = (th,ExprT(e),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evs,str1))
| None -> raise (Rewrite("<rew_one_step,assign5,Event_space.plusE>",(disp_event ":" (Assign(th,l,v)) Plenty)))
end
| _ -> (** assign3 **)
(**let () = Printf.printf "Rule *assign3*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(StmtExp(Ass(le,e2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,assign3>",(disp_aterm ":" ee Plenty)))
end
end
| None -> (** assign1 **)
(**let () = Printf.printf "Rule *assign1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(Acc(le)),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprT(Acc(e2)) ->
let elterm = (th,ExprT(StmtExp(Ass(e2,e))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,assign1>",(disp_aterm ":" ee Plenty)))
end
end
(* var *)
| (mt,((th,ExprT(Acc(Var(i))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *var*\n" in**)
begin
match Stack_of_env.lookup stck (Ident(i)) with
| Some v ->
let elterm = (th,ExprT(StmtExp(ValS(v))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
| None -> raise (Rewrite( "<rew_one_step,var,Stack_of_env.lookup>",
(disp_identthis "i" (Ident(i)) Plenty)
^(Stack_of_env.display stck "s" Plenty)))
end
(* access2 *)
| (mt1,((th,ExprT(Acc(Field(StmtExp(ValS(Oref(Nullobj))),f))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *access2*\n" in**)
let (p,str2,bcknew) = Store.new_inst str1 "NullPointerException" [] in
let elterm = (th,StatSeqT([ExpStmt(ThrowSE(Throw(Nonnull(p)))); BlockStmt(bcknew)]),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str2))
(* access3 *) (* access1 *)
| (mt1,((th,ExprT(Acc(Field(e1,f)as le)),R,stck1),objs1,evsp1,str1)) ->
if isLval le then (** access3 **)
(**let () = Printf.printf "Rule *access3*\n" in**)
begin match lhsLval le with
| Some l ->
begin match Store.getRval str1 l with
| Some v ->
begin match Evtspace.plusE evsp1 (Use(th,l,v)) with
| Some evs ->
let elterm = (th,ExprT(StmtExp(ValS(v))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evs,str1))
| None -> raise (Rewrite("<rew_one_step,access3,Event_space.plusE>",(disp_event ":" (Use(th,l,v)) Plenty)))
end
| None -> raise (Rewrite("<rew_one_step,access3,Store.getRval>",
(*Store.display str1 "s:"*)
(disp_lval "l:" l Plenty)))
end
| None -> raise (Not_Applicable("<rew_one_step,access3>",(disp_lefthandside ":" le Plenty)))
end
else (** access1 **)
(**let () = Printf.printf "Rule *access1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(Acc(Field(e2,f))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,access1>",(disp_aterm ":" ee Plenty)))
end
(* this *)
| (mt,((th,ExprT(This),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *this*\n" in**)
begin match Stack_of_env.lookup stck (ThisExp) with
| Some v ->
let elterm = (th,ExprT(StmtExp(ValS(v))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
| None -> raise (Rewrite( "<rew_one_step,this,Stack_of_env.lookup>",
(Stack_of_env.display stck ":" Plenty)
^"\n---------------------------"
^(disp_identthis ":" (ThisExp) Plenty)))
end
(* newc2 *) (* newc1 *)
| (mt1,((th,ExprT(StmtExp(NewC(c,eE))),R,stck1),objs1,evsp1,str1)) ->
begin match expRvalList eE with
| Some vl -> (** newc2 **)
(**let () = Printf.printf "Rule *newc2*\n" in**)
begin try
let (p,str2,bcknew) = Store.new_inst str1 c vl in (** it modifies 'str1' **)
let elterm = (th,StatSeqT([ExpStmt(ValS(Oref(Nonnull(p)))); BlockStmt(bcknew)]),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str2))
with
Store.Class_Not_Found(_,_) -> raise (Rewrite("<rew_one_step,newc2,Store.new_inst>",
disp_aterm ":" (ExprT(StmtExp(NewC(c,eE)))) Plenty))
end
| None -> (** newc1 **)
(**let () = Printf.printf "Rule *newc1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprSeqT(eE),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprSeqT(eE2) ->
let elterm = (th,ExprT(StmtExp(NewC(c,eE2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,newc1>",(disp_aterm ":" ee Plenty)))
end
end
(* lit *)
| (mt,((th,ExprT(Lit(k)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *lit*\n" in**)
let elterm = (th,ExprT(StmtExp(ValS(Store.value k))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* instof2 *) (* instof3 *)
| (mt,((th,ExprT(InstOf(StmtExp(ValS(Oref(Nonnull(p)))),c)),R,stck),objs,evsp,str)) ->
if Store.belongs str (Nonnull(p)) c then (** instof2 **)
(**let () = Printf.printf "Rule *instof2*\n" in**)
let elterm = (th,ExprT(Lit(BoolLit(true))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
else (** instof3 **)
(**let () = Printf.printf "Rule *instof3*\n" in**)
let elterm = (th,ExprT(Lit(BoolLit(false))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* instof1 *)
| (mt1,((th,ExprT(InstOf(e1,c)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *instof1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(InstOf(e2,c)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,instof1>",(disp_aterm ":" ee Plenty)))
end
(* unop2 *)
| (mt1,((th,ExprT(UnOp(f,StmtExp(ValS(v)))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *unop2*\n" in**)
let elterm = (th,ExprT(StmtExp(ValS(f v))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
(* unop1 *)
| (mt1,((th,ExprT(UnOp(f,e1)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *unop1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(UnOp(f,e2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,unop1>",(disp_aterm ":" ee Plenty)))
end
(* binop3 *)
| (mt1,((th,ExprT(BinOp(StmtExp(ValS(v1)),f,StmtExp(ValS(v2)))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *binop3*\n" in**)
let elterm = (th,ExprT(StmtExp(ValS(f v1 v2))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
(* binop2 *)
| (mt1,((th,ExprT(BinOp(StmtExp(ValS(v1)),f,e)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *binop2*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(BinOp(StmtExp(ValS(v1)),f,e2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,binop2>",(disp_aterm ":" ee Plenty)))
end
(* binop1 *)
| (mt1,((th,ExprT(BinOp(e1,f,e)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *binop1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(BinOp(e2,f,e)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,binop1>",(disp_aterm ":" ee Plenty)))
end
(* parseq2 *)
| (mt1,((th,ExprSeqT((StmtExp(ValS(v)))::eE1),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *parseq2*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprSeqT(eE1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprSeqT(eE2) ->
let elterm = (th,ExprSeqT((StmtExp(ValS(v)))::eE2),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,parseq2>",(disp_aterm ":" ee Plenty)))
end
(* parseq1 *)
| (mt1,((th,ExprSeqT(e1::eE1),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *parseq1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprSeqT(e2::eE1),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,parseq1>",(disp_aterm ":" ee Plenty)))
end
(* call4 *)
| (mt,((th,ExprT(StmtExp(MCall(StmtExp(ValS(Oref(Nullobj))),m,_))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *call4*\n" in**)
let (p,str2,bcknew) = Store.new_inst str "NullPointerException" [] in
let elterm = (th,StatSeqT([ExpStmt(ThrowSE(Throw(Nonnull(p)))); BlockStmt(bcknew)]),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str2))
(* call3 *) (* call2 *)
| (mt1,((th,ExprT(StmtExp(MCall(StmtExp(ValS(Oref(p))),m,eE))),R,stck1),objs1,evsp1,str1)) ->
begin match expRvalList eE with
| Some vl -> (** call3 **)
(**let () = Printf.printf "Rule *call3*\n" in**)
begin match Store.frame str1 p m vl with
| Some f ->
let elterm = (th,ExprT(StmtExp(AFrame(fst f,snd f))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
| None -> let msg = (Store.display str1 "s:" Plenty)
^ (disp_obj "o:" p Plenty)
^ (disp_mcallid "m:" m Plenty)
^ (disp_rval_list "rv:" vl Plenty)
in raise (Rewrite("<rew_one_step,call3,Store.frame>", msg))
end
| None -> (** call2 **)
(**let () = Printf.printf "Rule *call2*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprSeqT(eE),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprSeqT(eE2) ->
let elterm = (th,ExprT(StmtExp(MCall(StmtExp(ValS(Oref(p))),m,eE2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,call2>",(disp_aterm ":" ee Plenty)))
end
end
(* call1 *)
| (mt1,((th,ExprT(StmtExp(MCall(e1,m,eE))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *call1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,ExprT(StmtExp(MCall(e2,m,eE))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,call1>",(disp_aterm ":" ee Plenty)))
end
(*****************************************************************)
(********************** ACTIVATION FRAMES ************************)
(*****************************************************************)
(* exit1 *)
| (mt,((th,StatT(ExpStmt(AFrame(m,BlockIt([],_)))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *exit1*\n" in**)
let elterm = (th,StatT(Nop),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* exit2 *)
| (mt,((th,StatT(ExpStmt(AFrame(m,BlockIt((ExpStmt(ReturnSE(None)))::sS,_)))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *exit2*\n" in**)
let elterm = (th,StatT(Nop),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* exit3 *)
| (mt,((th,ExprT(StmtExp(AFrame(m,BlockIt((ExpStmt(ReturnSE(Some v)))::sS,_)))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *exit3*\n" in**)
let elterm = (th,ExprT(StmtExp(ValS(v))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* frame *)
| (mt1,((th,ExprT(StmtExp(AFrame(m,b1))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *frame*\n" in**)
let (mt2,((_,bb,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,StatT(BlockStmt(b1)),R,stck1),objs1,evsp1,str1)) in
begin match bb with
| StatT(BlockStmt(b2)) ->
let elterm = (th,ExprT(StmtExp(AFrame(m,b2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,frame>",(disp_aterm ":" bb Plenty)))
end
(*****************************************************************)
(******************* LOCAL VARIABLE DECLARATIONS *****************)
(*****************************************************************)
(* decl *)
| (mt,((th,StatT(VarDeclStmtN(t,i)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *decl*\n" in**)
begin match Stack_of_env.bind stck (Ident(i)) (Store.init_val t) with
| Some s ->
let elterm = (th,StatT(Nop),R,s) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
| None -> raise (Rewrite( "<rew_one_step,decl,Stack_of_env.bind>",""))
end
(* decle2 *)
| (mt,((th,StatT(VarDeclStmtE(t,i,StmtExp(ValS(v)))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *decle2*\n" in**)
begin match Stack_of_env.bind stck (Ident(i)) v with
| Some s ->
let elterm = (th,StatT(Nop),R,s) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
| None -> raise (Rewrite("<rew_one_step,decle2,Stack_of_env.bind>",""))
end
(* decle1 *)
| (mt1,((th,StatT(VarDeclStmtE(t,i,e1)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *decle1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin match ee with
| ExprT(e2) ->
let elterm = (th,StatT(VarDeclStmtE(t,i,e2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
(** <because of the definition of new_inst> **)
| StatSeqT(ExpStmt(ValS(v))::sS) ->
(**let () = Printf.printf "Rule *because of the new definition of new_inst*\n" in**)
let elterm = (th,StatSeqT((VarDeclStmtE(t,i,StmtExp(ValS(v))))::sS),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,decle1>",
(disp_expr ":" e1 Plenty)
^"\n---------------------------"
^(disp_aterm ":" ee Plenty)))
end
(*****************************************************************)
(***** EXPRESSION STATEMENT, SKIP, CONDITIONAL AND ITERATION *****)
(*****************************************************************)
(* skip *)
| (mt1,((th,StatT(SemiCol),R,stck1),objs1,evsp1,str1)) -> (** skip **)
(**let () = Printf.printf "Rule *skip*\n" in**)
let elterm = (th,StatT(Nop),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
(* expstat2 *)
| (mt1,((th,StatT(ExpStmt(ValS(v))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *expstat2*\n" in**)
let elterm = (th,StatT(Nop),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
(* if2 *)
| (mt,((th,StatT(IfStmt(StmtExp(ValS(Bval(true))),s)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *if2*\n" in**)
let elterm = (th,StatT(s),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* if3 *)
| (mt,((th,StatT(IfStmt(StmtExp(ValS(Bval(false))),s)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *if3*\n" in**)
let elterm = (th,StatT(Nop),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* if1 *)
| (mt1,((th,StatT(IfStmt(e1,s)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *if1*\n" in**)
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(e2) ->
let elterm = (th,StatT(IfStmt(e2,s)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,if1>",(disp_aterm ":" ee Plenty)))
end
(* while *)
| (mt,((th,StatT(WhileStmt(e,s)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *while*\n" in**)
let elterm = (th,StatT(IfStmt(e,BlockStmt(BlockIt([s;WhileStmt(e,s)],Stack_of_env.createEnv())))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(*****************************************************************)
(******************* BLOCKS AND SYNCHRONIZATION ******************)
(*****************************************************************)
(* nop *)
| (mt,((th,StatSeqT((Nop)::sS),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *nop*\n" in**)
let elterm = (th,StatSeqT(sS),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* statseq *)
| (mt1,((th,StatSeqT(s1::sS),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *statseq*\n" in**)
let (mt2,((_,ss,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,StatT(s1),R,stck1),objs1,evsp1,str1)) in
begin
match ss with
| StatT(s2) ->
let elterm = (th,StatSeqT(s2::sS),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
(** <because of the definition of new_inst> **)
| StatSeqT(s2) ->
(**let () = Printf.printf "Rule *because of the definition of new_inst*\n" in**)
let elterm = (th,StatSeqT(s2@sS),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,statseq>",(disp_aterm ":" ss Plenty)))
end
(* block1 *)
| (mt,((th,StatT(BlockStmt(BlockIt([],env))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *block1*\n" in**)
let elterm = (th,StatT(Nop),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* syn4 *) (* syn3 *)
| (mt1,((th,StatT(SyncStmt(StmtExp(ValS(Oref(o))),b1)),R,stck1),objs1,evsp1,str1)) ->
let (mt2,((_,bb,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,StatT(BlockStmt(b1)),R,stck1),objs1,evsp1,str1)) in
begin
match bb with
| StatT(Nop) |
ExprT(StmtExp(ValS(_))) |
StatT(ExpStmt(ValS(_))) |
ExprT(StmtExp(ThrowSE(Throw(_)))) |
StatT(ExpStmt(ThrowSE(Throw(_)))) |
ExprT(StmtExp(ReturnSE(_))) |
StatT(ExpStmt(ReturnSE(_))) -> (** syn4 **)
(**let () = Printf.printf "Rule *syn4*\n" in**)
begin match Evtspace.plusE evsp2 (Unlock(th,o)) with
| Some evs ->
let elterm = (th,bb,z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evs,str2))
| None -> raise (Rewrite("<rew_one_step,syn4,Event_space.plusE>",(disp_event ":" (Unlock(th,o)) Plenty)))
end
| StatT(BlockStmt(b2)) -> (** syn3 **)
(**let () = Printf.printf "Rule *syn3*\n" in**)
let elterm = (th,StatT(SyncStmt(StmtExp(ValS(Oref(o))),b2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,syn4,syn3>",(disp_aterm ":" bb Plenty)))
end
(* syn2 *) (* syn1 *)
| (mt1,((th,StatT(SyncStmt(e1,b)),R,stck1),objs1,evsp1,str1)) ->
let (mt2,((_,ee,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ee with
| ExprT(StmtExp(ValS(Oref(o)))) -> (** syn2 **)
(**let () = Printf.printf "Rule *syn2*\n" in**)
begin match Evtspace.plusE evsp2 (Lock(th,o)) with
| Some evs ->
let elterm = (th,StatT(SyncStmt(StmtExp(ValS(Oref(o))),b)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evs,str2))
| None -> raise (Rewrite("<rew_one_step,syn2,Event_space.plusE>",(disp_event ":" (Lock(th,o)) Plenty)))
end
| ExprT(e2) -> (** syn1 **)
(**let () = Printf.printf "Rule *syn1*\n" in**)
let elterm = (th,StatT(SyncStmt(e2,b)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,syn2,syn1>",(disp_aterm ":" ee Plenty)))
end
(*****************************************************************)
(********************** EXCEPTIONS AND RETURN ********************)
(*****************************************************************)
(* exit4 *)
| (mt,((th,StatT(BlockStmt(BlockIt((ExpStmt(ThrowSE(Throw(o))))::sS,_))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *exit4*\n" in**)
let elterm = (th,StatT(ExpStmt(ThrowSE(Throw(o)))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* throw2 *)
| (mt1,((th,StatT(ThrowStmt((StmtExp(ValS(Oref(o)))))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *throw2*\n" in**)
let elterm = (th,StatT(ExpStmt(ThrowSE(Throw(o)))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
(* throw1 *)
| (mt1,((th,StatT(ThrowStmt(e1)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *throw1*\n" in**)
let (mt2,((_,ss,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin match ss with
| ExprT(e2) ->
let elterm = (th,StatT(ThrowStmt(e2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,throw1>",(disp_aterm ":" ss Plenty)))
end
(* block2 *)
| (mt1,((th,StatT(BlockStmt(BlockIt(sS1,env1))),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *block2*\n" in**)
let (mt2,((_,sSS,z,stck2),objs2,evsp2,str2)) =
rew_one_step (mt1,((th,StatSeqT(sS1),R,Stack_of_env.push stck1 env1),objs1,evsp1,str1)) in
begin match sSS with
| StatSeqT(sS2) ->
begin match Stack_of_env.pop stck2 with
| Some env2 ->
let elterm = (th,StatT(BlockStmt(BlockIt(sS2,env2))),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| None -> raise (Rewrite("<rew_one_step,block2,Stack_of_env.pop>",
(Stack_of_env.display stck2 "s:" Plenty)
^(disp_aterm "a1:" (StatSeqT(sS1)) Plenty)
^(disp_aterm "a2:" sSS Plenty)))
end
| _ -> raise (Not_Applicable("<rew_one_step,block2>",
(disp_aterm ":" (StatSeqT(sS1)) Plenty)
^"\n---------------------------"
^(disp_aterm ":" sSS Plenty)))
end
(* ret2 *)
| (mt,((th,StatT(ReturnStmt(None)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *ret2*\n" inq**)
let elterm = (th,StatT(ExpStmt(ReturnSE(None))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* ret2 *)
| (mt,((th,StatT(ReturnStmt(Some StmtExp(ValS(v)))),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *ret2*\n" in**)
let elterm = (th,StatT(ExpStmt(ReturnSE(Some v))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* ret1 *)
| (mt1,((th,StatT(ReturnStmt(Some e1)),R,stck1),objs1,evsp1,str1)) ->
(**let () = Printf.printf "Rule *ret1*\n" in**)
let (mt2,((_,ss,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,ExprT(e1),R,stck1),objs1,evsp1,str1)) in
begin
match ss with
| ExprT(e2) ->
let elterm = (th,StatT(ReturnStmt(Some e2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,ret1>",(disp_aterm ":" ss Plenty)))
end
(* try1 *)
| (mt,((th,StatT(TryStmt(BlockIt([],_),_,_)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *try1*\n" in**)
let elterm = (th,StatT(Nop),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* try2 *) (** first part **)
| (mt,((th,StatT(TryStmt(BlockIt((ExpStmt(ReturnSE(f)))::sS,_),_,_)),R,stck),objs,evsp,str)) ->
(**let () = Printf.printf "Rule *try2 first-part*\n" in**)
let elterm = (th,StatT(ExpStmt(ReturnSE(f))),R,stck) in
(Mterm.add elterm (Mterm.remove elterm mt),
(elterm,objs,evsp,str))
(* try2 *) (** second part: finally clause **)
(* fin3 *)
|(mt1,((th,StatT(TryFinStmt(BlockIt((ExpStmt(ReturnSE(f)))::sS,envr),hH,b)),R,stck1),objs1,evsp1,str1)) ->
begin match b with
| BlockIt([],_) -> (** try2 **)
(**let () = Printf.printf "Rule *try2 second-part*\n" in**)
let elterm = (th,StatT(ExpStmt(ReturnSE(f))),R,stck1) in
(Mterm.add elterm (Mterm.remove elterm mt1),
(elterm,objs1,evsp1,str1))
| _ -> (* fin3 *)
let (mt2,((_,bb,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,StatT(BlockStmt(b)),R,stck1),objs1,evsp1,str1)) in
begin
match bb with
| StatT(BlockStmt(b2)) -> (** fin3 **)
(**let () = Printf.printf "Rule *fin3*\n" in**)
let elterm = (th,StatT(TryFinStmt(BlockIt((ExpStmt(ReturnSE(f)))::sS,envr),hH,b2)),z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),
(elterm,objs2,evsp2,str2))
| _ -> raise (Not_Applicable("<rew_one_step,fin3>",(disp_aterm ":" bb Plenty)))
end
end
(** b1 is throws **)
(* try6 *)
(* try5 *) (** first part **)
(* try10 *) (** first part **)
(* try9 *) (** first part **)
| (mt1,((th,StatT(TryStmt(BlockIt((ExpStmt(ThrowSE(Throw(Nonnull(p)))))::sS,envr),CC(ClType(ct),i,b1),hH)),R,stck1),objs1,evsp1,str1)) ->
if Store.belongs str1 (Nonnull(p)) ct then (** try6 **) (** try5 **)
let (mt2,((_,bc,z,stck2),objs2,evsp2,str2)) = rew_one_step (mt1,((th,StatT(BlockStmt(b1)),R,stck1),objs1,evsp1,str1)) in
begin match bc with
| StatT(Nop) |
ExprT(StmtExp(ValS(_))) |
StatT(ExpStmt(ValS(_))) |
ExprT(StmtExp(ThrowSE(Throw(_)))) |
StatT(ExpStmt(ThrowSE(Throw(_)))) |
ExprT(StmtExp(ReturnSE(_))) |
StatT(ExpStmt(ReturnSE(_))) -> (** try6 **)
(**let () = Printf.printf "Rule *try6*\n" in**)
let elterm = (th,bc,z,stck2) in
(Mterm.add elterm (Mterm.remove elterm mt2),