-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeSpecs.pck.st
2505 lines (2155 loc) · 72.9 KB
/
CodeSpecs.pck.st
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
'From Cuis 6.0 [latest update: #5658] on 1 February 2023 at 1:34:28 pm'!
'Description Transliterator for translating between Smalltalk dialects.
Used in Bee/Powerlang porting.
Copyright (c) 2021 Quorum Software.
See (MIT) license in LICENSES directory.'!
!provides: 'CodeSpecs' 1 8!
!requires: 'BeeCompatibility' 1 21 nil!
!requires: 'ExchangeFormat-Tonel-Lite' 1 38 nil!
SystemOrganization addCategory: 'CodeSpecs'!
SystemOrganization addCategory: 'CodeSpecs-Porting-Rules'!
SystemOrganization addCategory: 'CodeSpecs-Porting'!
SystemOrganization addCategory: 'CodeSpecs-Porting-Tests'!
!classDefinition: #ModuleTransliteratorTest category: 'CodeSpecs-Porting-Tests'!
TestCase subclass: #ModuleTransliteratorTest
instanceVariableNames: 'module transliterator builder'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Tests'!
!classDefinition: 'ModuleTransliteratorTest class' category: 'CodeSpecs-Porting-Tests'!
ModuleTransliteratorTest class
instanceVariableNames: ''!
!classDefinition: #MethodSpec category: 'CodeSpecs'!
Object subclass: #MethodSpec
instanceVariableNames: 'selector class source category module ast'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs'!
!classDefinition: 'MethodSpec class' category: 'CodeSpecs'!
MethodSpec class
instanceVariableNames: ''!
!classDefinition: #ModuleSpec category: 'CodeSpecs'!
Object subclass: #ModuleSpec
instanceVariableNames: 'name description classes extendedClasses subclassifiedClasses imports dependencies'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs'!
!classDefinition: 'ModuleSpec class' category: 'CodeSpecs'!
ModuleSpec class
instanceVariableNames: ''!
!classDefinition: #SpeciesSpec category: 'CodeSpecs'!
Object subclass: #SpeciesSpec
instanceVariableNames: 'instanceVariables methods module format'
classVariableNames: 'Format'
poolDictionaries: ''
category: 'CodeSpecs'!
!classDefinition: 'SpeciesSpec class' category: 'CodeSpecs'!
SpeciesSpec class
instanceVariableNames: 'Format'!
!classDefinition: #ClassSpec category: 'CodeSpecs'!
SpeciesSpec subclass: #ClassSpec
instanceVariableNames: 'name supername classVariables sharedPools metaclass variable pointers'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs'!
!classDefinition: 'ClassSpec class' category: 'CodeSpecs'!
ClassSpec class
instanceVariableNames: ''!
!classDefinition: #MetaclassSpec category: 'CodeSpecs'!
SpeciesSpec subclass: #MetaclassSpec
instanceVariableNames: 'class'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs'!
!classDefinition: 'MetaclassSpec class' category: 'CodeSpecs'!
MetaclassSpec class
instanceVariableNames: ''!
!classDefinition: #TransliterationRule category: 'CodeSpecs-Porting-Rules'!
Object subclass: #TransliterationRule
instanceVariableNames: 'scope'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'TransliterationRule class' category: 'CodeSpecs-Porting-Rules'!
TransliterationRule class
instanceVariableNames: ''!
!classDefinition: #MethodFilterRule category: 'CodeSpecs-Porting-Rules'!
TransliterationRule subclass: #MethodFilterRule
instanceVariableNames: 'block'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'MethodFilterRule class' category: 'CodeSpecs-Porting-Rules'!
MethodFilterRule class
instanceVariableNames: ''!
!classDefinition: #RefactoringRule category: 'CodeSpecs-Porting-Rules'!
TransliterationRule subclass: #RefactoringRule
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'RefactoringRule class' category: 'CodeSpecs-Porting-Rules'!
RefactoringRule class
instanceVariableNames: ''!
!classDefinition: #ClassRemoveRule category: 'CodeSpecs-Porting-Rules'!
RefactoringRule subclass: #ClassRemoveRule
instanceVariableNames: 'name'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'ClassRemoveRule class' category: 'CodeSpecs-Porting-Rules'!
ClassRemoveRule class
instanceVariableNames: ''!
!classDefinition: #ConversionRule category: 'CodeSpecs-Porting-Rules'!
RefactoringRule subclass: #ConversionRule
instanceVariableNames: 'original new'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'ConversionRule class' category: 'CodeSpecs-Porting-Rules'!
ConversionRule class
instanceVariableNames: ''!
!classDefinition: #IdentifierRenameRule category: 'CodeSpecs-Porting-Rules'!
ConversionRule subclass: #IdentifierRenameRule
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'IdentifierRenameRule class' category: 'CodeSpecs-Porting-Rules'!
IdentifierRenameRule class
instanceVariableNames: ''!
!classDefinition: #PackageRenameRule category: 'CodeSpecs-Porting-Rules'!
ConversionRule subclass: #PackageRenameRule
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'PackageRenameRule class' category: 'CodeSpecs-Porting-Rules'!
PackageRenameRule class
instanceVariableNames: ''!
!classDefinition: #SelectorRenameRule category: 'CodeSpecs-Porting-Rules'!
ConversionRule subclass: #SelectorRenameRule
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'SelectorRenameRule class' category: 'CodeSpecs-Porting-Rules'!
SelectorRenameRule class
instanceVariableNames: ''!
!classDefinition: #PackageRemoveRule category: 'CodeSpecs-Porting-Rules'!
RefactoringRule subclass: #PackageRemoveRule
instanceVariableNames: 'name'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'PackageRemoveRule class' category: 'CodeSpecs-Porting-Rules'!
PackageRemoveRule class
instanceVariableNames: ''!
!classDefinition: #RemoveInstVarRule category: 'CodeSpecs-Porting-Rules'!
RefactoringRule subclass: #RemoveInstVarRule
instanceVariableNames: 'ivar classname'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting-Rules'!
!classDefinition: 'RemoveInstVarRule class' category: 'CodeSpecs-Porting-Rules'!
RemoveInstVarRule class
instanceVariableNames: ''!
!classDefinition: #ImageModuleBuilder category: 'CodeSpecs-Porting'!
Object subclass: #ImageModuleBuilder
instanceVariableNames: 'module'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'ImageModuleBuilder class' category: 'CodeSpecs-Porting'!
ImageModuleBuilder class
instanceVariableNames: ''!
!classDefinition: #BeeModuleBuilder category: 'CodeSpecs-Porting'!
ImageModuleBuilder subclass: #BeeModuleBuilder
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'BeeModuleBuilder class' category: 'CodeSpecs-Porting'!
BeeModuleBuilder class
instanceVariableNames: ''!
!classDefinition: #PharoModuleBuilder category: 'CodeSpecs-Porting'!
ImageModuleBuilder subclass: #PharoModuleBuilder
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'PharoModuleBuilder class' category: 'CodeSpecs-Porting'!
PharoModuleBuilder class
instanceVariableNames: ''!
!classDefinition: #ModuleTransliterator category: 'CodeSpecs-Porting'!
Object subclass: #ModuleTransliterator
instanceVariableNames: 'module rules'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'ModuleTransliterator class' category: 'CodeSpecs-Porting'!
ModuleTransliterator class
instanceVariableNames: ''!
!classDefinition: #RejectMethodRule category: 'CodeSpecs-Porting'!
Object subclass: #RejectMethodRule
instanceVariableNames: 'scope'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'RejectMethodRule class' category: 'CodeSpecs-Porting'!
RejectMethodRule class
instanceVariableNames: ''!
!classDefinition: #TonelModuleExporter category: 'CodeSpecs-Porting'!
Object subclass: #TonelModuleExporter
instanceVariableNames: 'module path compatible'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'TonelModuleExporter class' category: 'CodeSpecs-Porting'!
TonelModuleExporter class
instanceVariableNames: ''!
!classDefinition: #TonelModuleImporter category: 'CodeSpecs-Porting'!
Object subclass: #TonelModuleImporter
instanceVariableNames: 'module path metadata'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'TonelModuleImporter class' category: 'CodeSpecs-Porting'!
TonelModuleImporter class
instanceVariableNames: ''!
!classDefinition: #TransliterationScope category: 'CodeSpecs-Porting'!
Object subclass: #TransliterationScope
instanceVariableNames: 'module class method'
classVariableNames: ''
poolDictionaries: ''
category: 'CodeSpecs-Porting'!
!classDefinition: 'TransliterationScope class' category: 'CodeSpecs-Porting'!
TransliterationScope class
instanceVariableNames: ''!
!ModuleTransliteratorTest commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!MethodSpec commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ModuleSpec commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!SpeciesSpec commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ClassSpec commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!MetaclassSpec commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!TransliterationRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!MethodFilterRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!RefactoringRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ClassRemoveRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ConversionRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!IdentifierRenameRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!PackageRenameRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!SelectorRenameRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!PackageRemoveRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!RemoveInstVarRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!BeeModuleBuilder commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ModuleTransliterator commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!RejectMethodRule commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!TonelModuleExporter commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!TonelModuleImporter commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!TransliterationScope commentStamp: '<historical>' prior: 0!
Copyright (c) 2021 Quorum Software.
See (MIT) license in root directory.
!
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
builderClass
^PharoModuleBuilder
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
setUp
module := ModuleSpec new name: 'TestModule'.
transliterator := ModuleTransliterator new module: module.
builder := self builderClass new module: module
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 2/1/2023 13:21:10'!
test001doNothing
builder addMethod: ModuleTransliteratorTest >> #test001doNothing.
transliterator transliterate.
self
assert: module name equals: 'TestModule';
assert: module classes size equals: 0;
assert: module extendedClasses size equals: 1;
assert: module extendedClasses first name equals: 'ModuleTransliteratorTest'
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test002filterMethod
| extensions class |
builder
addMethod: self class >> #test001doNothing;
addMethod: self class >> #test002filterMethod.
extensions := module extendedClasses.
class := extensions first.
transliterator
removeMethodsSuchThat: [:m | m selector beginsWith: 'test002'];
transliterate.
self
assert: module name equals: 'TestModule';
assert: extensions size equals: 1;
assert: class name equals: 'ModuleTransliteratorTest';
assert: class methods size equals: 1;
assert: class methods first selector equals: #test001doNothing
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test010removeClass
| extensions test |
builder
addMethod: self class >> #test001doNothing;
addMethod: self class >> #test010removeClass;
addMethodCompiling: '& anInteger ^self bitAnd: anInteger' in: LargeInteger;
addMethodCompiling: 'abs ^self' in: LargePositiveInteger;
addClassDefinition: LargeNegativeInteger;
calculateDependencies.
transliterator removeClass: 'LargeInteger'; transliterate.
extensions := module extendedClasses.
test := extensions first.
self
assert: module classes size equals: 0;
assert: extensions size equals: 1;
assert: test name equals: 'ModuleTransliteratorTest';
assert: test methods size equals: 1;
assert: test methods first selector equals: #test001doNothing
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test020removeInstVar
| extensions point |
builder
addMethod: Point >> #x;
addMethod: Point >> #y.
transliterator removeInstVar: 'x' in: 'Point'; transliterate.
extensions := module extendedClasses.
point := extensions first.
self
assert: extensions size equals: 1;
assert: point name equals: 'Point';
assert: point methods size equals: 1;
assert: point methods first selector equals: #y
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test030renameInstVar
| extensions point x source |
builder
addMethod: Point >> #x;
addMethod: Point >> #y.
transliterator
renameIdentifier: 'x' to: 'z' class: 'Point';
transliterate.
extensions := module extendedClasses.
point := extensions first.
x := point methods first.
source := x ast statements first source.
self
assert: extensions size equals: 1;
assert: point name equals: 'Point';
assert: point instVarNames asArray equals: #('z' 'y');
assert: point methods size equals: 2;
assert: x selector equals: #x;
deny: (source includesString: 'x');
assert: (source includesString: 'z')
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test031renameClassVar
| spec extensions source large method |
spec := builder addClassExtension: LargeInteger.
spec cvarNames: #('Base' 'DigitLength').
builder
addMethodCompiling: 'digitAt: index put: integer
| valid |
valid := integer bitAnd: Base - 1.
self uShortAtOffset: index - 1 * DigitLength put: valid' in: LargeInteger.
transliterator
renameIdentifier: 'Base' to: 'Foo' class: 'LargeInteger';
transliterate.
extensions := module extendedClasses.
large := extensions first.
method := large methods first.
source := method ast source.
self
assert: large classVarNames asArray sort equals: #('DigitLength' 'Foo');
deny: (source includesString: 'Base');
assert: (source includesString: 'Foo')
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test032renamePoolVar
| spec pool extensions character method source |
spec := builder addClassExtension: Character.
pool := PoolDictionary new at: 'Cr' put: 1; yourself.
spec classVariables at: 'Characters' put: pool.
builder addMethodCompiling: 'cr ^Cr' in: Character class.
transliterator renameIdentifier: 'Cr' to: 'Foo'; transliterate.
extensions := module extendedClasses.
character := extensions first.
method := character metaclass methods first.
source := method ast source.
self
deny: (source includesString: 'Cr');
assert: (source includesString: 'Foo')
! !
!ModuleTransliteratorTest methodsFor: 'private' stamp: 'KenD 5/1/2022 12:58:38'!
test033renameSharedPool
| spec |
spec := builder addClassDefinition: Character.
spec sharedPools add: #CharacterConstants.
transliterator
renameIdentifier: 'CharacterConstants' to: 'Characters';
transliterate.
self
assert: module classes first sharedPools asArray sort equals: #(#'Characters')
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
canBeCompiled
^self compiler notNil
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
canBeParsed
^self cannonicalAst notNil
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
equals: aMethodSpec
^self canBeCompiled
and: [aMethodSpec canBeCompiled]
and: [self isFrameless not]
and: [self isEquivalentTo: aMethodSpec]
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
isEquivalentTo: aMethodSpec
| m1 m2 |
selector == aMethodSpec selector ifFalse: [^false].
class == aMethodSpec classBinding ifFalse: [^false].
m1 := self asCompiledMethod.
m1 isNil ifTrue: [^false].
m2 := aMethodSpec asCompiledMethod.
m2 isNil ifTrue: [^false].
^m1 equals: m2
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
isExtension
^class isExtension
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
isFrameless
^self halt asCompiledMethod isFrameless
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
referencesIdentifier: aString
^self referencedIdentifiers
anySatisfy: [:identifier | identifier name = aString]
! !
!MethodSpec methodsFor: 'testing' stamp: 'KenD 5/1/2022 12:18:05'!
usesInstanceVariableNamed: aString
^(self ast variableNamed: aString) notNil
! !
!MethodSpec methodsFor: 'converting' stamp: 'KenD 5/1/2022 12:18:05'!
asCompiledMethod
self canBeCompiled ifFalse: [^nil].
^self
propertyAt: #compiledMethod
ifAbsentPut: [self compiler compileMethod: source]
! !
!MethodSpec methodsFor: 'converting' stamp: 'KenD 5/1/2022 12:18:05'!
ast
self canBeCompiled ifFalse: [^nil].
^ast ifNil:
[ast := [self compiler parse: source] on: SUndeclaredIdentifierError do: [ :e | e resume ]]
! !
!MethodSpec methodsFor: 'converting' stamp: 'KenD 5/1/2022 12:18:05'!
cannonicalAst
^self halt propertyAt: #cannonicalAst ifAbsentPut: [self ast]
! !
!MethodSpec methodsFor: 'converting' stamp: 'KenD 5/1/2022 12:18:05'!
referencedIdentifiers
^self ast ifNil: [#()] ifNotNil: [:node | node identifiers]
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
category
^self isExtension
ifTrue: ['*' , (module name readStream upToLast: $-)]
ifFalse: [category]
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
category: aString
category := aString
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
classBinding
^class
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
classBinding: aSpeciesSpec
class := aSpeciesSpec
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/5/2022 13:43:14'!
compiler
^ Smalltalk at: #SSmalltalkCompiler ifAbsent: [ nil ]! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
module
^module
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
module: aModuleSpec
module := aModuleSpec
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
removeFromClass
class removeMethod: self
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
selector
^selector
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
selector: aSymbol
selector := aSymbol
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
source
^source
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
source: aString
source := aString.
ast := nil
! !
!MethodSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:18:05'!
sourceCode
^source
! !
!MethodSpec methodsFor: 'inquiries' stamp: 'KenD 5/1/2022 12:18:05'!
bytecodes
^self canBeCompiled ifTrue: [self asCompiledMethod bytecodes]
! !
!MethodSpec methodsFor: 'inquiries' stamp: 'KenD 5/1/2022 12:18:05'!
classname
^class name
! !
!MethodSpec methodsFor: 'comparing' stamp: 'KenD 5/1/2022 12:18:05'!
= aMethodSpec
^aMethodSpec class = self class
and: [aMethodSpec selector == selector]
and: [aMethodSpec classBinding = class]
! !
!MethodSpec methodsFor: 'comparing' stamp: 'KenD 5/1/2022 12:18:05'!
hash
^class name hash hashWith: selector
! !
!MethodSpec methodsFor: 'printing' stamp: 'KenD 5/1/2022 12:18:05'!
printOn: aStream
aStream nextPutAll: class name asString , '>>#' , selector asString
! !
!MethodSpec methodsFor: 'services' stamp: 'KenD 5/1/2022 12:18:05'!
resolveClass
^module resolveClass: class name
! !
!ModuleSpec methodsFor: 'services' stamp: 'KenD 5/1/2022 12:16:33'!
withAllSubclasses: aClassSpec
| all |
all := self allClasses.
aClassSpec isMetaclass ifTrue: [all := all collect: #metaclass].
^all select: [:c | c withAllSuperclasses includes: aClassSpec]
! !
!ModuleSpec methodsFor: '*CodeSpecs-Porting' stamp: 'KenD 5/1/2022 13:17:47'!
beeDefinition
| changes sorted meta useful extmeta |
sorted := self sortedClasses.
meta := sorted collect: [:c | c metaclass].
changes := OrderedCollection new.
sorted collect: [:c | c beeDefinition] in: changes.
useful := meta select: [:m | m instVarNames notEmpty].
useful collect: [:m | m beeDefinition] in: changes.
extmeta := extendedClasses collect: [:c | c metaclass].
meta , sorted , extendedClasses , extmeta
do: [:c | c methods collect: [:m | m beeDefinition] in: changes].
^changes
! !
!ModuleSpec methodsFor: '*CodeSpecs-Porting' stamp: 'KenD 5/1/2022 13:17:47'!
exportPseudoTonel: path
TonelModuleExporter new path: path; module: self; exportPseudoTonel
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
addClass: aClassSpec
classes add: aClassSpec
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
addClassExtension: aClassSpec
extendedClasses add: aClassSpec
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
addClasses: aCollection
aCollection do: [:c | self addClass: c]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
addDependencies: aCollection
aCollection keysAndValuesDo: [:dep :objects |
dependencies
at: dep
put: objects
ifPresent: [:current | (current addAll: objects) withoutDuplicates]]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/18/2022 13:53:46'!
addSubclassifiedClass: aClassSpec
subclassifiedClasses ifAbsentAdd: aClassSpec
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
associationAt: aSymbol ifAbsent: aBlock
| string |
string := aSymbol asString.
classes do: [:c | c name = string ifTrue: [^aSymbol -> c]].
extendedClasses do: [:c | c name = string ifTrue: [^aSymbol -> c]].
subclassifiedClasses do: [:c | c name = string ifTrue: [^aSymbol -> c]].
^imports associationAt: aSymbol ifAbsent: aBlock
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
cleanDependencies
| needed |
needed := OrderedCollection new.
self methodReferences keys do: [:identifier | needed add: identifier name].
self hierarchyReferences keys
do: [:identifier | needed add: identifier name].
extendedClasses do: [:c | needed add: c name].
dependencies copy keysAndValuesDo: [:module :identifiers |
(identifiers keys anySatisfy: [:identifier | needed includes: identifier])
ifFalse: [dependencies removeKey: module]]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
hierarchyReferences
| references |
references := Dictionary new.
self allClassesDo: [:c | | list |
c superclass ifNotNil: [
list := references at: c superclass ifAbsentPut: [OrderedCollection new].
list add: c]].
^references
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
methodReferences
| references |
references := Dictionary new.
self allMethodsDo: [:m |
m referencedIdentifiers reject: #isLocal thenDo: [:identifier | | list |
list := references at: identifier ifAbsentPut: [OrderedCollection new].
list add: m]].
^references
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
printOn: aStream
aStream
nextPut: $<;
print: name;
nextPutAll: '> module'
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeCategory: aSymbol inClass: aClassSpec
| class |
class := self resolveClass: aClassSpec.
class removeCategory: aSymbol
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeClass: aClassSpec
| class |
class := self resolveClass: aClassSpec.
classes remove: class ifAbsent: nil
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeEmptyExtensions
extendedClasses copy
reject: #hasMethods
thenDo: [:c | extendedClasses remove: c]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeExtendedClass: aClassSpec
| class |
class := self resolveClass: aClassSpec.
extendedClasses remove: class ifAbsent: nil
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeMethod: aMethodSpec
self ASSERT: (self includesClass: aMethodSpec classBinding).
aMethodSpec classBinding removeMethod: aMethodSpec
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeSelectors: aCollection
self allClassesDo: [:c |
c removeSelectors: aCollection.
c metaclass removeSelectors: aCollection]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeSelectors: aCollection inClass: aClassSpec
| class |
class := self resolveClass: aClassSpec.
class removeSelectors: aCollection
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeSelectors: aCollection inScope: aClassSpec
| class all |
class := self resolveClass: aClassSpec.
all := self withAllSubclasses: class.
all do: [:c | c removeSelectors: aCollection]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeSubclassesOf: aClassSpec
| class |
class := self resolveClass: aClassSpec.
class allSubclasses do: [:c | self removeClass: c; removeExtendedClass: c]
! !
!ModuleSpec methodsFor: 'adding / removing' stamp: 'KenD 5/1/2022 12:16:33'!
removeSubclassifiedClass: aClassSpec
| class |
class := self resolveClass: aClassSpec.
subclassifiedClasses remove: class ifAbsent: nil
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
at: aSymbol
^self at: aSymbol ifAbsent: nil
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
at: aSymbol ifAbsent: aBlock
| string |
string := aSymbol asString.
classes do: [:c | c name = string ifTrue: [^c]].
extendedClasses do: [:c | c name = string ifTrue: [^c]].
subclassifiedClasses do: [:c | c name = string ifTrue: [^c]].
^imports at: aSymbol ifAbsent: aBlock
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
classes
^classes
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
dependencies
^dependencies
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
dependencies: aDictionary
dependencies := aDictionary
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
description
^description
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
description: aString
description := aString
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
extendedClasses
^extendedClasses
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
name
^name
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
name: aString
name := aString
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
referencedGlobals
| referenced |
referenced := Dictionary new.
self allMethodsDo: [:m |
m referencedIdentifiers
select: [:identifier | | b |
b := identifier binding.
b isGlobal or: [b isUnresolved]]
thenDo: [:global | (referenced
at: global name
ifAbsentPut: [OrderedCollection new])
add: m]].
^referenced
! !
!ModuleSpec methodsFor: 'accessing' stamp: 'KenD 5/1/2022 12:16:33'!
requiredImports
| required |
required := Dictionary new.
self referencedGlobals
keysAndValuesDo: [:global :dependents | (self definesGlobal: global)
ifFalse: [required at: global put: dependents]].
^required
! !
!ModuleSpec methodsFor: 'private' stamp: 'KenD 5/1/2022 12:16:33'!
sortedClasses
| remaining sorted |
remaining := classes copy.
sorted := OrderedCollection new.
[remaining isEmpty] whileFalse: [| c |
c := remaining first.
(remaining includes: c superclass)
ifTrue: [remaining removeFirst; add: c]
ifFalse: [
remaining remove: c.
sorted add: c]].
^sorted
! !
!ModuleSpec methodsFor: 'initialization' stamp: 'KenD 5/1/2022 12:16:33'!
addImport: anAssociation
imports add: anAssociation
! !
!ModuleSpec methodsFor: 'initialization' stamp: 'KenD 5/1/2022 12:16:33'!
addImports: aCollection
aCollection do: [:token | self addImport: token asSymbol -> nil]
! !
!ModuleSpec methodsFor: 'initialization' stamp: 'KenD 5/1/2022 12:16:33'!
initialize
classes := OrderedCollection new.
extendedClasses := OrderedCollection new.
subclassifiedClasses := OrderedCollection new.
imports := Dictionary new.
dependencies := Dictionary new
! !
!ModuleSpec methodsFor: 'resolving' stamp: 'KenD 5/1/2022 12:16:33'!
basicResolveClass: aString
classes do: [:c | c name asString = aString ifTrue: [^c]].
extendedClasses do: [:c | c name asString = aString ifTrue: [^c]].
subclassifiedClasses do: [:c | c name asString = aString ifTrue: [^c]].
^nil
! !
!ModuleSpec methodsFor: 'resolving' stamp: 'KenD 5/1/2022 12:16:33'!