Compiler.st 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 evaluateExpression: 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: #AbstractCompiler
  610. instanceVariableNames: 'currentClass source'
  611. package: 'Compiler'!
  612. !AbstractCompiler methodsFor: 'accessing'!
  613. classNameFor: aClass
  614. ^aClass isMetaclass
  615. ifTrue: [aClass instanceClass name, '.klass']
  616. ifFalse: [
  617. aClass isNil
  618. ifTrue: ['nil']
  619. ifFalse: [aClass name]]
  620. !
  621. currentClass
  622. ^currentClass
  623. !
  624. currentClass: aClass
  625. currentClass := aClass
  626. !
  627. pseudoVariables
  628. ^#('self' 'super' 'true' 'false' 'nil' 'thisContext')
  629. !
  630. safeVariableNameFor: aString
  631. ^(Smalltalk current reservedWords includes: aString)
  632. ifTrue: [aString, '_']
  633. ifFalse: [aString]
  634. !
  635. source
  636. ^source ifNil: ['']
  637. !
  638. source: aString
  639. source := aString
  640. ! !
  641. !AbstractCompiler methodsFor: 'compiling'!
  642. compile: aString
  643. ^self compileNode: (self parse: aString)
  644. !
  645. compile: aString forClass: aClass
  646. self currentClass: aClass.
  647. self source: aString.
  648. ^self compile: aString
  649. !
  650. compileExpression: aString
  651. self currentClass: DoIt.
  652. self source: 'doIt ^[', aString, '] value'.
  653. ^self compileNode: (self parse: self source)
  654. !
  655. compileNode: aNode
  656. self subclassResponsibility
  657. !
  658. eval: aString
  659. <return eval(aString)>
  660. !
  661. evaluateExpression: aString
  662. "Unlike #eval: evaluate a Smalltalk expression and answer the returned object"
  663. | result |
  664. DoIt addCompiledMethod: (self eval: (self compileExpression: aString)).
  665. result := DoIt new doIt.
  666. DoIt removeCompiledMethod: (DoIt methodDictionary at: 'doIt').
  667. ^result
  668. !
  669. install: aString forClass: aBehavior category: anotherString
  670. | compiled |
  671. compiled := self eval: (self compile: aString forClass: aBehavior).
  672. compiled category: anotherString.
  673. aBehavior addCompiledMethod: compiled.
  674. ^compiled
  675. !
  676. parse: aString
  677. ^Smalltalk current parse: aString
  678. !
  679. parseExpression: aString
  680. ^self parse: 'doIt ^[', aString, '] value'
  681. !
  682. recompile: aClass
  683. aClass methodDictionary do: [:each |
  684. self install: each source forClass: aClass category: each category].
  685. self setupClass: aClass.
  686. aClass isMetaclass ifFalse: [self recompile: aClass class]
  687. !
  688. recompileAll
  689. Smalltalk current classes do: [:each |
  690. Transcript show: each; cr.
  691. [self recompile: each] valueWithTimeout: 100]
  692. !
  693. setupClass: aClass
  694. <smalltalk.init(aClass)>
  695. ! !
  696. !AbstractCompiler class methodsFor: 'compiling'!
  697. recompile: aClass
  698. self new recompile: aClass
  699. !
  700. recompileAll
  701. Smalltalk current classes do: [:each |
  702. self recompile: each]
  703. ! !
  704. AbstractCompiler subclass: #Compiler
  705. instanceVariableNames: 'stream nestedBlocks earlyReturn currentSelector unknownVariables tempVariables messageSends referencedClasses classReferenced argVariables'
  706. package: 'Compiler'!
  707. !Compiler methodsFor: 'accessing'!
  708. argVariables
  709. ^argVariables copy
  710. !
  711. knownVariables
  712. ^self pseudoVariables
  713. addAll: self tempVariables;
  714. addAll: self argVariables;
  715. yourself
  716. !
  717. tempVariables
  718. ^tempVariables copy
  719. !
  720. unknownVariables
  721. ^unknownVariables copy
  722. ! !
  723. !Compiler methodsFor: 'compiling'!
  724. compileNode: aNode
  725. stream := '' writeStream.
  726. self visit: aNode.
  727. ^stream contents
  728. ! !
  729. !Compiler methodsFor: 'initialization'!
  730. initialize
  731. super initialize.
  732. stream := '' writeStream.
  733. unknownVariables := #().
  734. tempVariables := #().
  735. argVariables := #().
  736. messageSends := #().
  737. classReferenced := #()
  738. ! !
  739. !Compiler methodsFor: 'optimizations'!
  740. checkClass: aClassName for: receiver
  741. stream nextPutAll: '((($receiver = ', receiver, ').klass === smalltalk.', aClassName, ') ? '
  742. !
  743. inline: aSelector receiver: receiver argumentNodes: aCollection
  744. | inlined |
  745. inlined := false.
  746. "-- Booleans --"
  747. (aSelector = 'ifFalse:') ifTrue: [
  748. aCollection first isBlockNode ifTrue: [
  749. self checkClass: 'Boolean' for: receiver.
  750. stream nextPutAll: '(!! $receiver ? '.
  751. self visit: aCollection first.
  752. stream nextPutAll: '() : nil)'.
  753. inlined := true]].
  754. (aSelector = 'ifTrue:') ifTrue: [
  755. aCollection first isBlockNode ifTrue: [
  756. self checkClass: 'Boolean' for: receiver.
  757. stream nextPutAll: '($receiver ? '.
  758. self visit: aCollection first.
  759. stream nextPutAll: '() : nil)'.
  760. inlined := true]].
  761. (aSelector = 'ifTrue:ifFalse:') ifTrue: [
  762. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  763. self checkClass: 'Boolean' for: receiver.
  764. stream nextPutAll: '($receiver ? '.
  765. self visit: aCollection first.
  766. stream nextPutAll: '() : '.
  767. self visit: aCollection second.
  768. stream nextPutAll: '())'.
  769. inlined := true]].
  770. (aSelector = 'ifFalse:ifTrue:') ifTrue: [
  771. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  772. self checkClass: 'Boolean' for: receiver.
  773. stream nextPutAll: '(!! $receiver ? '.
  774. self visit: aCollection first.
  775. stream nextPutAll: '() : '.
  776. self visit: aCollection second.
  777. stream nextPutAll: '())'.
  778. inlined := true]].
  779. "-- Numbers --"
  780. (aSelector = '<') ifTrue: [
  781. self checkClass: 'Number' for: receiver.
  782. stream nextPutAll: '$receiver <'.
  783. self visit: aCollection first.
  784. inlined := true].
  785. (aSelector = '<=') ifTrue: [
  786. self checkClass: 'Number' for: receiver.
  787. stream nextPutAll: '$receiver <='.
  788. self visit: aCollection first.
  789. inlined := true].
  790. (aSelector = '>') ifTrue: [
  791. self checkClass: 'Number' for: receiver.
  792. stream nextPutAll: '$receiver >'.
  793. self visit: aCollection first.
  794. inlined := true].
  795. (aSelector = '>=') ifTrue: [
  796. self checkClass: 'Number' for: receiver.
  797. stream nextPutAll: '$receiver >='.
  798. self visit: aCollection first.
  799. inlined := true].
  800. (aSelector = '+') ifTrue: [
  801. self checkClass: 'Number' for: receiver.
  802. stream nextPutAll: '$receiver +'.
  803. self visit: aCollection first.
  804. inlined := true].
  805. (aSelector = '-') ifTrue: [
  806. self checkClass: 'Number' for: receiver.
  807. stream nextPutAll: '$receiver -'.
  808. self visit: aCollection first.
  809. inlined := true].
  810. (aSelector = '*') ifTrue: [
  811. self checkClass: 'Number' for: receiver.
  812. stream nextPutAll: '$receiver *'.
  813. self visit: aCollection first.
  814. inlined := true].
  815. (aSelector = '/') ifTrue: [
  816. self checkClass: 'Number' for: receiver.
  817. stream nextPutAll: '$receiver /'.
  818. self visit: aCollection first.
  819. inlined := true].
  820. ^inlined
  821. !
  822. inlineLiteral: aSelector receiverNode: anObject argumentNodes: aCollection
  823. | inlined |
  824. inlined := false.
  825. "-- BlockClosures --"
  826. (aSelector = 'whileTrue:') ifTrue: [
  827. (anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
  828. stream nextPutAll: '(function(){while('.
  829. self visit: anObject.
  830. stream nextPutAll: '()) {'.
  831. self visit: aCollection first.
  832. stream nextPutAll: '()}})()'.
  833. inlined := true]].
  834. (aSelector = 'whileFalse:') ifTrue: [
  835. (anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
  836. stream nextPutAll: '(function(){while(!!'.
  837. self visit: anObject.
  838. stream nextPutAll: '()) {'.
  839. self visit: aCollection first.
  840. stream nextPutAll: '()}})()'.
  841. inlined := true]].
  842. (aSelector = 'whileTrue') ifTrue: [
  843. anObject isBlockNode ifTrue: [
  844. stream nextPutAll: '(function(){while('.
  845. self visit: anObject.
  846. stream nextPutAll: '()) {}})()'.
  847. inlined := true]].
  848. (aSelector = 'whileFalse') ifTrue: [
  849. anObject isBlockNode ifTrue: [
  850. stream nextPutAll: '(function(){while(!!'.
  851. self visit: anObject.
  852. stream nextPutAll: '()) {}})()'.
  853. inlined := true]].
  854. "-- Numbers --"
  855. (aSelector = '+') ifTrue: [
  856. (self isNode: anObject ofClass: Number) ifTrue: [
  857. self visit: anObject.
  858. stream nextPutAll: ' + '.
  859. self visit: aCollection first.
  860. inlined := true]].
  861. (aSelector = '-') ifTrue: [
  862. (self isNode: anObject ofClass: Number) ifTrue: [
  863. self visit: anObject.
  864. stream nextPutAll: ' - '.
  865. self visit: aCollection first.
  866. inlined := true]].
  867. (aSelector = '*') ifTrue: [
  868. (self isNode: anObject ofClass: Number) ifTrue: [
  869. self visit: anObject.
  870. stream nextPutAll: ' * '.
  871. self visit: aCollection first.
  872. inlined := true]].
  873. (aSelector = '/') ifTrue: [
  874. (self isNode: anObject ofClass: Number) ifTrue: [
  875. self visit: anObject.
  876. stream nextPutAll: ' / '.
  877. self visit: aCollection first.
  878. inlined := true]].
  879. (aSelector = '<') ifTrue: [
  880. (self isNode: anObject ofClass: Number) ifTrue: [
  881. self visit: anObject.
  882. stream nextPutAll: ' < '.
  883. self visit: aCollection first.
  884. inlined := true]].
  885. (aSelector = '<=') ifTrue: [
  886. (self isNode: anObject ofClass: Number) ifTrue: [
  887. self visit: anObject.
  888. stream nextPutAll: ' <= '.
  889. self visit: aCollection first.
  890. inlined := true]].
  891. (aSelector = '>') ifTrue: [
  892. (self isNode: anObject ofClass: Number) ifTrue: [
  893. self visit: anObject.
  894. stream nextPutAll: ' > '.
  895. self visit: aCollection first.
  896. inlined := true]].
  897. (aSelector = '>=') ifTrue: [
  898. (self isNode: anObject ofClass: Number) ifTrue: [
  899. self visit: anObject.
  900. stream nextPutAll: ' >= '.
  901. self visit: aCollection first.
  902. inlined := true]].
  903. "-- UndefinedObject --"
  904. (aSelector = 'ifNil:') ifTrue: [
  905. aCollection first isBlockNode ifTrue: [
  906. stream nextPutAll: '(($receiver = '.
  907. self visit: anObject.
  908. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  909. self visit: aCollection first.
  910. stream nextPutAll: '() : $receiver'.
  911. inlined := true]].
  912. (aSelector = 'ifNotNil:') ifTrue: [
  913. aCollection first isBlockNode ifTrue: [
  914. stream nextPutAll: '(($receiver = '.
  915. self visit: anObject.
  916. stream nextPutAll: ') !!= nil && $receiver !!= undefined) ? '.
  917. self visit: aCollection first.
  918. stream nextPutAll: '() : nil'.
  919. inlined := true]].
  920. (aSelector = 'ifNil:ifNotNil:') ifTrue: [
  921. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  922. stream nextPutAll: '(($receiver = '.
  923. self visit: anObject.
  924. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  925. self visit: aCollection first.
  926. stream nextPutAll: '() : '.
  927. self visit: aCollection second.
  928. stream nextPutAll: '()'.
  929. inlined := true]].
  930. (aSelector = 'ifNotNil:ifNil:') ifTrue: [
  931. (aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
  932. stream nextPutAll: '(($receiver = '.
  933. self visit: anObject.
  934. stream nextPutAll: ') == nil || $receiver == undefined) ? '.
  935. self visit: aCollection second.
  936. stream nextPutAll: '() : '.
  937. self visit: aCollection first.
  938. stream nextPutAll: '()'.
  939. inlined := true]].
  940. ^inlined
  941. !
  942. isNode: aNode ofClass: aClass
  943. ^aNode isValueNode and: [
  944. aNode value class = aClass or: [
  945. aNode value = 'self' and: [self currentClass = aClass]]]
  946. ! !
  947. !Compiler methodsFor: 'testing'!
  948. performOptimizations
  949. ^self class performOptimizations
  950. ! !
  951. !Compiler methodsFor: 'visiting'!
  952. send: aSelector to: aReceiver arguments: aCollection superSend: aBoolean
  953. ^String streamContents: [:str || tmp |
  954. tmp := stream.
  955. str nextPutAll: 'smalltalk.send('.
  956. str nextPutAll: aReceiver.
  957. str nextPutAll: ', "', aSelector asSelector, '", ['.
  958. stream := str.
  959. aCollection
  960. do: [:each | self visit: each]
  961. separatedBy: [stream nextPutAll: ', '].
  962. stream := tmp.
  963. str nextPutAll: ']'.
  964. aBoolean ifTrue: [
  965. str nextPutAll: ', smalltalk.', (self classNameFor: self currentClass), '.superclass || nil'].
  966. str nextPutAll: ')']
  967. !
  968. visit: aNode
  969. aNode accept: self
  970. !
  971. visitAssignmentNode: aNode
  972. stream nextPutAll: '('.
  973. self visit: aNode left.
  974. stream nextPutAll: '='.
  975. self visit: aNode right.
  976. stream nextPutAll: ')'
  977. !
  978. visitBlockNode: aNode
  979. stream nextPutAll: '(function('.
  980. aNode parameters
  981. do: [:each |
  982. tempVariables add: each.
  983. stream nextPutAll: each]
  984. separatedBy: [stream nextPutAll: ', '].
  985. stream nextPutAll: '){'.
  986. aNode nodes do: [:each | self visit: each].
  987. stream nextPutAll: '})'
  988. !
  989. visitBlockSequenceNode: aNode
  990. | index |
  991. nestedBlocks := nestedBlocks + 1.
  992. aNode nodes isEmpty
  993. ifTrue: [
  994. stream nextPutAll: 'return nil;']
  995. ifFalse: [
  996. aNode temps do: [:each | | temp |
  997. temp := self safeVariableNameFor: each.
  998. tempVariables add: temp.
  999. stream nextPutAll: 'var ', temp, '=nil;'; lf].
  1000. index := 0.
  1001. aNode nodes do: [:each |
  1002. index := index + 1.
  1003. index = aNode nodes size ifTrue: [
  1004. stream nextPutAll: 'return '].
  1005. self visit: each.
  1006. stream nextPutAll: ';']].
  1007. nestedBlocks := nestedBlocks - 1
  1008. !
  1009. visitCascadeNode: aNode
  1010. | index |
  1011. index := 0.
  1012. (tempVariables includes: '$rec') ifFalse: [
  1013. tempVariables add: '$rec'].
  1014. stream nextPutAll: '(function($rec){'.
  1015. aNode nodes do: [:each |
  1016. index := index + 1.
  1017. index = aNode nodes size ifTrue: [
  1018. stream nextPutAll: 'return '].
  1019. each receiver: (VariableNode new value: '$rec').
  1020. self visit: each.
  1021. stream nextPutAll: ';'].
  1022. stream nextPutAll: '})('.
  1023. self visit: aNode receiver.
  1024. stream nextPutAll: ')'
  1025. !
  1026. visitClassReferenceNode: aNode
  1027. (referencedClasses includes: aNode value) ifFalse: [
  1028. referencedClasses add: aNode value].
  1029. stream nextPutAll: '(smalltalk.', aNode value, ' || ', aNode value, ')'
  1030. !
  1031. visitDynamicArrayNode: aNode
  1032. stream nextPutAll: '['.
  1033. aNode nodes
  1034. do: [:each | self visit: each]
  1035. separatedBy: [stream nextPutAll: ','].
  1036. stream nextPutAll: ']'
  1037. !
  1038. visitDynamicDictionaryNode: aNode
  1039. stream nextPutAll: 'smalltalk.HashedCollection._fromPairs_(['.
  1040. aNode nodes
  1041. do: [:each | self visit: each]
  1042. separatedBy: [stream nextPutAll: ','].
  1043. stream nextPutAll: '])'
  1044. !
  1045. visitFailure: aFailure
  1046. self error: aFailure asString
  1047. !
  1048. visitJSStatementNode: aNode
  1049. stream nextPutAll: aNode source
  1050. !
  1051. visitMethodNode: aNode
  1052. | str currentSelector |
  1053. currentSelector := aNode selector asSelector.
  1054. nestedBlocks := 0.
  1055. earlyReturn := false.
  1056. messageSends := #().
  1057. referencedClasses := #().
  1058. unknownVariables := #().
  1059. tempVariables := #().
  1060. argVariables := #().
  1061. stream
  1062. nextPutAll: 'smalltalk.method({'; lf;
  1063. nextPutAll: 'selector: "', aNode selector, '",'; lf.
  1064. stream nextPutAll: 'source: ', self source asJavascript, ',';lf.
  1065. stream nextPutAll: 'fn: function('.
  1066. aNode arguments
  1067. do: [:each |
  1068. argVariables add: each.
  1069. stream nextPutAll: each]
  1070. separatedBy: [stream nextPutAll: ', '].
  1071. stream
  1072. nextPutAll: '){'; lf;
  1073. nextPutAll: 'var self=this;'; lf.
  1074. str := stream.
  1075. stream := '' writeStream.
  1076. aNode nodes do: [:each |
  1077. self visit: each].
  1078. earlyReturn ifTrue: [
  1079. str nextPutAll: 'var $early={};'; lf; nextPutAll: 'try{'].
  1080. str nextPutAll: stream contents.
  1081. stream := str.
  1082. stream
  1083. lf;
  1084. nextPutAll: 'return self;'.
  1085. earlyReturn ifTrue: [
  1086. stream lf; nextPutAll: '} catch(e) {if(e===$early)return e[0]; throw e}'].
  1087. stream nextPutAll: '}'.
  1088. stream
  1089. nextPutAll: ',', String lf, 'messageSends: ';
  1090. nextPutAll: messageSends asJavascript, ','; lf;
  1091. nextPutAll: 'args: ', argVariables asJavascript, ','; lf;
  1092. nextPutAll: 'referencedClasses: ['.
  1093. referencedClasses
  1094. do: [:each | stream nextPutAll: each printString]
  1095. separatedBy: [stream nextPutAll: ','].
  1096. stream nextPutAll: ']'.
  1097. stream nextPutAll: '})'
  1098. !
  1099. visitReturnNode: aNode
  1100. nestedBlocks > 0 ifTrue: [
  1101. earlyReturn := true].
  1102. nestedBlocks > 0
  1103. ifTrue: [
  1104. stream
  1105. nextPutAll: '(function(){throw $early=[']
  1106. ifFalse: [stream nextPutAll: 'return '].
  1107. aNode nodes do: [:each |
  1108. self visit: each].
  1109. nestedBlocks > 0 ifTrue: [
  1110. stream nextPutAll: ']})()']
  1111. !
  1112. visitSendNode: aNode
  1113. | str receiver superSend inlined |
  1114. str := stream.
  1115. (messageSends includes: aNode selector) ifFalse: [
  1116. messageSends add: aNode selector].
  1117. stream := '' writeStream.
  1118. self visit: aNode receiver.
  1119. superSend := stream contents = 'super'.
  1120. receiver := superSend ifTrue: ['self'] ifFalse: [stream contents].
  1121. stream := str.
  1122. self performOptimizations
  1123. ifTrue: [
  1124. (self inlineLiteral: aNode selector receiverNode: aNode receiver argumentNodes: aNode arguments) ifFalse: [
  1125. (self inline: aNode selector receiver: receiver argumentNodes: aNode arguments)
  1126. ifTrue: [stream nextPutAll: ' : ', (self send: aNode selector to: '$receiver' arguments: aNode arguments superSend: superSend), ')']
  1127. ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]]]
  1128. ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]
  1129. !
  1130. visitSequenceNode: aNode
  1131. aNode temps do: [:each || temp |
  1132. temp := self safeVariableNameFor: each.
  1133. tempVariables add: temp.
  1134. stream nextPutAll: 'var ', temp, '=nil;'; lf].
  1135. aNode nodes do: [:each |
  1136. self visit: each.
  1137. stream nextPutAll: ';']
  1138. separatedBy: [stream lf]
  1139. !
  1140. visitValueNode: aNode
  1141. stream nextPutAll: aNode value asJavascript
  1142. !
  1143. visitVariableNode: aNode
  1144. | varName |
  1145. (self currentClass allInstanceVariableNames includes: aNode value)
  1146. ifTrue: [stream nextPutAll: 'self[''@', aNode value, ''']']
  1147. ifFalse: [
  1148. varName := self safeVariableNameFor: aNode value.
  1149. (self knownVariables includes: varName)
  1150. ifFalse: [
  1151. unknownVariables add: aNode value.
  1152. aNode assigned
  1153. ifTrue: [stream nextPutAll: varName]
  1154. ifFalse: [stream nextPutAll: '(typeof ', varName, ' == ''undefined'' ? nil : ', varName, ')']]
  1155. ifTrue: [
  1156. aNode value = 'thisContext'
  1157. ifTrue: [stream nextPutAll: '(smalltalk.getThisContext())']
  1158. ifFalse: [stream nextPutAll: varName]]]
  1159. ! !
  1160. Compiler class instanceVariableNames: 'performOptimizations'!
  1161. !Compiler class methodsFor: 'accessing'!
  1162. performOptimizations
  1163. ^performOptimizations ifNil: [true]
  1164. !
  1165. performOptimizations: aBoolean
  1166. performOptimizations := aBoolean
  1167. ! !