-
Notifications
You must be signed in to change notification settings - Fork 65
/
CogScriptsAttic.class.st
196 lines (185 loc) · 7.86 KB
/
CogScriptsAttic.class.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
Class {
#name : #CogScriptsAttic,
#superclass : #CogScripts,
#category : #'CogAttic-Scripts'
}
{ #category : #'closure scripts' }
CogScriptsAttic class >> bootstrapClosures [
"CogScripts bootstrapClosures"
| rep |
Transcript clear.
rep := false
ifTrue: [MCCacheRepository default]
ifFalse:
[MCHttpRepository
location: 'http://dev.qwaq.com/ss/Oinq'
user: 'qwaq'
password: ''].
"This changes load order in Monticello such that additions come in before modifications."
(rep loadVersionFromFileNamed: 'Monticello-eem.302.mcz') load.
"This adds some prereqs the compiler uses that are loaded in later packages:
Fix the ClassBuilder so redefining CompiledMethod can add and remove class variables.
Add Object/Array>>isArray.
Add new interface for accessing inst vars & fields on initializing the compiler (Encoder)."
self bootstrapClosuresCompilerPreloadCode readStream fileIn.
"This temporarily stops Monticello from unloading code on load and warning about overwriting changes.
Since changes span multiple packages need all additions in before any deletions occur.
Can't warn about anything until the new debugger api is installed."
ChangeSet
newChangesFromStream: self bootstrapClosuresNeuterMonticelloCode readStream
named: 'neuterMonticello'.
Smalltalk at: #DoNotUnload put: true.
1 to: 2 do:
[:i|
#( 'Compiler-eem.30.mcz'
'Files-eem.21.mcz'
'Exceptions-eem.14.mcz'
'Collections-eem.55.mcz'
'Tools-eem.45.mcz'
'Kernel-eem.82.mcz'
'System-eem.53.mcz'
'Brad-eem.51.mcz'
'Morphic-eem.38.mcz'
'Tweak-Compiler-eem.36.mcz'
'Tweak-Hacks-eem.30.mcz'
'Tweak-Basic-eem.151.mcz'
'Tweak-Core-Proto-eem.56.mcz') do:
[:pn|
Transcript clear; nextPutAll: pn; space; nextPut: $(; print: i; nextPut: $); endEntry.
(rep loadVersionFromFileNamed: pn) load].
Smalltalk at: #DoNotUnload put: false].
"Now remove the temporary hacks to Monticello"
(ChangeSet named: 'neuterMonticello') changedMessageList do:
[:mr| | changeRecords |
changeRecords := mr actualClass changeRecordsAt: mr methodSymbol.
changeRecords second fileIn].
"Install BlockClosure in the specialObjectsArray"
Smalltalk recreateSpecialObjectsArray.
"Throw the switch to compile to closures"
self bootstrapClosuresClosureCompilerSwitchCode readStream fileIn.
"Recompile the system except the one method we can't yet deal with in GeniePlugin (1 too many literals)"
(Smalltalk forgetDoIts allClasses reject: [:c| c name == #GeniePlugin]) do:
[:c|
{ c. c class } do:
[:b|
Transcript cr; print: b; endEntry.
b selectors asSortedCollection do:
[:s|
b recompile: s from: b]]].
UsefulScripts postRecompileCleanup.
self inform: 'Save and quit and then run UsefulScripts postRecompileCleanup.\Rinse and repeat' withCRs
]
{ #category : #'separate vm scripts' }
CogScriptsAttic class >> createSVMTree [
"Create the parallel StackInterpreterS, CoInterpreterS tree in which
objectMemory is an inst var rather than ObjectMemory et al being a superclass"
"CogScripts createSVMTree"
| changes map |
changes := Cursor execute showWhile: [self changedMethodsForObjectMemorySends].
map := Cursor execute showWhile: [self createStackInterpreterSHierarchy].
(ChangeSet superclassOrder: (StackInterpreter withAllSubclasses select: [:c| map includesKey: c]) asArray) do:
[:sourceClass|
sourceClass selectors do:
[:sel| | destClass source stamp |
destClass := map
at: (((sel beginsWith: 'primitive')
and: [sel last ~~ $:
and: [sel ~~ #primitiveFail]])
ifTrue: [{sourceClass. #primitives}]
ifFalse: [sourceClass])
ifAbsent: [map at: sourceClass].
(changes detect: [:c| c changeClass == sourceClass and: [c selector = sel]] ifNone: [])
ifNotNil:
[:change|
source := change source.
stamp := Utilities changeStamp copyReplaceAll: Utilities authorInitials with: Utilities authorInitials, ' (objmem refactor)']
ifNil:
[source := sourceClass sourceCodeAt: sel.
stamp := (sourceClass >> sel) timeStamp].
[destClass
compile: source
classified: (sourceClass whichCategoryIncludesSelector: sel)
withStamp: stamp
notifying: nil]
on: SyntaxErrorNotification
do: [:ex| | newBrowser |
newBrowser := Browser new setClass: destClass selector: nil.
newBrowser selectMessageCategoryNamed: (sourceClass whichCategoryIncludesSelector: sel).
Browser
openBrowserView: (newBrowser openMessageCatEditString: source)
label: 'category "', (sourceClass whichCategoryIncludesSelector: sel), '" in ', destClass name]]].
self readWriteVars, self readOnlyVars do:
[:sym|
(NewObjectMemory whichClassIncludesSelector: sym) ifNil:
[(NewObjectMemory whichClassDefinesInstVar: sym asString)
compile: sym, (String with: Character cr with: Character tab with: $^), sym
classified: #accessing]].
self readWriteVars do:
[:sym| | setter | setter := (sym, ':') asSymbol.
(NewObjectMemory whichClassIncludesSelector: setter) ifNil:
[(NewObjectMemory whichClassDefinesInstVar: sym asString)
compile: setter, ' aValue', (String with: Character cr with: Character tab with: $^), sym, ' := aValue'
classified: #accessing]].
]
{ #category : #'separate vm scripts' }
CogScriptsAttic class >> createStackInterpreterSHierarchy [
"Create the parallel StackInterpreterS, CoInterpreterS tree (without methods).
Answer a Dictionary maping source class to dest class with {source. #primitives} -> dest
for the added primitives classes."
| map |
(Smalltalk classNamed: #StackInterpreterS) ifNotNil:
[:sis|
(Object confirm: 'StackInterpreterS exists, nuke?') ifTrue:
[(ChangeSet superclassOrder: sis withAllSubclasses asArray) reverseDo:
[:sissc| sissc removeFromSystemUnlogged]]].
map := Dictionary new.
(ChangeSet superclassOrder: (StackInterpreter withAllSubclasses
remove: SchizophrenicClosureFormatStackInterpreter;
yourself) asArray) do:
[:sisc| | def |
def := sisc definition.
def := sisc == StackInterpreter
ifTrue: [((def copyReplaceAll: sisc superclass name, ' ' with: ObjectMemory superclass name, ' ')
copyReplaceAll: 'instanceVariableNames: ''' with: 'instanceVariableNames: ''objectMemory ')
copyReplaceAll: 'poolDictionaries: ''' with: 'poolDictionaries: ''', (ObjectMemory poolDictionaryNames fold: [:a :b| a, ' ', b]), ' ']
ifFalse: [def copyReplaceAll: sisc superclass name, ' ' with: sisc superclass name, 'S '].
def := def copyReplaceAll: sisc name printString with: sisc name printString, 'S'.
map at: sisc put: (Compiler evaluate: def)].
map at: {StackInterpreter. #primitives}
put: (Compiler
evaluate: 'StackInterpreterS subclass: #StackInterpreterSPrimitives
instanceVariableNames: ''''
classVariableNames: ''''
poolDictionaries: ''''
category: ''VMMaker-Interpreter''');
at: {CoInterpreter. #primitives}
put: (Compiler
evaluate: 'CoInterpreterS subclass: #CoInterpreterSPrimitives
instanceVariableNames: ''''
classVariableNames: ''''
poolDictionaries: ''''
category: ''VMMaker-Interpreter''');
at: {StackInterpreter. #objmem}
put: (Compiler
evaluate: 'NewObjectMemory subclass: #NewObjectMemoryS
instanceVariableNames: ''coInterpreter''
classVariableNames: ''''
poolDictionaries: ''''
category: ''VMMaker-Interpreter''');
at: {CoInterpreter. #objmem}
put: (Compiler
evaluate: 'NewObjectMemoryS subclass: #NewCoObjectMemoryS
instanceVariableNames: ''''
classVariableNames: ''''
poolDictionaries: ''''
category: ''VMMaker-Interpreter''').
"reparent subclasses underneath StackInterpreterSPrimitives & CoInterpreterSPrimitives"
#(StackInterpreterS CoInterpreterS) do:
[:cn|
((Smalltalk classNamed: cn) subclasses reject: [:c| c name endsWith: 'Primitives']) do:
[:sisc| | def |
def := sisc definition.
def := def copyReplaceAll: cn, ' ' with: cn, 'Primitives '.
Compiler evaluate: def]].
^map
]