1
0

Compiler.st 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. Smalltalk current createPackage: 'Compiler' properties: #{}!
  2. Object subclass: #ChunkParser
  3. instanceVariableNames: 'stream'
  4. package: 'Compiler'!
  5. !ChunkParser methodsFor: 'accessing'!
  6. stream: aStream
  7. stream := aStream
  8. ! !
  9. !ChunkParser methodsFor: 'reading'!
  10. nextChunk
  11. "The chunk format (Smalltalk Interchange Format or Fileout format)
  12. is a trivial format but can be a bit tricky to understand:
  13. - Uses the exclamation mark as delimiter of chunks.
  14. - Inside a chunk a normal exclamation mark must be doubled.
  15. - A non empty chunk must be a valid Smalltalk expression.
  16. - A chunk on top level with a preceding empty chunk is an instruction chunk:
  17. - The object created by the expression then takes over reading chunks.
  18. This metod returns next chunk as a String (trimmed), empty String (all whitespace) or nil."
  19. | char result chunk |
  20. result := '' writeStream.
  21. [char := stream next.
  22. char notNil] whileTrue: [
  23. char = '!!' ifTrue: [
  24. stream peek = '!!'
  25. ifTrue: [stream next "skipping the escape double"]
  26. ifFalse: [^result contents trimBoth "chunk end marker found"]].
  27. result nextPut: char].
  28. ^nil "a chunk needs to end with !!"
  29. ! !
  30. !ChunkParser class methodsFor: 'not yet classified'!
  31. on: aStream
  32. ^self new stream: aStream
  33. ! !
  34. Object subclass: #DoIt
  35. instanceVariableNames: ''
  36. package: 'Compiler'!
  37. Object subclass: #Exporter
  38. instanceVariableNames: ''
  39. package: 'Compiler'!
  40. !Exporter methodsFor: 'fileOut'!
  41. exportAll
  42. "Export all packages in the system."
  43. ^String streamContents: [:stream |
  44. Smalltalk current packages do: [:pkg |
  45. stream nextPutAll: (self exportPackage: pkg name)]]
  46. !
  47. exportClass: aClass
  48. "Export a single class. Subclasses override these methods."
  49. ^String streamContents: [:stream |
  50. self exportDefinitionOf: aClass on: stream.
  51. self exportMethodsOf: aClass on: stream.
  52. self exportMetaDefinitionOf: aClass on: stream.
  53. self exportMethodsOf: aClass class on: stream]
  54. !
  55. exportPackage: packageName
  56. "Export a given package by name."
  57. | package |
  58. ^String streamContents: [:stream |
  59. package := Smalltalk current packageAt: packageName.
  60. self exportPackageDefinitionOf: package on: stream.
  61. "Export classes in dependency order.
  62. Update (issue #171): Remove duplicates for export"
  63. package sortedClasses asSet do: [:each |
  64. stream nextPutAll: (self exportClass: each)].
  65. self exportPackageExtensionsOf: package on: stream]
  66. ! !
  67. !Exporter methodsFor: 'private'!
  68. classNameFor: aClass
  69. ^aClass isMetaclass
  70. ifTrue: [aClass instanceClass name, '.klass']
  71. ifFalse: [
  72. aClass isNil
  73. ifTrue: ['nil']
  74. ifFalse: [aClass name]]
  75. !
  76. exportDefinitionOf: aClass on: aStream
  77. aStream
  78. nextPutAll: 'smalltalk.addClass(';
  79. nextPutAll: '''', (self classNameFor: aClass), ''', ';
  80. nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);
  81. nextPutAll: ', ['.
  82. aClass instanceVariableNames
  83. do: [:each | aStream nextPutAll: '''', each, '''']
  84. separatedBy: [aStream nextPutAll: ', '].
  85. aStream
  86. nextPutAll: '], ''';
  87. nextPutAll: aClass category, '''';
  88. nextPutAll: ');'.
  89. aClass comment notEmpty ifTrue: [
  90. aStream
  91. lf;
  92. nextPutAll: 'smalltalk.';
  93. nextPutAll: (self classNameFor: aClass);
  94. nextPutAll: '.comment=';
  95. nextPutAll: aClass comment asJavascript].
  96. aStream lf
  97. !
  98. exportMetaDefinitionOf: aClass on: aStream
  99. aClass class instanceVariableNames isEmpty ifFalse: [
  100. aStream
  101. nextPutAll: 'smalltalk.', (self classNameFor: aClass class);
  102. nextPutAll: '.iVarNames = ['.
  103. aClass class instanceVariableNames
  104. do: [:each | aStream nextPutAll: '''', each, '''']
  105. separatedBy: [aStream nextPutAll: ','].
  106. aStream nextPutAll: '];', String lf]
  107. !
  108. exportMethod: aMethod of: aClass on: aStream
  109. aStream
  110. nextPutAll: 'smalltalk.addMethod(';lf;
  111. nextPutAll: aMethod selector asSelector asJavascript, ',';lf;
  112. nextPutAll: 'smalltalk.method({';lf;
  113. nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;
  114. nextPutAll: 'category: ''', aMethod category, ''',';lf;
  115. nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;
  116. nextPutAll: 'args: ', aMethod arguments asJavascript, ','; lf;
  117. nextPutAll: 'source: ', aMethod source asJavascript, ',';lf;
  118. nextPutAll: 'messageSends: ', aMethod messageSends asJavascript, ',';lf;
  119. nextPutAll: 'referencedClasses: ', aMethod referencedClasses asJavascript.
  120. aStream
  121. lf;
  122. nextPutAll: '}),';lf;
  123. nextPutAll: 'smalltalk.', (self classNameFor: aClass);
  124. nextPutAll: ');';lf;lf
  125. !
  126. exportMethodsOf: aClass on: aStream
  127. "Issue #143: sort methods alphabetically"
  128. ((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector]) do: [:each |
  129. (each category match: '^\*') ifFalse: [
  130. self exportMethod: each of: aClass on: aStream]].
  131. aStream lf
  132. !
  133. exportPackageDefinitionOf: package on: aStream
  134. aStream
  135. nextPutAll: 'smalltalk.addPackage(';
  136. nextPutAll: '''', package name, ''', ', package propertiesAsJSON , ');'.
  137. aStream lf
  138. !
  139. exportPackageExtensionsOf: package on: aStream
  140. "Issue #143: sort classes and methods alphabetically"
  141. | name |
  142. name := package name.
  143. (Package sortedClasses: Smalltalk current classes) do: [:each |
  144. {each. each class} do: [:aClass |
  145. ((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector]) do: [:method |
  146. (method category match: '^\*', name) ifTrue: [
  147. self exportMethod: method of: aClass on: aStream ]]]]
  148. ! !
  149. Exporter subclass: #ChunkExporter
  150. instanceVariableNames: ''
  151. package: 'Compiler'!
  152. !ChunkExporter methodsFor: 'not yet classified'!
  153. chunkEscape: aString
  154. "Replace all occurrences of !! with !!!! and trim at both ends."
  155. ^(aString replace: '!!' with: '!!!!') trimBoth
  156. !
  157. classNameFor: aClass
  158. ^aClass isMetaclass
  159. ifTrue: [aClass instanceClass name, ' class']
  160. ifFalse: [
  161. aClass isNil
  162. ifTrue: ['nil']
  163. ifFalse: [aClass name]]
  164. !
  165. exportDefinitionOf: aClass on: aStream
  166. "Chunk format."
  167. aStream
  168. nextPutAll: (self classNameFor: aClass superclass);
  169. nextPutAll: ' subclass: #', (self classNameFor: aClass); lf;
  170. nextPutAll: ' instanceVariableNames: '''.
  171. aClass instanceVariableNames
  172. do: [:each | aStream nextPutAll: each]
  173. separatedBy: [aStream nextPutAll: ' '].
  174. aStream
  175. nextPutAll: ''''; lf;
  176. nextPutAll: ' package: ''', aClass category, '''!!'; lf.
  177. aClass comment notEmpty ifTrue: [
  178. aStream
  179. nextPutAll: '!!', (self classNameFor: aClass), ' commentStamp!!';lf;
  180. nextPutAll: (self chunkEscape: aClass comment), '!!';lf].
  181. aStream lf
  182. !
  183. exportMetaDefinitionOf: aClass on: aStream
  184. aClass class instanceVariableNames isEmpty ifFalse: [
  185. aStream
  186. nextPutAll: (self classNameFor: aClass class);
  187. nextPutAll: ' instanceVariableNames: '''.
  188. aClass class instanceVariableNames
  189. do: [:each | aStream nextPutAll: each]
  190. separatedBy: [aStream nextPutAll: ' '].
  191. aStream
  192. nextPutAll: '''!!'; lf; lf]
  193. !
  194. exportMethod: aMethod of: aClass on: aStream
  195. aStream
  196. lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;
  197. nextPutAll: '!!'
  198. !
  199. exportMethods: methods category: category of: aClass on: aStream
  200. "Issue #143: sort methods alphabetically"
  201. aStream
  202. nextPutAll: '!!', (self classNameFor: aClass);
  203. nextPutAll: ' methodsFor: ''', category, '''!!'.
  204. (methods sorted: [:a :b | a selector <= b selector]) do: [:each |
  205. self exportMethod: each of: aClass on: aStream].
  206. aStream nextPutAll: ' !!'; lf; lf
  207. !
  208. exportMethodsOf: aClass on: aStream
  209. "Issue #143: sort protocol alphabetically"
  210. | map |
  211. map := Dictionary new.
  212. aClass protocolsDo: [:category :methods |
  213. (category match: '^\*') ifFalse: [ map at: category put: methods ]].
  214. (map keys sorted: [:a :b | a <= b ]) do: [:category | | methods |
  215. methods := map at: category.
  216. self
  217. exportMethods: methods
  218. category: category
  219. of: aClass
  220. on: aStream ]
  221. !
  222. exportPackageDefinitionOf: package on: aStream
  223. "Chunk format."
  224. aStream
  225. nextPutAll: 'Smalltalk current createPackage: ''', package name,
  226. ''' properties: ', package properties storeString, '!!'; lf.
  227. !
  228. exportPackageExtensionsOf: package on: aStream
  229. "We need to override this one too since we need to group
  230. all methods in a given protocol under a leading methodsFor: chunk
  231. for that class."
  232. "Issue #143: sort protocol alphabetically"
  233. | name map |
  234. name := package name.
  235. (Package sortedClasses: Smalltalk current classes) do: [:each |
  236. {each. each class} do: [:aClass |
  237. map := Dictionary new.
  238. aClass protocolsDo: [:category :methods |
  239. (category match: '^\*', name) ifTrue: [ map at: category put: methods ]].
  240. (map keys sorted: [:a :b | a <= b ]) do: [:category | | methods |
  241. methods := map at: category.
  242. self exportMethods: methods category: category of: aClass on: aStream ]]]
  243. ! !
  244. Exporter subclass: #StrippedExporter
  245. instanceVariableNames: ''
  246. package: 'Compiler'!
  247. !StrippedExporter methodsFor: 'private'!
  248. exportDefinitionOf: aClass on: aStream
  249. aStream
  250. nextPutAll: 'smalltalk.addClass(';
  251. nextPutAll: '''', (self classNameFor: aClass), ''', ';
  252. nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);
  253. nextPutAll: ', ['.
  254. aClass instanceVariableNames
  255. do: [:each | aStream nextPutAll: '''', each, '''']
  256. separatedBy: [aStream nextPutAll: ', '].
  257. aStream
  258. nextPutAll: '], ''';
  259. nextPutAll: aClass category, '''';
  260. nextPutAll: ');'.
  261. aStream lf
  262. !
  263. exportMethod: aMethod of: aClass on: aStream
  264. aStream
  265. nextPutAll: 'smalltalk.addMethod(';lf;
  266. nextPutAll: aMethod selector asSelector asJavascript, ',';lf;
  267. nextPutAll: 'smalltalk.method({';lf;
  268. nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;
  269. nextPutAll: 'fn: ', aMethod fn compiledSource;lf;
  270. nextPutAll: '}),';lf;
  271. nextPutAll: 'smalltalk.', (self classNameFor: aClass);
  272. nextPutAll: ');';lf;lf
  273. ! !
  274. Object subclass: #Importer
  275. instanceVariableNames: ''
  276. package: 'Compiler'!
  277. !Importer methodsFor: 'fileIn'!
  278. import: aStream
  279. | chunk result parser lastEmpty |
  280. parser := ChunkParser on: aStream.
  281. lastEmpty := false.
  282. [chunk := parser nextChunk.
  283. chunk isNil] whileFalse: [
  284. chunk isEmpty
  285. ifTrue: [lastEmpty := true]
  286. ifFalse: [
  287. result := Compiler new loadExpression: chunk.
  288. lastEmpty
  289. ifTrue: [
  290. lastEmpty := false.
  291. result scanFrom: parser]]]
  292. ! !
  293. Object subclass: #Node
  294. instanceVariableNames: 'nodes'
  295. package: 'Compiler'!
  296. !Node methodsFor: 'accessing'!
  297. addNode: aNode
  298. self nodes add: aNode
  299. !
  300. nodes
  301. ^nodes ifNil: [nodes := Array new]
  302. ! !
  303. !Node methodsFor: 'building'!
  304. nodes: aCollection
  305. nodes := aCollection
  306. ! !
  307. !Node methodsFor: 'testing'!
  308. isBlockNode
  309. ^false
  310. !
  311. isBlockSequenceNode
  312. ^false
  313. !
  314. isValueNode
  315. ^false
  316. ! !
  317. !Node methodsFor: 'visiting'!
  318. accept: aVisitor
  319. aVisitor visitNode: self
  320. ! !
  321. Node subclass: #AssignmentNode
  322. instanceVariableNames: 'left right'
  323. package: 'Compiler'!
  324. !AssignmentNode methodsFor: 'accessing'!
  325. left
  326. ^left
  327. !
  328. left: aNode
  329. left := aNode.
  330. left assigned: true
  331. !
  332. right
  333. ^right
  334. !
  335. right: aNode
  336. right := aNode
  337. ! !
  338. !AssignmentNode methodsFor: 'visiting'!
  339. accept: aVisitor
  340. aVisitor visitAssignmentNode: self
  341. ! !
  342. Node subclass: #BlockNode
  343. instanceVariableNames: 'parameters inlined'
  344. package: 'Compiler'!
  345. !BlockNode methodsFor: 'accessing'!
  346. inlined
  347. ^inlined ifNil: [false]
  348. !
  349. inlined: aBoolean
  350. inlined := aBoolean
  351. !
  352. parameters
  353. ^parameters ifNil: [parameters := Array new]
  354. !
  355. parameters: aCollection
  356. parameters := aCollection
  357. ! !
  358. !BlockNode methodsFor: 'testing'!
  359. isBlockNode
  360. ^true
  361. ! !
  362. !BlockNode methodsFor: 'visiting'!
  363. accept: aVisitor
  364. aVisitor visitBlockNode: self
  365. ! !
  366. Node subclass: #CascadeNode
  367. instanceVariableNames: 'receiver'
  368. package: 'Compiler'!
  369. !CascadeNode methodsFor: 'accessing'!
  370. receiver
  371. ^receiver
  372. !
  373. receiver: aNode
  374. receiver := aNode
  375. ! !
  376. !CascadeNode methodsFor: 'visiting'!
  377. accept: aVisitor
  378. aVisitor visitCascadeNode: self
  379. ! !
  380. Node subclass: #DynamicArrayNode
  381. instanceVariableNames: ''
  382. package: 'Compiler'!
  383. !DynamicArrayNode methodsFor: 'visiting'!
  384. accept: aVisitor
  385. aVisitor visitDynamicArrayNode: self
  386. ! !
  387. Node subclass: #DynamicDictionaryNode
  388. instanceVariableNames: ''
  389. package: 'Compiler'!
  390. !DynamicDictionaryNode methodsFor: 'visiting'!
  391. accept: aVisitor
  392. aVisitor visitDynamicDictionaryNode: self
  393. ! !
  394. Node subclass: #JSStatementNode
  395. instanceVariableNames: 'source'
  396. package: 'Compiler'!
  397. !JSStatementNode methodsFor: 'accessing'!
  398. source
  399. ^source ifNil: ['']
  400. !
  401. source: aString
  402. source := aString
  403. ! !
  404. !JSStatementNode methodsFor: 'visiting'!
  405. accept: aVisitor
  406. aVisitor visitJSStatementNode: self
  407. ! !
  408. Node subclass: #MethodNode
  409. instanceVariableNames: 'selector arguments source'
  410. package: 'Compiler'!
  411. !MethodNode methodsFor: 'accessing'!
  412. arguments
  413. ^arguments ifNil: [#()]
  414. !
  415. arguments: aCollection
  416. arguments := aCollection
  417. !
  418. selector
  419. ^selector
  420. !
  421. selector: aString
  422. selector := aString
  423. !
  424. source
  425. ^source
  426. !
  427. source: aString
  428. source := aString
  429. ! !
  430. !MethodNode methodsFor: 'visiting'!
  431. accept: aVisitor
  432. aVisitor visitMethodNode: self
  433. ! !
  434. Node subclass: #ReturnNode
  435. instanceVariableNames: ''
  436. package: 'Compiler'!
  437. !ReturnNode methodsFor: 'visiting'!
  438. accept: aVisitor
  439. aVisitor visitReturnNode: self
  440. ! !
  441. Node subclass: #SendNode
  442. instanceVariableNames: 'selector arguments receiver'
  443. package: 'Compiler'!
  444. !SendNode methodsFor: 'accessing'!
  445. arguments
  446. ^arguments ifNil: [arguments := #()]
  447. !
  448. arguments: aCollection
  449. arguments := aCollection
  450. !
  451. cascadeNodeWithMessages: aCollection
  452. | first |
  453. first := SendNode new
  454. selector: self selector;
  455. arguments: self arguments;
  456. yourself.
  457. ^CascadeNode new
  458. receiver: self receiver;
  459. nodes: (Array with: first), aCollection;
  460. yourself
  461. !
  462. receiver
  463. ^receiver
  464. !
  465. receiver: aNode
  466. receiver := aNode
  467. !
  468. selector
  469. ^selector
  470. !
  471. selector: aString
  472. selector := aString
  473. !
  474. valueForReceiver: anObject
  475. ^SendNode new
  476. receiver: (self receiver
  477. ifNil: [anObject]
  478. ifNotNil: [self receiver valueForReceiver: anObject]);
  479. selector: self selector;
  480. arguments: self arguments;
  481. yourself
  482. ! !
  483. !SendNode methodsFor: 'visiting'!
  484. accept: aVisitor
  485. aVisitor visitSendNode: self
  486. ! !
  487. Node subclass: #SequenceNode
  488. instanceVariableNames: 'temps'
  489. package: 'Compiler'!
  490. !SequenceNode methodsFor: 'accessing'!
  491. temps
  492. ^temps ifNil: [#()]
  493. !
  494. temps: aCollection
  495. temps := aCollection
  496. ! !
  497. !SequenceNode methodsFor: 'testing'!
  498. asBlockSequenceNode
  499. ^BlockSequenceNode new
  500. nodes: self nodes;
  501. temps: self temps;
  502. yourself
  503. ! !
  504. !SequenceNode methodsFor: 'visiting'!
  505. accept: aVisitor
  506. aVisitor visitSequenceNode: self
  507. ! !
  508. SequenceNode subclass: #BlockSequenceNode
  509. instanceVariableNames: ''
  510. package: 'Compiler'!
  511. !BlockSequenceNode methodsFor: 'testing'!
  512. isBlockSequenceNode
  513. ^true
  514. ! !
  515. !BlockSequenceNode methodsFor: 'visiting'!
  516. accept: aVisitor
  517. aVisitor visitBlockSequenceNode: self
  518. ! !
  519. Node subclass: #ValueNode
  520. instanceVariableNames: 'value'
  521. package: 'Compiler'!
  522. !ValueNode methodsFor: 'accessing'!
  523. value
  524. ^value
  525. !
  526. value: anObject
  527. value := anObject
  528. ! !
  529. !ValueNode methodsFor: 'testing'!
  530. isValueNode
  531. ^true
  532. ! !
  533. !ValueNode methodsFor: 'visiting'!
  534. accept: aVisitor
  535. aVisitor visitValueNode: self
  536. ! !
  537. ValueNode subclass: #VariableNode
  538. instanceVariableNames: 'assigned'
  539. package: 'Compiler'!
  540. !VariableNode methodsFor: 'accessing'!
  541. assigned
  542. ^assigned ifNil: [false]
  543. !
  544. assigned: aBoolean
  545. assigned := aBoolean
  546. ! !
  547. !VariableNode methodsFor: 'visiting'!
  548. accept: aVisitor
  549. aVisitor visitVariableNode: self
  550. ! !
  551. VariableNode subclass: #ClassReferenceNode
  552. instanceVariableNames: ''
  553. package: 'Compiler'!
  554. !ClassReferenceNode methodsFor: 'visiting'!
  555. accept: aVisitor
  556. aVisitor visitClassReferenceNode: self
  557. ! !
  558. Object subclass: #NodeVisitor
  559. instanceVariableNames: ''
  560. package: 'Compiler'!
  561. !NodeVisitor methodsFor: 'visiting'!
  562. visit: aNode
  563. aNode accept: self
  564. !
  565. visitAssignmentNode: aNode
  566. self visitNode: aNode
  567. !
  568. visitBlockNode: aNode
  569. self visitNode: aNode
  570. !
  571. visitBlockSequenceNode: aNode
  572. self visitNode: aNode
  573. !
  574. visitCascadeNode: aNode
  575. self visitNode: aNode
  576. !
  577. visitClassReferenceNode: aNode
  578. self visitNode: aNode
  579. !
  580. visitDynamicArrayNode: aNode
  581. self visitNode: aNode
  582. !
  583. visitDynamicDictionaryNode: aNode
  584. self visitNode: aNode
  585. !
  586. visitJSStatementNode: aNode
  587. self visitNode: aNode
  588. !
  589. visitMethodNode: aNode
  590. self visitNode: aNode
  591. !
  592. visitNode: aNode
  593. !
  594. visitReturnNode: aNode
  595. self visitNode: aNode
  596. !
  597. visitSendNode: aNode
  598. self visitNode: aNode
  599. !
  600. visitSequenceNode: aNode
  601. self visitNode: aNode
  602. !
  603. visitValueNode: aNode
  604. self visitNode: aNode
  605. !
  606. visitVariableNode: aNode
  607. self visitNode: aNode
  608. ! !
  609. NodeVisitor subclass: #Compiler
  610. instanceVariableNames: 'stream nestedBlocks earlyReturn currentClass currentSelector unknownVariables tempVariables messageSends referencedClasses classReferenced source argVariables'
  611. package: 'Compiler'!
  612. !Compiler methodsFor: 'accessing'!
  613. argVariables
  614. ^argVariables copy
  615. !
  616. classNameFor: aClass
  617. ^aClass isMetaclass
  618. ifTrue: [aClass instanceClass name, '.klass']
  619. ifFalse: [
  620. aClass isNil
  621. ifTrue: ['nil']
  622. ifFalse: [aClass name]]
  623. !
  624. currentClass
  625. ^currentClass
  626. !
  627. currentClass: aClass
  628. currentClass := aClass
  629. !
  630. knownVariables
  631. ^self pseudoVariables
  632. addAll: self tempVariables;
  633. addAll: self argVariables;
  634. yourself
  635. !
  636. parser
  637. ^SmalltalkParser new
  638. !
  639. pseudoVariables
  640. ^#('self' 'super' 'true' 'false' 'nil' 'thisContext')
  641. !
  642. safeVariableNameFor: aString
  643. ^(Smalltalk current reservedWords includes: aString)
  644. ifTrue: [aString, '_']
  645. ifFalse: [aString]
  646. !
  647. source
  648. ^source ifNil: ['']
  649. !
  650. source: aString
  651. source := aString
  652. !
  653. tempVariables
  654. ^tempVariables copy
  655. !
  656. unknownVariables
  657. ^unknownVariables copy
  658. ! !
  659. !Compiler methodsFor: 'compiling'!
  660. compile: aString
  661. ^self compileNode: (self parse: aString)
  662. !
  663. compile: aString forClass: aClass
  664. self currentClass: aClass.
  665. self source: aString.
  666. ^self compile: aString
  667. !
  668. compileExpression: aString
  669. self currentClass: DoIt.
  670. self source: 'doIt ^[', aString, '] value'.
  671. ^self compileNode: (self parse: self source)
  672. !
  673. compileNode: aNode
  674. stream := '' writeStream.
  675. self visit: aNode.
  676. ^stream contents
  677. !
  678. eval: aString
  679. <return eval(aString)>
  680. !
  681. load: aString forClass: aClass
  682. | compiled |
  683. compiled := self eval: (self compile: aString forClass: aClass).
  684. self setupClass: aClass.
  685. ^compiled
  686. !
  687. loadExpression: aString
  688. | result |
  689. DoIt addCompiledMethod: (self eval: (self compileExpression: aString)).
  690. result := DoIt new doIt.
  691. DoIt removeCompiledMethod: (DoIt methodDictionary at: 'doIt').
  692. ^result
  693. !
  694. parse: aString
  695. ^Smalltalk current parse: aString
  696. !
  697. parseExpression: aString
  698. ^self parse: 'doIt ^[', aString, '] value'
  699. !
  700. recompile: aClass
  701. aClass methodDictionary do: [:each || method |
  702. method := self load: each source forClass: aClass.
  703. method category: each category.
  704. aClass addCompiledMethod: method].
  705. aClass isMetaclass ifFalse: [self recompile: aClass class]
  706. !
  707. recompileAll
  708. Smalltalk current classes do: [:each |
  709. Transcript show: each; cr.
  710. [self recompile: each] valueWithTimeout: 100]
  711. !
  712. setupClass: aClass
  713. <smalltalk.init(aClass)>
  714. ! !
  715. !Compiler methodsFor: 'initialization'!
  716. initialize
  717. super initialize.
  718. stream := '' writeStream.
  719. unknownVariables := #().
  720. tempVariables := #().
  721. argVariables := #().
  722. messageSends := #().
  723. classReferenced := #()
  724. ! !
  725. !Compiler methodsFor: 'optimizations'!
  726. checkClass: aClassName for: receiver
  727. stream nextPutAll: '((($receiver = ', receiver, ').klass === smalltalk.', aClassName, ') ? '
  728. !
  729. inline: aSelector receiver: receiver argumentNodes: aCollection
  730. | inlined |
  731. inlined := false.
  732. "-- Booleans --"
  733. (aSelector = 'ifFalse:') ifTrue: [
  734. aCollection first isBlockNode ifTrue: [
  735. self checkClass: 'Boolean' for: receiver.
  736. stream nextPutAll: '(!! $receiver ? '.
  737. self visit: aCollection first.
  738. stream nextPutAll: '() : nil)'.
  739. inlined := true]].
  740. (aSelector = 'ifTrue:') ifTrue: [
  741. aCollection first isBlockNode ifTrue: [
  742. self checkClass: 'Boolean' for: receiver.
  743. stream nextPutAll: '($receiver ? '.
  744. self visit: aCollection first.
  745. stream nextPutAll: '() : nil)'.
  746. inlined := true]].
  747. (aSelector = 'ifTrue:ifFalse:') ifTrue: [
  748. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  749. self checkClass: 'Boolean' for: receiver.
  750. stream nextPutAll: '($receiver ? '.
  751. self visit: aCollection first.
  752. stream nextPutAll: '() : '.
  753. self visit: aCollection second.
  754. stream nextPutAll: '())'.
  755. inlined := true]].
  756. (aSelector = 'ifFalse:ifTrue:') ifTrue: [
  757. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  758. self checkClass: 'Boolean' for: receiver.
  759. stream nextPutAll: '(!! $receiver ? '.
  760. self visit: aCollection first.
  761. stream nextPutAll: '() : '.
  762. self visit: aCollection second.
  763. stream nextPutAll: '())'.
  764. inlined := true]].
  765. "-- Numbers --"
  766. (aSelector = '<') ifTrue: [
  767. self checkClass: 'Number' for: receiver.
  768. stream nextPutAll: '$receiver <'.
  769. self visit: aCollection first.
  770. inlined := true].
  771. (aSelector = '<=') ifTrue: [
  772. self checkClass: 'Number' for: receiver.
  773. stream nextPutAll: '$receiver <='.
  774. self visit: aCollection first.
  775. inlined := true].
  776. (aSelector = '>') ifTrue: [
  777. self checkClass: 'Number' for: receiver.
  778. stream nextPutAll: '$receiver >'.
  779. self visit: aCollection first.
  780. inlined := true].
  781. (aSelector = '>=') ifTrue: [
  782. self checkClass: 'Number' for: receiver.
  783. stream nextPutAll: '$receiver >='.
  784. self visit: aCollection first.
  785. inlined := true].
  786. (aSelector = '+') ifTrue: [
  787. self checkClass: 'Number' for: receiver.
  788. stream nextPutAll: '$receiver +'.
  789. self visit: aCollection first.
  790. inlined := true].
  791. (aSelector = '-') ifTrue: [
  792. self checkClass: 'Number' for: receiver.
  793. stream nextPutAll: '$receiver -'.
  794. self visit: aCollection first.
  795. inlined := true].
  796. (aSelector = '*') ifTrue: [
  797. self checkClass: 'Number' for: receiver.
  798. stream nextPutAll: '$receiver *'.
  799. self visit: aCollection first.
  800. inlined := true].
  801. (aSelector = '/') ifTrue: [
  802. self checkClass: 'Number' for: receiver.
  803. stream nextPutAll: '$receiver /'.
  804. self visit: aCollection first.
  805. inlined := true].
  806. ^inlined
  807. !
  808. inlineLiteral: aSelector receiverNode: anObject argumentNodes: aCollection
  809. | inlined |
  810. inlined := false.
  811. "-- BlockClosures --"
  812. (aSelector = 'whileTrue:') ifTrue: [
  813. (anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
  814. stream nextPutAll: '(function(){while('.
  815. self visit: anObject.
  816. stream nextPutAll: '()) {'.
  817. self visit: aCollection first.
  818. stream nextPutAll: '()}})()'.
  819. inlined := true]].
  820. (aSelector = 'whileFalse:') ifTrue: [
  821. (anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
  822. stream nextPutAll: '(function(){while(!!'.
  823. self visit: anObject.
  824. stream nextPutAll: '()) {'.
  825. self visit: aCollection first.
  826. stream nextPutAll: '()}})()'.
  827. inlined := true]].
  828. (aSelector = 'whileTrue') ifTrue: [
  829. anObject isBlockNode ifTrue: [
  830. stream nextPutAll: '(function(){while('.
  831. self visit: anObject.
  832. stream nextPutAll: '()) {}})()'.
  833. inlined := true]].
  834. (aSelector = 'whileFalse') ifTrue: [
  835. anObject isBlockNode ifTrue: [
  836. stream nextPutAll: '(function(){while(!!'.
  837. self visit: anObject.
  838. stream nextPutAll: '()) {}})()'.
  839. inlined := true]].
  840. "-- Numbers --"
  841. (aSelector = '+') ifTrue: [
  842. (self isNode: anObject ofClass: Number) ifTrue: [
  843. self visit: anObject.
  844. stream nextPutAll: ' + '.
  845. self visit: aCollection first.
  846. inlined := true]].
  847. (aSelector = '-') ifTrue: [
  848. (self isNode: anObject ofClass: Number) ifTrue: [
  849. self visit: anObject.
  850. stream nextPutAll: ' - '.
  851. self visit: aCollection first.
  852. inlined := true]].
  853. (aSelector = '*') ifTrue: [
  854. (self isNode: anObject ofClass: Number) ifTrue: [
  855. self visit: anObject.
  856. stream nextPutAll: ' * '.
  857. self visit: aCollection first.
  858. inlined := true]].
  859. (aSelector = '/') ifTrue: [
  860. (self isNode: anObject ofClass: Number) ifTrue: [
  861. self visit: anObject.
  862. stream nextPutAll: ' / '.
  863. self visit: aCollection first.
  864. inlined := true]].
  865. (aSelector = '<') ifTrue: [
  866. (self isNode: anObject ofClass: Number) ifTrue: [
  867. self visit: anObject.
  868. stream nextPutAll: ' < '.
  869. self visit: aCollection first.
  870. inlined := true]].
  871. (aSelector = '<=') ifTrue: [
  872. (self isNode: anObject ofClass: Number) ifTrue: [
  873. self visit: anObject.
  874. stream nextPutAll: ' <= '.
  875. self visit: aCollection first.
  876. inlined := true]].
  877. (aSelector = '>') ifTrue: [
  878. (self isNode: anObject ofClass: Number) ifTrue: [
  879. self visit: anObject.
  880. stream nextPutAll: ' > '.
  881. self visit: aCollection first.
  882. inlined := true]].
  883. (aSelector = '>=') ifTrue: [
  884. (self isNode: anObject ofClass: Number) ifTrue: [
  885. self visit: anObject.
  886. stream nextPutAll: ' >= '.
  887. self visit: aCollection first.
  888. inlined := true]].
  889. "-- UndefinedObject --"
  890. (aSelector = 'ifNil:') ifTrue: [
  891. aCollection first isBlockNode ifTrue: [
  892. stream nextPutAll: '(($receiver = '.
  893. self visit: anObject.
  894. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  895. self visit: aCollection first.
  896. stream nextPutAll: '() : $receiver'.
  897. inlined := true]].
  898. (aSelector = 'ifNotNil:') ifTrue: [
  899. aCollection first isBlockNode ifTrue: [
  900. stream nextPutAll: '(($receiver = '.
  901. self visit: anObject.
  902. stream nextPutAll: ') !!= nil && $receiver !!= undefined) ? '.
  903. self visit: aCollection first.
  904. stream nextPutAll: '() : nil'.
  905. inlined := true]].
  906. (aSelector = 'ifNil:ifNotNil:') ifTrue: [
  907. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  908. stream nextPutAll: '(($receiver = '.
  909. self visit: anObject.
  910. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  911. self visit: aCollection first.
  912. stream nextPutAll: '() : '.
  913. self visit: aCollection second.
  914. stream nextPutAll: '()'.
  915. inlined := true]].
  916. (aSelector = 'ifNotNil:ifNil:') ifTrue: [
  917. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  918. stream nextPutAll: '(($receiver = '.
  919. self visit: anObject.
  920. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  921. self visit: aCollection second.
  922. stream nextPutAll: '() : '.
  923. self visit: aCollection first.
  924. stream nextPutAll: '()'.
  925. inlined := true]].
  926. ^inlined
  927. !
  928. isNode: aNode ofClass: aClass
  929. ^aNode isValueNode and: [
  930. aNode value class = aClass or: [
  931. aNode value = 'self' and: [self currentClass = aClass]]]
  932. ! !
  933. !Compiler methodsFor: 'testing'!
  934. performOptimizations
  935. ^self class performOptimizations
  936. ! !
  937. !Compiler methodsFor: 'visiting'!
  938. send: aSelector to: aReceiver arguments: aCollection superSend: aBoolean
  939. ^String streamContents: [:str || tmp |
  940. tmp := stream.
  941. str nextPutAll: 'smalltalk.send('.
  942. str nextPutAll: aReceiver.
  943. str nextPutAll: ', "', aSelector asSelector, '", ['.
  944. stream := str.
  945. aCollection
  946. do: [:each | self visit: each]
  947. separatedBy: [stream nextPutAll: ', '].
  948. stream := tmp.
  949. str nextPutAll: ']'.
  950. aBoolean ifTrue: [
  951. str nextPutAll: ', smalltalk.', (self classNameFor: self currentClass superclass)].
  952. str nextPutAll: ')']
  953. !
  954. visit: aNode
  955. aNode accept: self
  956. !
  957. visitAssignmentNode: aNode
  958. stream nextPutAll: '('.
  959. self visit: aNode left.
  960. stream nextPutAll: '='.
  961. self visit: aNode right.
  962. stream nextPutAll: ')'
  963. !
  964. visitBlockNode: aNode
  965. stream nextPutAll: '(function('.
  966. aNode parameters
  967. do: [:each |
  968. tempVariables add: each.
  969. stream nextPutAll: each]
  970. separatedBy: [stream nextPutAll: ', '].
  971. stream nextPutAll: '){'.
  972. aNode nodes do: [:each | self visit: each].
  973. stream nextPutAll: '})'
  974. !
  975. visitBlockSequenceNode: aNode
  976. | index |
  977. nestedBlocks := nestedBlocks + 1.
  978. aNode nodes isEmpty
  979. ifTrue: [
  980. stream nextPutAll: 'return nil;']
  981. ifFalse: [
  982. aNode temps do: [:each | | temp |
  983. temp := self safeVariableNameFor: each.
  984. tempVariables add: temp.
  985. stream nextPutAll: 'var ', temp, '=nil;'; lf].
  986. index := 0.
  987. aNode nodes do: [:each |
  988. index := index + 1.
  989. index = aNode nodes size ifTrue: [
  990. stream nextPutAll: 'return '].
  991. self visit: each.
  992. stream nextPutAll: ';']].
  993. nestedBlocks := nestedBlocks - 1
  994. !
  995. visitCascadeNode: aNode
  996. | index |
  997. index := 0.
  998. (tempVariables includes: '$rec') ifFalse: [
  999. tempVariables add: '$rec'].
  1000. stream nextPutAll: '(function($rec){'.
  1001. aNode nodes do: [:each |
  1002. index := index + 1.
  1003. index = aNode nodes size ifTrue: [
  1004. stream nextPutAll: 'return '].
  1005. each receiver: (VariableNode new value: '$rec').
  1006. self visit: each.
  1007. stream nextPutAll: ';'].
  1008. stream nextPutAll: '})('.
  1009. self visit: aNode receiver.
  1010. stream nextPutAll: ')'
  1011. !
  1012. visitClassReferenceNode: aNode
  1013. (referencedClasses includes: aNode value) ifFalse: [
  1014. referencedClasses add: aNode value].
  1015. stream nextPutAll: '(smalltalk.', aNode value, ' || ', aNode value, ')'
  1016. !
  1017. visitDynamicArrayNode: aNode
  1018. stream nextPutAll: '['.
  1019. aNode nodes
  1020. do: [:each | self visit: each]
  1021. separatedBy: [stream nextPutAll: ','].
  1022. stream nextPutAll: ']'
  1023. !
  1024. visitDynamicDictionaryNode: aNode
  1025. stream nextPutAll: 'smalltalk.HashedCollection._fromPairs_(['.
  1026. aNode nodes
  1027. do: [:each | self visit: each]
  1028. separatedBy: [stream nextPutAll: ','].
  1029. stream nextPutAll: '])'
  1030. !
  1031. visitFailure: aFailure
  1032. self error: aFailure asString
  1033. !
  1034. visitJSStatementNode: aNode
  1035. stream nextPutAll: (aNode source replace: '>>' with: '>')
  1036. !
  1037. visitMethodNode: aNode
  1038. | str currentSelector |
  1039. currentSelector := aNode selector asSelector.
  1040. nestedBlocks := 0.
  1041. earlyReturn := false.
  1042. messageSends := #().
  1043. referencedClasses := #().
  1044. unknownVariables := #().
  1045. tempVariables := #().
  1046. argVariables := #().
  1047. stream
  1048. nextPutAll: 'smalltalk.method({'; lf;
  1049. nextPutAll: 'selector: "', aNode selector, '",'; lf.
  1050. stream nextPutAll: 'source: ', self source asJavascript, ',';lf.
  1051. stream nextPutAll: 'fn: function('.
  1052. aNode arguments
  1053. do: [:each |
  1054. argVariables add: each.
  1055. stream nextPutAll: each]
  1056. separatedBy: [stream nextPutAll: ', '].
  1057. stream
  1058. nextPutAll: '){'; lf;
  1059. nextPutAll: 'var self=this;'; lf.
  1060. str := stream.
  1061. stream := '' writeStream.
  1062. aNode nodes do: [:each |
  1063. self visit: each].
  1064. earlyReturn ifTrue: [
  1065. str nextPutAll: 'var $early={};'; lf; nextPutAll: 'try{'].
  1066. str nextPutAll: stream contents.
  1067. stream := str.
  1068. stream
  1069. lf;
  1070. nextPutAll: 'return self;'.
  1071. earlyReturn ifTrue: [
  1072. stream lf; nextPutAll: '} catch(e) {if(e===$early)return e(); throw e}'].
  1073. stream nextPutAll: '}'.
  1074. stream
  1075. nextPutAll: ',', String lf, 'messageSends: ';
  1076. nextPutAll: messageSends asJavascript, ','; lf;
  1077. nextPutAll: 'args: ', argVariables asJavascript, ','; lf;
  1078. nextPutAll: 'referencedClasses: ['.
  1079. referencedClasses
  1080. do: [:each | stream nextPutAll: each printString]
  1081. separatedBy: [stream nextPutAll: ','].
  1082. stream nextPutAll: ']'.
  1083. stream nextPutAll: '})'
  1084. !
  1085. visitReturnNode: aNode
  1086. nestedBlocks > 0 ifTrue: [
  1087. earlyReturn := true].
  1088. nestedBlocks > 0
  1089. ifTrue: [
  1090. stream
  1091. nextPutAll: '(function(){throw $early=function(){return ']
  1092. ifFalse: [stream nextPutAll: 'return '].
  1093. aNode nodes do: [:each |
  1094. self visit: each].
  1095. nestedBlocks > 0 ifTrue: [
  1096. stream nextPutAll: '}})()']
  1097. !
  1098. visitSendNode: aNode
  1099. | str receiver superSend inlined |
  1100. str := stream.
  1101. (messageSends includes: aNode selector) ifFalse: [
  1102. messageSends add: aNode selector].
  1103. stream := '' writeStream.
  1104. self visit: aNode receiver.
  1105. superSend := stream contents = 'super'.
  1106. receiver := superSend ifTrue: ['self'] ifFalse: [stream contents].
  1107. stream := str.
  1108. self performOptimizations
  1109. ifTrue: [
  1110. (self inlineLiteral: aNode selector receiverNode: aNode receiver argumentNodes: aNode arguments) ifFalse: [
  1111. (self inline: aNode selector receiver: receiver argumentNodes: aNode arguments)
  1112. ifTrue: [stream nextPutAll: ' : ', (self send: aNode selector to: '$receiver' arguments: aNode arguments superSend: superSend), ')']
  1113. ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]]]
  1114. ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]
  1115. !
  1116. visitSequenceNode: aNode
  1117. aNode temps do: [:each || temp |
  1118. temp := self safeVariableNameFor: each.
  1119. tempVariables add: temp.
  1120. stream nextPutAll: 'var ', temp, '=nil;'; lf].
  1121. aNode nodes do: [:each |
  1122. self visit: each.
  1123. stream nextPutAll: ';']
  1124. separatedBy: [stream lf]
  1125. !
  1126. visitValueNode: aNode
  1127. stream nextPutAll: aNode value asJavascript
  1128. !
  1129. visitVariableNode: aNode
  1130. | varName |
  1131. (self currentClass allInstanceVariableNames includes: aNode value)
  1132. ifTrue: [stream nextPutAll: 'self[''@', aNode value, ''']']
  1133. ifFalse: [
  1134. varName := self safeVariableNameFor: aNode value.
  1135. (self knownVariables includes: varName)
  1136. ifFalse: [
  1137. unknownVariables add: aNode value.
  1138. aNode assigned
  1139. ifTrue: [stream nextPutAll: varName]
  1140. ifFalse: [stream nextPutAll: '(typeof ', varName, ' == ''undefined'' ? nil : ', varName, ')']]
  1141. ifTrue: [
  1142. aNode value = 'thisContext'
  1143. ifTrue: [stream nextPutAll: '(smalltalk.getThisContext())']
  1144. ifFalse: [stream nextPutAll: varName]]]
  1145. ! !
  1146. Compiler class instanceVariableNames: 'performOptimizations'!
  1147. !Compiler class methodsFor: 'accessing'!
  1148. performOptimizations
  1149. ^performOptimizations ifNil: [true]
  1150. !
  1151. performOptimizations: aBoolean
  1152. performOptimizations := aBoolean
  1153. ! !
  1154. !Compiler class methodsFor: 'compiling'!
  1155. recompile: aClass
  1156. aClass methodDictionary do: [:each || method |
  1157. method := self new load: each source forClass: aClass.
  1158. method category: each category.
  1159. aClass addCompiledMethod: method].
  1160. aClass isMetaclass ifFalse: [self recompile: aClass class]
  1161. !
  1162. recompileAll
  1163. Smalltalk current classes do: [:each |
  1164. self recompile: each]
  1165. ! !