-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathActivationMirrorTesting.ns
1478 lines (1316 loc) · 51 KB
/
ActivationMirrorTesting.ns
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
Newspeak3
'Root'
class ActivationMirrorTesting usingPlatform: p testFramework: m = (|
private ClassDeclarationBuilder = p mirrors ClassDeclarationBuilder.
private ObjectMirror = p mirrors ObjectMirror.
private ActivationMirror = p mirrors ActivationMirror.
private Message = p kernel Message.
private StringBuilder = p kernel StringBuilder.
private List = p collections List.
private Map = p collections Map.
private TestContext = m TestContext.
|) (
public class ActivationTests = TestBase () (
class Point x: x y: y = Object new (
|
public x = x.
public y ::= y.
public z
|
) (
) : (
)
activationRestartMethod: list = (
list add: 1984.
^10
)
add: x to: y = (
| z |
z:: x + y.
^z
)
assertOperandsOf: activation haveValues: values = (
assertList: (activation operands collect: [:ea | ea reflectee]) equals: values.
)
assertSlotsOf: activation haveNamesAndValues: pairs = (
| slots success |
slots:: activation slots.
success:: true.
1 to: pairs size / 2 do:
[:index | | name value |
name:: pairs at: index * 2 - 1.
value:: pairs at: index * 2.
assert: (slots at: index) name equals: name.
assert: (slots at: index) value reflectee equals: value].
)
assertThread: thread atMethod: expectedMethod snippet: expectedSnippet = (
| activation |
activation:: thread suspendedActivation.
assert: activation method name equals: expectedMethod.
assert: (currentSnippet: activation) equals: expectedSnippet.
)
compilationError = (
^Error
)
currentSnippet: activation = (
| range |
range:: activation sourceRange.
nil = range ifTrue: [^nil].
^activation method source copyFrom: range start to: range stop
)
deadHomeWithLocals: a = (
| b c d |
b:: 2. (* Not copied *)
c:: 3. (* Copied *)
d:: 4. (* Indirect *)
^[d:: d + c]
)
describeActivation: activation = (
| sb = StringBuilder new. |
describeActivation: activation to: sb.
^sb asString
)
describeActivation: activation to: sb = (
| enclosing methodMixin receiverMixin source range |
enclosing:: activation enclosingActivation.
[nil = enclosing] whileFalse:
[sb add: '[] in '.
enclosing:: enclosing enclosingActivation].
receiverMixin:: activation receiver getClass mixin.
sb add: receiverMixin name.
methodMixin:: activation method definingMixin.
methodMixin = receiverMixin ifFalse:
[sb add: '(', methodMixin name, ')'].
sb add: ' '.
sb add: activation method name.
sb add: ' '.
activation isUncontinuable ifTrue:
[sb add: '<uncontinuable>'. ^self].
source:: activation method source.
nil = source ifTrue:
[sb add: '<no source>'. ^self].
range:: activation sourceRange.
nil = range ifTrue:
[sb add: '<no source range for this bytecode>'. ^self].
sb add: '<'.
sb add: (source copyFrom: range start to: range stop).
sb add: '>'.
)
liveHomeWithLocals: a = (
| b c d |
b:: 2. (* Not copied *)
c:: 3. (* Copied *)
d:: 4. (* Indirect *)
^[d:: d + c] value
)
nlr1 = (
^nlr2
)
nlr2 = (
nlr3: [^2].
^20
)
nlr3: block = (
block value.
^3
)
quickResumeReturnAcrossBoundry = (
| closure thread activation |
closure:: [^'escaping simulation!'].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
activation:: thread suspendedActivation.
assert: activation closure equals: (ObjectMirror reflecting: closure).
assert: activation receiver equals: (ObjectMirror reflecting: self).
assert: activation method name equals: #quickResumeReturnAcrossBoundry.
assert: activation sender equals: nil.
thread resume.
assert: thread isBroken.
assert: (thread result reflectee printString startsWith: 'CannotReturn').
assert: thread suspendedActivation method name equals: #cannotReturn:.
assert: thread suspendedActivation sender equals: activation.
^'expected return'
)
seven = (
^[3 + 4]
)
seventySeven = (
^[(add: 3 to: 4) + (add: 30 to: 40)]
)
stackOf: thread = (
| names activation |
names:: List new.
activation:: thread suspendedActivation.
[nil = activation] whileFalse:
[names add: activation method name.
activation:: activation sender].
^names
)
public testActivationEquality = (
| closure thread activation1 activation2 activation3 |
closure:: [seven].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
activation1:: thread suspendedActivation.
thread stepInto. (* Send seven *)
activation2:: thread suspendedActivation.
activation3:: activation2 sender.
assert: activation1 method name equals: #testActivationEquality.
assert: activation2 method name equals: #seven.
assert: activation3 method name equals: #testActivationEquality.
assert: activation1 equals: activation3.
assert: activation1 hash equals: activation3 hash.
deny: activation1 equals: activation2.
deny: activation2 equals: activation3.
)
public testActivationEvaluate = (
| closure thread activation eval |
closure:: [add: 3 to: 4].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
thread stepInto. (* Push 3 *)
thread stepInto. (* Push 4 *)
thread stepInto. (* Send add:to: *)
activation:: thread suspendedActivation.
assert: activation receiver equals: (ObjectMirror reflecting: self).
assert: activation method name equals: #add:to:.
eval:: activation evaluate: 'x'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 3.
eval:: activation evaluate: 'y'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 4.
eval:: activation evaluate: 'z'.
assert: eval isFulfilled.
assert: eval result reflectee equals: nil.
eval:: activation evaluate: 'self'.
assert: eval isFulfilled.
assert: eval result reflectee equals: self.
should: [activation evaluate: '++'] signal: compilationError.
eval:: activation evaluate: 'w'.
assert: eval isBroken.
assert: eval result getClass mixin name equals: 'MessageNotUnderstood'.
)
public testActivationEvaluateEnclosingLocals = (
| x closure thread activation eval |
x:: 3. (* Not captured *)
closure:: [nil].
thread:: ActivationMirror invokeSuspended: closure.
activation:: thread suspendedActivation.
assert: activation receiver equals: (ObjectMirror reflecting: self).
assert: activation closure equals: (ObjectMirror reflecting: closure).
assert: activation method name equals: #testActivationEvaluateEnclosingLocals.
eval:: activation evaluate: 'x'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 3.
eval:: activation evaluate: 'x: 4'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 4.
assert: x equals: 4.
)
public testActivationEvaluateWithScope = (
| closure thread activation scope eval |
closure:: [add: 3 to: 4].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
thread stepInto. (* Push 3 *)
thread stepInto. (* Push 4 *)
thread stepInto. (* Send add:to: *)
activation:: thread suspendedActivation.
assert: activation receiver equals: (ObjectMirror reflecting: self).
assert: activation method name equals: #add:to:.
scope:: Map new.
scope at: #w put: (ObjectMirror reflecting: 10).
eval:: activation evaluate: 'x + y + w' with: scope.
assert: eval isFulfilled.
assert: eval result reflectee equals: 17.
)
public testActivationFactory = (
| src Point thread activation |
(* Need a fresh compile to ensure consistency of the factory compilation strategy. Can be removed the next time the bootstrap compiler is updated. *)
src:: 'class Point x: x y: y = Object new (
|
public x = x.
public y ::= y.
public z
|
)()'.
Point:: (ClassDeclarationBuilder fromSource: src) install applyToObject reflectee.
thread:: ActivationMirror invokeSuspended: [Point x: 3 y: 4].
assertThread: thread atMethod: #testActivationFactory snippet: 'Point'.
thread suspendedActivation stepOver. (* Send Point *)
assertThread: thread atMethod: #testActivationFactory snippet: '3'.
thread suspendedActivation stepOver. (* Push 3 *)
assertThread: thread atMethod: #testActivationFactory snippet: '4'.
thread suspendedActivation stepOver. (* Push 4 *)
assertThread: thread atMethod: #testActivationFactory snippet: 'x: 3 y: 4'.
thread suspendedActivation stepInto. (* Send x:y: *)
assertThread: thread atMethod: #x:y: snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #'Point class'.
thread suspendedActivation stepOver. (* Send basicNew *)
assertThread: thread atMethod: #x:y: snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #'Point class'.
thread suspendedActivation stepInto. (* Store @newInstance *)
assertThread: thread atMethod: #x:y: snippet: 'x'.
assert: thread suspendedActivation method definingMixin name equals: #'Point class'.
thread suspendedActivation stepInto. (* Push x *)
assertThread: thread atMethod: #x:y: snippet: 'y'.
assert: thread suspendedActivation method definingMixin name equals: #'Point class'.
thread suspendedActivation stepInto. (* Push y *)
assertThread: thread atMethod: #x:y: snippet: 'x: x y: y'.
assert: thread suspendedActivation method definingMixin name equals: #'Point class'.
thread suspendedActivation stepInto. (* Send initializer`x:y: *)
assertThread: thread atMethod: #x:y: snippet: 'new'.
assert: thread suspendedActivation method definingMixin name equals: #'Point'.
thread suspendedActivation stepOver. (* Send super initializer`new *)
assertThread: thread atMethod: #x:y: snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Pop *)
assertThread: thread atMethod: #x:y: snippet: 'x'.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Push x *)
assertThread: thread atMethod: #x:y: snippet: 'public x = x'.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Send init`x: *)
assertThread: thread atMethod: #x:y: snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Pop *)
assertThread: thread atMethod: #x:y: snippet: 'y'.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Push y *)
assertThread: thread atMethod: #x:y: snippet: 'public y ::= y'.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepInto. (* Send init`y: *)
assertThread: thread atMethod: #x:y: snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #Point.
thread suspendedActivation stepOut. (* Instance initializer *)
thread suspendedActivation stepOut. (* Factory *)
thread suspendedActivation stepOut. (* Closure *)
assert: thread isFulfilled.
assert: thread result reflectee x equals: 3.
assert: thread result reflectee y equals: 4.
assert: thread suspendedActivation equals: nil.
)
public testActivationIsUncontinuable = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [1984].
assertThread: thread atMethod: #testActivationIsUncontinuable snippet: '1984'. (* Push 1984 *)
assert: thread isSuspended.
activation:: thread suspendedActivation.
deny: activation isUncontinuable.
activation stepOver.
assertThread: thread atMethod: #testActivationIsUncontinuable snippet: '1984'. (* Return top *)
assert: thread isSuspended.
deny: activation isUncontinuable.
activation stepOver.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 1984).
assert: activation isUncontinuable.
)
public testActivationLocals = (
| closure thread activation locals |
closure:: [add: 3 to: 4].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
thread stepInto. (* Push 3 *)
thread stepInto. (* Push 4 *)
thread stepInto. (* Send add:to: *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. nil}.
thread stepInto. (* Send x *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. nil}.
thread stepInto. (* Send y *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. nil}.
thread stepInto. (* Send + y *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. nil}.
thread stepInto. (* Send z: *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. 7}.
thread stepInto. (* Send z *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#x. 3. #y. 4. #z. 7}.
thread stepInto. (* Return top *)
thread stepInto. (* Return top *)
assert: thread isFulfilled.
)
public testActivationLocalsDeadHome = (
| closure thread activation locals |
closure:: deadHomeWithLocals: 1.
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. nil. #b. nil. #c. nil. #d. nil}.
thread stepInto. (* Push d *)
thread stepInto. (* Push c *)
thread stepInto. (* Send + *)
thread stepInto. (* Store d *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. nil. #b. nil. #c. nil. #d. nil}.
thread stepInto. (* Return top *)
assert: thread isFulfilled.
)
public testActivationLocalsLiveHome = (
| closure thread activation locals |
closure:: [liveHomeWithLocals: 1].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
thread stepInto. (* Push 1 *)
thread stepInto. (* Send liveHomeWithLocals: *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. 1. #b. nil. #c. nil. #d. nil}.
thread stepInto. (* Push new array *)
thread stepInto. (* PopInto vector *)
thread stepInto. (* Push 2 *)
thread stepInto. (* PopInto b *)
thread stepInto. (* Push 3 *)
thread stepInto. (* PopInto c *)
thread stepInto. (* Push 4 *)
thread stepInto. (* PopIntoVector d *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. 1. #b. 2. #c. 3. #d. 4}.
thread stepInto. (* Push vector (copied) *)
thread stepInto. (* Push c (copied) *)
thread stepInto. (* Push closure *)
thread stepInto. (* Send value *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. 1. #b. 2. #c. 3. #d. 4}.
thread stepInto. (* Push d *)
thread stepInto. (* Push c *)
thread stepInto. (* Send + *)
thread stepInto. (* Store d *)
assertSlotsOf: thread suspendedActivation
haveNamesAndValues: {#a. 1. #b. 2. #c. 3. #d. 7}.
thread stepInto. (* Return top *)
thread stepInto. (* Return top *)
thread stepInto. (* Return top *)
assert: thread isFulfilled.
)
public testActivationNestedClassAccessor = (
| thread activation |
Point. (* Ensure consistency in whether the nested class has already been created. *)
thread:: ActivationMirror invokeSuspended: [Point].
assertThread: thread atMethod: #testActivationNestedClassAccessor snippet: 'Point'.
thread suspendedActivation stepInto. (* Send Point *)
assertThread: thread atMethod: #Point snippet: nil.
assert: thread suspendedActivation method definingMixin name equals: #ActivationTests.
thread suspendedActivation stepOut.
assertThread: thread atMethod: #testActivationNestedClassAccessor snippet: 'Point'.
thread suspendedActivation stepOut.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: Point).
assert: thread suspendedActivation equals: nil.
)
public testActivationOperandsClosure = (
| three four thread activation |
three:: 3.
four:: 4.
thread:: ActivationMirror invokeSuspended: [three + four].
assert: thread isSuspended.
activation:: thread suspendedActivation.
assertOperandsOf: activation haveValues: {}.
thread stepInto. (* Push three *)
assertOperandsOf: activation haveValues: {3}.
thread stepInto. (* Push four *)
assertOperandsOf: activation haveValues: {3. 4}.
thread stepInto. (* Send + *)
assertOperandsOf: activation haveValues: {7}.
thread stepInto. (* Return top *)
assertOperandsOf: activation haveValues: {}.
assert: thread isFulfilled.
)
public testActivationOperandsMethod = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
thread stepInto. (* Push 3 *)
thread stepInto. (* Push 4 *)
thread stepInto. (* Send add:to: *)
activation:: thread suspendedActivation.
assertOperandsOf: activation haveValues: {}.
thread stepInto. (* Send x *)
assertOperandsOf: activation haveValues: {3}.
thread stepInto. (* Send y *)
assertOperandsOf: activation haveValues: {3. 4}.
thread stepInto. (* Send + y *)
assertOperandsOf: activation haveValues: {7}.
thread stepInto. (* Send z: *)
assertOperandsOf: activation haveValues: {}.
thread stepInto. (* Send z *)
assertOperandsOf: activation haveValues: {7}.
thread stepInto. (* Return top *)
assertOperandsOf: activation haveValues: {}.
thread stepInto. (* Return top *)
assert: thread isFulfilled.
)
public testActivationRestartClosure = (
| list thread activation |
list:: List new.
thread:: ActivationMirror invokeSuspended: [list add: 1984. 10].
assertThread: thread atMethod: #testActivationRestartClosure snippet: 'list'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationRestartClosure snippet: '1984'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationRestartClosure snippet: 'add: 1984'.
assertList: list equals: {}.
thread suspendedActivation stepOver.
assertList: list equals: {1984}.
thread suspendedActivation restart.
assertThread: thread atMethod: #testActivationRestartClosure snippet: 'list'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 10).
assert: thread suspendedActivation equals: nil.
assertList: list equals: {1984. 1984}.
)
public testActivationRestartClosureWithLookup = (
| list thread activation |
list:: List new.
thread:: ActivationMirror invokeSuspended: [list add: 1984. 10].
assert: thread isSuspended.
assert: (describeActivation: thread suspendedActivation)
equals: '[] in ActivationTests testActivationRestartClosureWithLookup <list>'.
should: [activation restartWithLookup] signal: Error.
assert: thread isSuspended.
assert: (describeActivation: thread suspendedActivation)
equals: '[] in ActivationTests testActivationRestartClosureWithLookup <list>'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 10).
assert: thread suspendedActivation equals: nil.
assertList: list equals: {1984}.
)
public testActivationRestartMethod = (
| list thread activation |
list:: List new.
thread:: ActivationMirror invokeSuspended: [activationRestartMethod: list].
assertThread: thread atMethod: #testActivationRestartMethod snippet: 'list'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationRestartMethod snippet: 'activationRestartMethod: list'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #activationRestartMethod: snippet: 'list'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #activationRestartMethod: snippet: '1984'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #activationRestartMethod: snippet: 'add: 1984'.
assertList: list equals: {}.
thread suspendedActivation stepOver.
assertList: list equals: {1984}.
thread suspendedActivation restart.
assertThread: thread atMethod: #activationRestartMethod: snippet: 'list'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 10).
assert: thread suspendedActivation equals: nil.
assertList: list equals: {1984. 1984}.
)
public testActivationRestartMethodWithLookup = (
| builder klass instance list thread activation |
builder:: ClassDeclarationBuilder fromSource: 'class Foo = ()(
public foo: list = ( ^self bar )
public bar = ( ^Exception new signal )
public baz = ( ^Exception new signal )
)'.
klass:: builder install applyToObject reflectee.
instance:: klass new.
list:: List new.
thread:: (ActivationMirror invokeSuspended: [instance foo: list]) resume.
assert: thread isBroken.
activation:: thread suspendedActivation sender.
assert: (describeActivation: activation) equals: 'Foo foo: <bar>'.
(* Note the new method has a different number of temporaries than the old method. *)
builder instanceSide methods addFromSource:
'public foo: list = (
| temp1 temp2 |
temp1:: self baz.
temp2:: self baz.
list add: temp1.
list add: temp2.
^temp1 + temp2
)'.
builder install.
activation restartWithLookup.
assert: thread isSuspended.
activation:: thread suspendedActivation.
assert: (describeActivation: activation) equals: 'Foo foo: <baz>'.
thread resume.
assert: thread isBroken.
activation:: thread suspendedActivation.
assert: (describeActivation: activation) equals: 'Foo baz <^Exception new signal>'.
builder instanceSide methods addFromSource:
'public baz = ( ^1984 )'.
builder install.
activation restartWithLookup.
assert: thread isSuspended.
activation:: thread suspendedActivation.
assert: (describeActivation: activation) equals: 'Foo baz <1984>'.
assertList: list equals: {}.
thread resume.
assert: thread isFulfilled.
assert: thread result reflectee equals: 3968.
assertList: list equals: {1984. 1984}.
)
public testActivationRestartTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation restart] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationReturn = (
| list thread activation |
list:: List new.
thread:: ActivationMirror invokeSuspended: [list add: (add: 3 to: 4)].
assertThread: thread atMethod: #testActivationReturn snippet: 'list'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationReturn snippet: '3'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationReturn snippet: '4'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationReturn snippet: 'add: 3 to: 4'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #add:to: snippet: 'x'.
(* Return to another activation. *)
thread suspendedActivation return: (ObjectMirror reflecting: 1984).
assertThread: thread atMethod: #testActivationReturn snippet: 'add: (add: 3 to: 4)'.
thread suspendedActivation stepOver.
assertList: list equals: {1984}.
assertThread: thread atMethod: #testActivationReturn snippet: 'list add: (add: 3 to: 4)'.
(* Return to complete thread. *)
thread suspendedActivation return: (ObjectMirror reflecting: 42).
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 42).
assert: thread suspendedActivation equals: nil.
)
public testActivationReturnTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation return: (ObjectMirror reflecting: 1984)] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationSourceRange = (
| closure thread activation |
closure:: [add: 3 to: 4].
thread:: ActivationMirror invokeSuspended: closure.
assert: thread isSuspended.
assert: (currentSnippet: thread suspendedActivation) equals: '3'.
thread stepInto. (* Push 3 *)
assert: (currentSnippet: thread suspendedActivation) equals: '4'.
thread stepInto. (* Push 4 *)
assert: (currentSnippet: thread suspendedActivation) equals: 'add: 3 to: 4'.
thread stepInto. (* Send add:to: *)
assert: (currentSnippet: thread suspendedActivation) equals: 'x'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Send x *)
assert: (currentSnippet: thread suspendedActivation) equals: 'y'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Send y *)
assert: (currentSnippet: thread suspendedActivation) equals: '+ y'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Send + y *)
assert: (currentSnippet: thread suspendedActivation) equals: 'z:: x + y'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Send z: *)
assert: (currentSnippet: thread suspendedActivation) equals: 'z'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Send z *)
assert: (currentSnippet: thread suspendedActivation) equals: '^z'.
assert: (currentSnippet: thread suspendedActivation sender) equals: 'add: 3 to: 4'.
thread stepInto. (* Return top *)
assert: (currentSnippet: thread suspendedActivation) equals: 'add: 3 to: 4'.
thread stepInto. (* Return top *)
assert: thread isFulfilled.
)
public testActivationStepInto = (
| thread activation |
thread:: ActivationMirror invokeSuspended: seven.
assert: thread isSuspended.
thread stepInto. (* Push 3 *)
assert: thread isSuspended.
assertList: (stackOf: thread) equals: {#seven}.
thread stepInto. (* Push 4 *)
assert: thread isSuspended.
assertList: (stackOf: thread) equals: {#seven}.
thread stepInto. (* Send + *)
assert: thread isSuspended.
assertList: (stackOf: thread) equals: {#seven}.
thread stepInto. (* Return 7 *)
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 7).
assertList: (stackOf: thread) equals: {}.
)
public testActivationStepIntoTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation stepInto] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOut = (
| thread activation |
thread:: ActivationMirror invokeSuspended: seventySeven.
assertThread: thread atMethod: #seventySeven snippet: '3'.
thread suspendedActivation stepOver. (* Push 3 *)
assertThread: thread atMethod: #seventySeven snippet: '4'.
thread suspendedActivation stepOver. (* Push 4 *)
assertThread: thread atMethod: #seventySeven snippet: 'add: 3 to: 4'.
thread suspendedActivation stepInto. (* Send add:to: *)
assertThread: thread atMethod: #add:to: snippet: 'x'.
thread suspendedActivation stepOut.
assertThread: thread atMethod: #seventySeven snippet: '30'.
thread suspendedActivation stepOver. (* Push 30 *)
assertThread: thread atMethod: #seventySeven snippet: '40'.
thread suspendedActivation stepOver. (* Push 40 *)
assertThread: thread atMethod: #seventySeven snippet: 'add: 30 to: 40'.
thread suspendedActivation stepInto. (* Send add:to: *)
assertThread: thread atMethod: #add:to: snippet: 'x'.
thread suspendedActivation stepOut.
assertThread: thread atMethod: #seventySeven snippet: '+ (add: 30 to: 40)'.
thread suspendedActivation stepOut.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 77).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOutNLRSkipsGoal = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [nlr1].
assertThread: thread atMethod: #testActivationStepOutNLRSkipsGoal snippet: 'nlr1'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr1 snippet: 'nlr2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '[^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: 'nlr3: [^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr3: snippet: 'block'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr3: snippet: 'value'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '^2'.
thread suspendedActivation stepOut.
assertThread: thread atMethod: #nlr1 snippet: '^nlr2'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 2).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOutTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation stepOut] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOver = (
| thread activation |
thread:: ActivationMirror invokeSuspended: seventySeven.
assertThread: thread atMethod: #seventySeven snippet: '3'.
thread suspendedActivation stepOver. (* Push 3 *)
assertThread: thread atMethod: #seventySeven snippet: '4'.
thread suspendedActivation stepOver. (* Push 4 *)
assertThread: thread atMethod: #seventySeven snippet: 'add: 3 to: 4'.
thread suspendedActivation stepOver. (* Send add:to: *)
assertThread: thread atMethod: #seventySeven snippet: '30'.
thread suspendedActivation stepOver. (* Push 30 *)
assertThread: thread atMethod: #seventySeven snippet: '40'.
thread suspendedActivation stepOver. (* Push 40 *)
assertThread: thread atMethod: #seventySeven snippet: 'add: 30 to: 40'.
thread suspendedActivation stepOver. (* Send add:to: *)
assertThread: thread atMethod: #seventySeven snippet: '+ (add: 30 to: 40)'.
thread suspendedActivation stepOver. (* Send + *)
assertThread: thread atMethod: #seventySeven snippet: '(add: 3 to: 4) + (add: 30 to: 40)'.
thread suspendedActivation stepOver. (* Return 77 *)
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 77).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOverNLRSkipsGoal = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [nlr1].
assertThread: thread atMethod: #testActivationStepOverNLRSkipsGoal snippet: 'nlr1'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr1 snippet: 'nlr2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '[^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: 'nlr3: [^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr3: snippet: 'block'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr3: snippet: 'value'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #nlr1 snippet: '^nlr2'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 2).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepOverTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation stepOver] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationStepThrough = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [nlr1].
assertThread: thread atMethod: #testActivationStepThrough snippet: 'nlr1'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr1 snippet: 'nlr2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '[^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: 'nlr3: [^2]'.
thread suspendedActivation stepThrough.
assertThread: thread atMethod: #nlr2 snippet: '2'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 2).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepThroughNLRSkipsGoal = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [nlr1].
assertThread: thread atMethod: #testActivationStepThroughNLRSkipsGoal snippet: 'nlr1'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr1 snippet: 'nlr2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '[^2]'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: 'nlr3: [^2]'.
thread suspendedActivation stepThrough.
assertThread: thread atMethod: #nlr2 snippet: '2'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #nlr2 snippet: '^2'.
thread suspendedActivation stepThrough.
assertThread: thread atMethod: #nlr1 snippet: '^nlr2'.
thread resume.
assert: thread isFulfilled.
assert: thread result equals: (ObjectMirror reflecting: 2).
assert: thread suspendedActivation equals: nil.
)
public testActivationStepThroughTerminated = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assert: thread isSuspended.
activation:: thread suspendedActivation.
thread terminate.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
should: [activation stepThrough] signal: Exception.
assert: thread isTerminated.
assert: thread result equals: nil.
assert: thread suspendedActivation equals: nil.
)
public testActivationStepUncontinuable = (
| thread activation |
thread:: ActivationMirror invokeSuspended: [add: 3 to: 4].
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: '3'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: '4'.
thread suspendedActivation stepOver.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: 'add: 3 to: 4'.
thread suspendedActivation stepInto.
assertThread: thread atMethod: #add:to: snippet: 'x'.
activation:: thread suspendedActivation.
thread suspendedActivation stepOut.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: 'add: 3 to: 4'.
assert: activation isUncontinuable.
should: [activation stepInto] signal: Error.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: 'add: 3 to: 4'.
assert: thread isSuspended.
should: [activation stepOver] signal: Error.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: 'add: 3 to: 4'.
assert: thread isSuspended.
should: [activation stepThrough] signal: Error.
assertThread: thread atMethod: #testActivationStepUncontinuable snippet: 'add: 3 to: 4'.
assert: thread isSuspended.
should: [activation stepOut] signal: Error.