Compiler-Tests.st 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. Smalltalk createPackage: 'Compiler-Tests'!
  2. TestCase subclass: #ASTMethodRunningTest
  3. slots: {#receiver. #arguments}
  4. package: 'Compiler-Tests'!
  5. !ASTMethodRunningTest methodsFor: 'accessing'!
  6. arguments
  7. ^ arguments
  8. !
  9. receiver
  10. ^ receiver
  11. ! !
  12. !ASTMethodRunningTest methodsFor: 'initialization'!
  13. setUp
  14. arguments := #().
  15. receiver := DoIt new
  16. ! !
  17. !ASTMethodRunningTest methodsFor: 'testing'!
  18. should: aString class: aClass receiver: anObject return: aResult
  19. receiver := anObject.
  20. self while: aString inClass: aClass should: [ :runBlock |
  21. self assert: runBlock value equals: aResult ]
  22. !
  23. should: aString receiver: anObject raise: anErrorClass
  24. receiver := anObject.
  25. self while: aString should: [ :runBlock |
  26. self should: runBlock raise: anErrorClass ]
  27. !
  28. should: aString receiver: anObject return: aResult
  29. receiver := anObject.
  30. self should: aString return: aResult
  31. !
  32. should: aString return: anObject
  33. self while: aString should: [ :runBlock |
  34. self assert: runBlock value equals: anObject ]
  35. ! !
  36. ASTMethodRunningTest subclass: #AbstractCompilerTest
  37. slots: {}
  38. package: 'Compiler-Tests'!
  39. !AbstractCompilerTest methodsFor: 'tests'!
  40. testAfterInliningNonLocalBlockReturnIndexSend
  41. self should: 'foo [ ^ true ifTrue: [ self class ] ] value. self class' return: DoIt.
  42. !
  43. testAfterInliningNonLocalBlockReturnSuperSend
  44. self should: 'foo [ ^ true ifTrue: [ super class ] ] value' return: DoIt.
  45. !
  46. testAssignment
  47. self should: 'foo | a | a := true ifTrue: [ 1 ]. ^ a' return: 1.
  48. self should: 'foo | a | a := false ifTrue: [ 1 ]. ^ a' return: nil.
  49. self should: 'foo | a | ^ a := true ifTrue: [ 1 ]' return: 1
  50. !
  51. testBackslashSelectors
  52. self should: '\ arg ^ 4' return: 4.
  53. self should: '\\ arg ^ 42' return: 42
  54. !
  55. testBlockReturn
  56. self should: 'foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]' return: #(2 3 4).
  57. self should: 'foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]' return: #(2 3 4).
  58. self should: 'foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]' return: #(2 1 4).
  59. !
  60. testCascades
  61. self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)
  62. !
  63. testCascadesInDynamicArray
  64. self should: 'foo | x | x := 1. ^ {x. [x:=2] value; in: [x]}' return: #(1 2)
  65. !
  66. testCascadesInDynamicDictioary
  67. self should: 'foo | x | x := 1. ^ #{''one'' -> x. ''two'' -> ([x:=2] value; in: [x])}' return: #{'one' -> 1. 'two' -> 2}
  68. !
  69. testCascadesInSend
  70. self should: 'foo | x | x := 1. ^ Array with: x with: ([x:=2] value; in: [x])' return: #(1 2)
  71. !
  72. testCascadesWithInlining
  73. self should: 'foo ^ true class; ifTrue: [ 1 ] ifFalse: [ 2 ]' return: 1.
  74. self should: 'foo ^ false class; ifTrue: [ 1 ] ifFalse: [ 2 ]' return: 2
  75. !
  76. testDynamicArrayElementsOrdered
  77. self should: 'foo
  78. | x |
  79. x := 1.
  80. ^ { x. x := 2 }
  81. ' return: #(1 2).
  82. self should: 'foo
  83. | x |
  84. x := 1.
  85. ^ { x. true ifTrue: [ x := 2 ] }
  86. ' return: #(1 2).
  87. !
  88. testDynamicDictionaryElementsOrdered
  89. self should: 'foo
  90. | x |
  91. x := ''foo''.
  92. ^ #{ x->1. ''bar''->(true ifTrue: [ 2 ]) }
  93. ' return: #{'foo'->1. 'bar'->2}.
  94. !
  95. testDynamicDictionaryWithMoreArrows
  96. self should: 'foo ^ #{1->2->3}' return: (HashedCollection with: 1->2->3)
  97. !
  98. testGlobalVar
  99. self should: 'foo ^ eval class' return: BlockClosure.
  100. self should: 'foo ^ Math cos: 0' return: 1.
  101. self should: 'foo ^ NonExistingVar' return: nil
  102. !
  103. testInnerTemporalDependentElementsOrdered
  104. self should: 'foo
  105. | x |
  106. x := Array.
  107. ^ x with: ''foo''->x with: ''bar''->(x := 2)
  108. ' return: {'foo'->Array. 'bar'->2}.
  109. self should: 'foo
  110. | x |
  111. x := Array.
  112. ^ x with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])
  113. ' return: {'foo'->Array. 'bar'->2}.
  114. self should: 'foo
  115. | x |
  116. x := 1.
  117. ^ Array with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])
  118. ' return: {'foo'->1. 'bar'->2}.
  119. self should: 'foo
  120. | x |
  121. x := 1.
  122. ^ { ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }
  123. ' return: {'foo'->1. 'bar'->2}.
  124. self should: 'foo
  125. | x |
  126. x := 1.
  127. ^ #{ ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }
  128. ' return: #{'foo'->1. 'bar'->2}.
  129. !
  130. testLexicalScope
  131. self should: 'foo | a | a := 1. [ a := 2 ] value. ^ a' return: 2
  132. !
  133. testLiterals
  134. self should: 'foo ^ 1' return: 1.
  135. self should: 'foo ^ ''hello''' return: 'hello'.
  136. self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).
  137. self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).
  138. self should: 'foo ^ true' return: true.
  139. self should: 'foo ^ false' return: false.
  140. self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.
  141. self should: 'foo ^ #hello' return: #hello.
  142. self should: 'foo ^ $h' return: 'h'.
  143. self should: 'foo ^ -123.456' return: -123.456.
  144. self should: 'foo ^ -2.5e4' return: -25000.
  145. !
  146. testLocalReturn
  147. self should: 'foo ^ 1' return: 1.
  148. self should: 'foo ^ 1 + 1' return: 2.
  149. self should: 'foo ' return: receiver.
  150. self should: 'foo self asString' return: receiver.
  151. self should: 'foo | a b | a := 1. b := 2. ^ a + b' return: 3
  152. !
  153. testMessageSends
  154. self should: 'foo ^ 1 asString' return: '1'.
  155. self should: 'foo ^ 1 + 1' return: 2.
  156. self should: 'foo ^ 1 + 2 * 3' return: 9.
  157. self should: 'foo ^ 1 to: 3' return: #(1 2 3).
  158. self should: 'foo ^ 1 to: 5 by: 2' return: #(1 3 5)
  159. !
  160. testMultipleSequences
  161. self should: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6' return: 30
  162. !
  163. testMutableLiterals
  164. "Mutable literals must be aliased in cascades.
  165. See https://lolg.it/amber/amber/issues/428"
  166. self
  167. should: 'foo ^ #( 1 2 ) at: 1 put: 3; yourself'
  168. return: #(3 2)
  169. !
  170. testNestedIfTrue
  171. self should: 'foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]' return: 1.
  172. self should: 'foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]' return: nil.
  173. self should: 'foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]' return: 1.
  174. self should: 'foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]' return: receiver.
  175. !
  176. testNestedSends
  177. self should: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString' return: (Point x: (2@3) y: 4) asString
  178. !
  179. testNilPerform
  180. self should: 'foo ^ nil perform: #yourself' return: nil
  181. !
  182. testNonLocalReturn
  183. self should: 'foo [ ^ 1 ] value' return: 1.
  184. self should: 'foo [ ^ 1 + 1 ] value' return: 2.
  185. self should: 'foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt' return: 3.
  186. self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8
  187. !
  188. testPascalCaseGlobal
  189. self should: 'foo ^Object' return: (Smalltalk globals at: 'Object').
  190. self should: 'foo ^NonExistent' return: nil
  191. !
  192. testPragmaJSStatement
  193. self should: 'foo < inlineJS: ''return 2+3'' >' return: 5
  194. !
  195. testReceiverEvaluatedOnceInSpecials
  196. self should: 'foo |x| x := 1. ^ {[ x := x+1 ] value ifNil: []. x}' return: {2. 2}.
  197. self should: 'foo |xs| xs := {nil. nil}. ^ {[ xs removeLast ] value ifNotNil: []. xs}' return: {nil. {nil}}.
  198. !
  199. testRegression1242
  200. self should: '
  201. foo
  202. |x|
  203. x := 2.
  204. x := nil ifNil: [].
  205. ^ x
  206. ' return: nil.
  207. self should: '
  208. foo
  209. |x|
  210. x := 2.
  211. x := 1 ifNotNil: [].
  212. ^ x
  213. ' return: nil.
  214. self should: '
  215. foo
  216. |x|
  217. x := 2.
  218. x := false ifFalse: [].
  219. ^ x
  220. ' return: nil.
  221. self should: '
  222. foo
  223. |x|
  224. x := 2.
  225. x := true ifTrue: [].
  226. ^ x
  227. ' return: nil.
  228. !
  229. testRegression1242ForReturn
  230. self should: 'foo [ ^ nil ifNil: [] ] value' return: nil.
  231. self should: 'foo [ ^ 1 ifNotNil: [] ] value' return: nil.
  232. self should: 'foo [ ^ false ifFalse: [] ] value' return: nil.
  233. self should: 'foo [ ^ true ifTrue: [] ] value' return: nil.
  234. !
  235. testRegression1244
  236. self should: 'foo [ ^ true ifTrue: [1] ifFalse: [2] ] value' return: 1
  237. !
  238. testRootSuperSend
  239. self
  240. should: 'foo ^ super class'
  241. receiver: ProtoObject new
  242. raise: MessageNotUnderstood
  243. !
  244. testSendReceiverAndArgumentsOrdered
  245. self should: 'foo
  246. | x |
  247. x := 1.
  248. ^ Array with: x with: (true ifTrue: [ x := 2 ])
  249. ' return: #(1 2).
  250. self should: 'foo
  251. | x |
  252. x := Array.
  253. ^ x with: x with: (true ifTrue: [ x := 2 ])
  254. ' return: {Array. 2}.
  255. !
  256. testSuperSend
  257. self
  258. should: 'foo ^ super isBoolean'
  259. receiver: true
  260. return: false
  261. !
  262. testSuperSend2
  263. self
  264. should: 'foo ^ super isNil'
  265. receiver: nil
  266. return: false
  267. !
  268. testSuperSend3
  269. self
  270. should: 'doo ^ super isNil'
  271. class: Object
  272. receiver: nil
  273. return: false
  274. !
  275. testSuperSend4
  276. self
  277. should: 'foo ^ super asJavaScriptObject'
  278. receiver: 'me'
  279. return: #('m' 'e')
  280. !
  281. testSuperSend5
  282. self
  283. should: 'foo [super addLast: 4] on: Error do: [ self add: 5 ]. ^ self'
  284. class: SequenceableCollection
  285. receiver: #(1 2 3)
  286. return: #(1 2 3 5)
  287. !
  288. testSuperSend6
  289. self
  290. should: 'foo ^ super ifTrue: [ true ] ifFalse: [ false ]'
  291. receiver: true
  292. raise: Error
  293. !
  294. testTempVariables
  295. self should: 'foo | a | ^ a' return: nil.
  296. self should: 'foo | AVariable | ^ AVariable' return: nil.
  297. self should: 'foo | a b c | ^ c' return: nil.
  298. self should: 'foo | a | [ | d | ^ d ] value' return: nil.
  299. self should: 'foo | a | a:= 1. ^ a' return: 1.
  300. self should: 'foo | AVariable | AVariable := 1. ^ AVariable' return: 1.
  301. !
  302. testThisContext
  303. self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true
  304. !
  305. testUnknownPragma
  306. self should: 'foo < fooBar: ''return 2+3'' > | x | ^ x := 6' return: 6.
  307. self should: 'foo | x | < fooBar: ''return 2+3'' > ^ x := 6' return: 6
  308. !
  309. testifFalse
  310. self should: 'foo true ifFalse: [ ^ 1 ]' return: receiver.
  311. self should: 'foo false ifFalse: [ ^ 2 ]' return: 2.
  312. self should: 'foo ^ true ifFalse: [ 1 ]' return: nil.
  313. self should: 'foo ^ false ifFalse: [ 2 ]' return: 2.
  314. !
  315. testifFalseIfTrue
  316. self should: 'foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]' return: 2.
  317. self should: 'foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]' return: 2.
  318. self should: 'foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]' return: 2.
  319. self should: 'foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]' return: 2.
  320. !
  321. testifNil
  322. self should: 'foo ^ 1 ifNil: [ 2 ]' return: 1.
  323. self should: 'foo ^ nil ifNil: [ 2 ]' return: 2.
  324. self should: 'foo 1 ifNil: [ ^ 2 ]' return: receiver.
  325. self should: 'foo nil ifNil: [ ^ 2 ]' return: 2.
  326. !
  327. testifNilIfNotNil
  328. self should: 'foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 3.
  329. self should: 'foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 2.
  330. self should: 'foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 3.
  331. self should: 'foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 2.
  332. !
  333. testifNotNil
  334. self should: 'foo ^ 1 ifNotNil: [ 2 ]' return: 2.
  335. self should: 'foo ^ nil ifNotNil: [ 2 ]' return: nil.
  336. self should: 'foo 1 ifNotNil: [ ^ 2 ]' return: 2.
  337. self should: 'foo nil ifNotNil: [ ^ 2 ]' return: receiver.
  338. !
  339. testifNotNilWithArgument
  340. self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.
  341. self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.
  342. self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.
  343. self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.
  344. self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.
  345. self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5
  346. !
  347. testifTrue
  348. self should: 'foo false ifTrue: [ ^ 1 ]' return: receiver.
  349. self should: 'foo true ifTrue: [ ^ 2 ]' return: 2.
  350. self should: 'foo ^ false ifTrue: [ 1 ]' return: nil.
  351. self should: 'foo ^ true ifTrue: [ 2 ]' return: 2.
  352. !
  353. testifTrueIfFalse
  354. self should: 'foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]' return: 2.
  355. self should: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]' return: 1.
  356. self should: 'foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 1.
  357. self should: 'foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 2.
  358. ! !
  359. !AbstractCompilerTest class methodsFor: 'testing'!
  360. isAbstract
  361. ^ self name = AbstractCompilerTest name
  362. ! !
  363. AbstractCompilerTest subclass: #ASTDebuggerTest
  364. slots: {}
  365. package: 'Compiler-Tests'!
  366. AbstractCompilerTest subclass: #ASTInterpreterTest
  367. slots: {}
  368. package: 'Compiler-Tests'!
  369. AbstractCompilerTest subclass: #CodeGeneratorTest
  370. slots: {}
  371. package: 'Compiler-Tests'!
  372. AbstractCompilerTest subclass: #InliningCodeGeneratorTest
  373. slots: {}
  374. package: 'Compiler-Tests'!
  375. ASTMethodRunningTest subclass: #AbstractJavaScriptGatewayTest
  376. slots: {#theClass}
  377. package: 'Compiler-Tests'!
  378. !AbstractJavaScriptGatewayTest methodsFor: 'accessing'!
  379. theClass
  380. ^ theClass
  381. ! !
  382. !AbstractJavaScriptGatewayTest methodsFor: 'running'!
  383. jsConstructor
  384. <inlineJS: '
  385. var ctr = function () {};
  386. ctr.prototype.foo = function (a,b) {return a+","+b};
  387. return ctr;
  388. '>
  389. ! !
  390. !AbstractJavaScriptGatewayTest methodsFor: 'tests'!
  391. testDyadicSuperDifferentNames
  392. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  393. theClass beJavaScriptSubclassOf: self jsConstructor.
  394. receiver := ObjectMock2 new foo: 'should be shadowed'; yourself.
  395. arguments := #(4 true).
  396. self
  397. should: 'bar: anObject baz: anotherObject
  398. <jsOverride: #foo args: #(anObject anotherObject)>
  399. ^ super bar: anObject baz: anotherObject'
  400. return: '4,true'
  401. !
  402. testDyadicSuperDifferentNamesNested
  403. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  404. theClass beJavaScriptSubclassOf: self jsConstructor.
  405. receiver := ObjectMock2 new foo: 'should be shadowed'; yourself.
  406. arguments := #(4 true).
  407. self
  408. should: 'bar: anObject baz: anotherObject
  409. <jsOverride: #foo args: #(anObject anotherObject)>
  410. ^ [ super bar: anObject baz: anotherObject ] value'
  411. return: '4,true'
  412. !
  413. testDyadicSuperDifferentNamesPermutated
  414. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  415. theClass beJavaScriptSubclassOf: self jsConstructor.
  416. receiver := ObjectMock2 new foo: 'should be shadowed'; yourself.
  417. arguments := #(4 true).
  418. self
  419. should: 'bar: anObject baz: anotherObject
  420. <jsOverride: #foo args: #(anotherObject anObject)>
  421. ^ super bar: anObject baz: anotherObject'
  422. return: 'true,4'
  423. !
  424. testMonadicSuperDifferentNames
  425. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  426. theClass beJavaScriptSubclassOf: self jsConstructor.
  427. receiver := ObjectMock2 new foo: 'should be shadowed'; yourself.
  428. arguments := #(4).
  429. self
  430. should: 'bar: anObject <jsOverride: #foo args: #(anObject)> ^ super bar: anObject'
  431. return: '4,undefined'
  432. !
  433. testNiladicSuper
  434. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  435. theClass beJavaScriptSubclassOf: self jsConstructor.
  436. self
  437. should: 'foo <jsOverride: #foo> ^ super foo'
  438. receiver: (ObjectMock2 new foo: 'should be shadowed'; yourself)
  439. return: 'undefined,undefined'
  440. !
  441. testNiladicSuperDifferentNames
  442. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  443. theClass beJavaScriptSubclassOf: self jsConstructor.
  444. self
  445. should: 'bar <jsOverride: #foo> ^ super bar'
  446. receiver: (ObjectMock2 new foo: 'should be shadowed'; yourself)
  447. return: 'undefined,undefined'
  448. !
  449. testNiladicSuperNested
  450. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  451. theClass beJavaScriptSubclassOf: self jsConstructor.
  452. self
  453. should: 'foo <jsOverride: #foo> ^ [ super foo ] value'
  454. receiver: (ObjectMock2 new foo: 'should be shadowed'; yourself)
  455. return: 'undefined,undefined'
  456. !
  457. testTriadicSuperDifferentNamesPermutated
  458. theClass := ObjectMock subclass: #ObjectMock2 slots: #() package: 'Compiler-Tests'.
  459. theClass beJavaScriptSubclassOf: self jsConstructor.
  460. receiver := ObjectMock2 new foo: 'should be shadowed'; yourself.
  461. arguments := #(4 true 'hello').
  462. self
  463. should: 'bar: anObject baz: anotherObject moo: yao
  464. <jsOverride: #foo args: #(yao anObject anotherObject)>
  465. ^ super bar: anObject baz: anotherObject moo: yao'
  466. return: 'hello,4'
  467. ! !
  468. !AbstractJavaScriptGatewayTest class methodsFor: 'testing'!
  469. isAbstract
  470. ^ self name = AbstractJavaScriptGatewayTest name
  471. ! !
  472. AbstractJavaScriptGatewayTest subclass: #DebuggedJSGTest
  473. slots: {}
  474. package: 'Compiler-Tests'!
  475. AbstractJavaScriptGatewayTest subclass: #InlinedJSGTest
  476. slots: {}
  477. package: 'Compiler-Tests'!
  478. AbstractJavaScriptGatewayTest subclass: #InterpretedJSGTest
  479. slots: {}
  480. package: 'Compiler-Tests'!
  481. AbstractJavaScriptGatewayTest subclass: #PlainJSGTest
  482. slots: {}
  483. package: 'Compiler-Tests'!
  484. TestCase subclass: #ASTPCNodeVisitorTest
  485. slots: {}
  486. package: 'Compiler-Tests'!
  487. !ASTPCNodeVisitorTest methodsFor: 'factory'!
  488. astPCNodeVisitor
  489. ^ ASTPCNodeVisitor new
  490. index: 0;
  491. yourself
  492. !
  493. astPCNodeVisitorForSelector: aString
  494. ^ ASTPCNodeVisitor new
  495. selector: aString;
  496. index: 0;
  497. yourself
  498. !
  499. newTeachableVisitor
  500. | result |
  501. result := Teachable new
  502. whenSend: #visit: evaluate: [ :one | one acceptDagVisitor: result ];
  503. acceptSend: #visitDagNode:.
  504. ^ result
  505. ! !
  506. !ASTPCNodeVisitorTest methodsFor: 'tests'!
  507. testJSStatementNode
  508. | ast result |
  509. ast := self parse: 'foo <inlineJS: ''consolee.log(1)''>' forClass: Object.
  510. result := self astPCNodeVisitor visit: ast; currentNode.
  511. self
  512. assert: ((self newTeachableVisitor whenSend: #visitJSStatementNode: return: 'JS'; yourself) visit: result)
  513. equals: 'JS'
  514. !
  515. testMessageSend
  516. | ast |
  517. ast := self parse: 'foo self asString yourself. ^ self asBoolean' forClass: Object.
  518. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  519. visit: ast;
  520. currentNode) selector equals: 'yourself'
  521. !
  522. testMessageSendWithBlocks
  523. | ast |
  524. ast := self parse: 'foo true ifTrue: [ [ self asString yourself ] value. ]. ^ self asBoolean' forClass: Object.
  525. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  526. visit: ast;
  527. currentNode) selector equals: 'yourself'
  528. !
  529. testMessageSendWithInlining
  530. | ast |
  531. ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.
  532. self assert: ((self astPCNodeVisitorForSelector: 'yourself')
  533. visit: ast;
  534. currentNode) selector equals: 'yourself'.
  535. ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.
  536. self assert: ((self astPCNodeVisitorForSelector: 'asBoolean')
  537. visit: ast;
  538. currentNode) selector equals: 'asBoolean'
  539. !
  540. testNoMessageSend
  541. | ast |
  542. ast := self parse: 'foo ^ self' forClass: Object.
  543. self assert: (self astPCNodeVisitor
  544. visit: ast;
  545. currentNode) isNil
  546. ! !
  547. TestCase subclass: #ASTPositionTest
  548. slots: {}
  549. package: 'Compiler-Tests'!
  550. !ASTPositionTest methodsFor: 'tests'!
  551. testNodeAtPosition
  552. | node |
  553. node := self parse: 'yourself
  554. ^ self' forClass: Object.
  555. self assert: (node navigationNodeAt: 2@4 ifAbsent: [ nil ]) source equals: 'self'.
  556. node := self parse: 'foo
  557. true ifTrue: [ 1 ]' forClass: Object.
  558. self assert: (node navigationNodeAt: 2@7 ifAbsent: [ nil ]) selector equals: 'ifTrue:'.
  559. node := self parse: 'foo
  560. self foo; bar; baz' forClass: Object.
  561. self assert: (node navigationNodeAt: 2@8 ifAbsent: [ nil ]) selector equals: 'foo'
  562. ! !
  563. TestCase subclass: #AbstractCodeGeneratorInstallTest
  564. slots: {#receiver}
  565. package: 'Compiler-Tests'!
  566. !AbstractCodeGeneratorInstallTest methodsFor: 'accessing'!
  567. receiver
  568. ^ receiver
  569. ! !
  570. !AbstractCodeGeneratorInstallTest methodsFor: 'testing'!
  571. shouldntInstall: aString andRaise: anErrorClass
  572. | method |
  573. [ self
  574. should: [ method := self install: aString forClass: receiver class ]
  575. raise: anErrorClass ]
  576. ensure: [ method ifNotNil: [ receiver class removeCompiledMethod: method ] ]
  577. ! !
  578. !AbstractCodeGeneratorInstallTest methodsFor: 'tests'!
  579. testDyadicJSOverrideArgMismatch
  580. receiver := ObjectMock new.
  581. self
  582. shouldntInstall: 'quux: aNumber foo: anotherNumber
  583. <jsOverride: #mux args: #(anInteger anotherNumber)>
  584. ^ (foo := foo * aNumber + anotherNumber)'
  585. andRaise: CompilerError.
  586. self
  587. shouldntInstall: 'quux: aNumber foo: anotherNumber
  588. <jsOverride: #mux args: #(aNumber anotherInteger)>
  589. ^ (foo := foo * aNumber + anotherNumber)'
  590. andRaise: CompilerError.
  591. self
  592. shouldntInstall: 'quux: aNumber foo: anotherNumber
  593. <jsOverride: #mux args: #(anotherNumber anInteger)>
  594. ^ (foo := foo * aNumber + anotherNumber)'
  595. andRaise: CompilerError
  596. !
  597. testDyadicJSOverrideDifferentNames
  598. receiver := ObjectMock new.
  599. receiver foo: 4.
  600. self while: 'quux: anInteger foo: anotherInteger
  601. <jsOverride: #mux args: #(anInteger anotherInteger)>
  602. ^ (foo := foo * anInteger + anotherInteger)' should: [
  603. self should: [ receiver mux ] raise: MessageNotUnderstood.
  604. self should: [ receiver mux: 2 and: -1 ] raise: MessageNotUnderstood.
  605. self assert: (receiver basicPerform: #mux withArguments: #(2 -2)) equals: 6.
  606. self assert: (receiver quux: 1 foo: 4) equals: 10.
  607. self should: [ receiver basicPerform: #quux ] raise: Error.
  608. self assert: receiver foo equals: 10 ]
  609. !
  610. testDyadicJSOverrideDifferentNamesPermutated
  611. receiver := ObjectMock new.
  612. receiver foo: 4.
  613. self while: 'quux: anInteger foo: anotherInteger
  614. <jsOverride: #mux args: #(anotherInteger anInteger)>
  615. ^ (foo := foo * anInteger + anotherInteger)' should: [
  616. self should: [ receiver mux ] raise: MessageNotUnderstood.
  617. self should: [ receiver mux: 2 and: -1 ] raise: MessageNotUnderstood.
  618. self assert: (receiver basicPerform: #mux withArguments: #(-2 2)) equals: 6.
  619. self assert: (receiver quux: 1 foo: 4) equals: 10.
  620. self should: [ receiver basicPerform: #quux ] raise: Error.
  621. self assert: receiver foo equals: 10 ]
  622. !
  623. testDyadicJSOverrideInOneArg
  624. receiver := ObjectMock new.
  625. self
  626. shouldntInstall: 'quux: anInteger
  627. <jsOverride: #mux args: #(anInteger anotherInteger)>
  628. ^ (foo := foo + anInteger)'
  629. andRaise: CompilerError.
  630. self
  631. shouldntInstall: 'quux: anInteger
  632. <jsOverride: #mux args: #(anotherInteger anInteger)>
  633. ^ (foo := foo + anInteger)'
  634. andRaise: CompilerError
  635. !
  636. testDyadicJSOverrideInUnary
  637. receiver := ObjectMock new.
  638. self
  639. shouldntInstall: 'quux <jsOverride: #mux args: #(anInteger anotherInteger)> ^ (foo := foo + 3)'
  640. andRaise: CompilerError
  641. !
  642. testDyadicJSOverrideRepeatedArgs
  643. receiver := ObjectMock new.
  644. self
  645. shouldntInstall: 'quux: anInteger
  646. <jsOverride: #mux args: #(anInteger anInteger)>
  647. ^ (foo := foo + anInteger)'
  648. andRaise: CompilerError.
  649. self
  650. shouldntInstall: 'quux: anInteger foo: anotherInteger
  651. <jsOverride: #mux args: #(anInteger anInteger)>
  652. ^ (foo := foo * anInteger + anotherInteger)'
  653. andRaise: CompilerError
  654. !
  655. testInvalidAssignment
  656. self shouldntInstall: 'foo:a a:=1' andRaise: InvalidAssignmentError.
  657. self shouldntInstall: 'foo false:=1' andRaise: InvalidAssignmentError.
  658. self shouldntInstall: 'foo console:=1' andRaise: InvalidAssignmentError.
  659. self shouldntInstall: 'foo Number:=1' andRaise: InvalidAssignmentError
  660. !
  661. testMistypedPragmaJSStatement
  662. self shouldntInstall: 'foo < inlineJS: ''return ''foo'''' >' andRaise: ParseError
  663. !
  664. testMonadicJSOverrideArgMismatch
  665. receiver := ObjectMock new.
  666. self
  667. shouldntInstall: 'quux: aNumber <jsOverride: #mux args: #(anInteger)> ^ (foo := foo + aNumber)'
  668. andRaise: CompilerError
  669. !
  670. testMonadicJSOverrideDifferentNames
  671. receiver := ObjectMock new.
  672. receiver foo: 4.
  673. self while: 'quux: anInteger <jsOverride: #mux args: #(anInteger)> ^ (foo := foo + anInteger)' should: [
  674. self should: [ receiver mux ] raise: MessageNotUnderstood.
  675. self should: [ receiver mux: 2 ] raise: MessageNotUnderstood.
  676. self assert: (receiver basicPerform: #mux withArguments: #(2)) equals: 6.
  677. self assert: (receiver quux: 4) equals: 10.
  678. self should: [ receiver basicPerform: #quux ] raise: Error.
  679. self assert: receiver foo equals: 10 ]
  680. !
  681. testMonadicJSOverrideInUnary
  682. receiver := ObjectMock new.
  683. self
  684. shouldntInstall: 'quux <jsOverride: #mux args: #(anInteger)> ^ (foo := foo + 3)'
  685. andRaise: CompilerError
  686. !
  687. testNiladicJSOverride
  688. receiver := ObjectMock new.
  689. receiver foo: 4.
  690. self while: 'baz <jsOverride: #baz> ^ (foo := foo + 3)' should: [
  691. self assert: receiver baz equals: 7.
  692. self assert: (receiver basicPerform: #baz) equals: 10.
  693. self assert: receiver baz equals: 13.
  694. self assert: receiver foo equals: 13 ]
  695. !
  696. testNiladicJSOverrideDifferentNames
  697. receiver := ObjectMock new.
  698. receiver foo: 4.
  699. self while: 'quux <jsOverride: #mux> ^ (foo := foo + 3)' should: [
  700. self should: [ receiver mux ] raise: MessageNotUnderstood.
  701. self assert: (receiver basicPerform: #mux) equals: 7.
  702. self assert: receiver quux equals: 10.
  703. self should: [ receiver basicPerform: #quux ] raise: Error.
  704. self assert: receiver foo equals: 10 ]
  705. !
  706. testNiladicJSOverrideInOneArg
  707. receiver := ObjectMock new.
  708. self
  709. shouldntInstall: 'quux: anInteger <jsOverride: #mux> ^ (foo := foo + anInteger)'
  710. andRaise: CompilerError
  711. !
  712. testPragmaInBlock
  713. self shouldntInstall: 'foo ^ [ < fooBar > 4 ] value' andRaise: ParseError
  714. !
  715. testTriadicJSOverrideDifferentNamesPermutated
  716. receiver := ObjectMock new.
  717. receiver foo: 4.
  718. self while: 'quux: anInteger foo: anotherInteger bar: yaInt
  719. <jsOverride: #mux args: #(yaInt anInteger anotherInteger)>
  720. ^ (foo := foo * anInteger + anotherInteger - yaInt)' should: [
  721. self should: [ receiver mux ] raise: MessageNotUnderstood.
  722. self should: [ receiver mux: 2 and: -1 and: 0 ] raise: MessageNotUnderstood.
  723. self assert: (receiver basicPerform: #mux withArguments: #(5 2 3)) equals: 6.
  724. self assert: (receiver quux: 1 foo: 4 bar: 20) equals: -10.
  725. self should: [ receiver basicPerform: #quux ] raise: Error.
  726. self assert: receiver foo equals: -10 ]
  727. ! !
  728. !AbstractCodeGeneratorInstallTest class methodsFor: 'testing'!
  729. isAbstract
  730. ^ self name = AbstractCodeGeneratorInstallTest name
  731. ! !
  732. AbstractCodeGeneratorInstallTest subclass: #CodeGeneratorInstallTest
  733. slots: {}
  734. package: 'Compiler-Tests'!
  735. AbstractCodeGeneratorInstallTest subclass: #InliningCodeGeneratorInstallTest
  736. slots: {}
  737. package: 'Compiler-Tests'!
  738. TestCase subclass: #ScopeVarTest
  739. slots: {}
  740. package: 'Compiler-Tests'!
  741. !ScopeVarTest methodsFor: 'tests'!
  742. testClassRefVar
  743. | node binding |
  744. node := VariableNode new
  745. identifier: 'Object';
  746. yourself.
  747. SemanticAnalyzer new
  748. pushScope: MethodLexicalScope new;
  749. visit: node.
  750. binding := node binding.
  751. self deny: binding isAssignable.
  752. self deny: binding isIdempotent.
  753. self assert: (binding alias includesSubString: 'Object').
  754. self assert: (binding alias ~= 'Object')
  755. !
  756. testExternallyKnownVar
  757. | node binding |
  758. node := VariableNode new
  759. identifier: 'console';
  760. yourself.
  761. SemanticAnalyzer new
  762. pushScope: MethodLexicalScope new;
  763. visit: node.
  764. binding := node binding.
  765. self deny: binding isAssignable.
  766. self deny: binding isIdempotent.
  767. self assert: binding alias equals: 'console'
  768. !
  769. testExternallyUnknownVar
  770. | node |
  771. node := VariableNode new
  772. identifier: 'bzzz';
  773. yourself.
  774. self
  775. should: [
  776. SemanticAnalyzer new
  777. pushScope: MethodLexicalScope new;
  778. visit: node ]
  779. raise: UnknownVariableError
  780. !
  781. testPseudoVar
  782. #('self' 'super' 'true' 'false' 'nil' 'thisContext') do: [ :each |
  783. | binding |
  784. binding := MethodLexicalScope new bindingFor: each.
  785. self deny: binding isAssignable.
  786. self assert: binding isIdempotent ]
  787. !
  788. testSlotVar
  789. | binding |
  790. binding := MethodLexicalScope new
  791. addSlotVar: 'bzzz';
  792. bindingFor: 'bzzz'.
  793. self assert: binding isAssignable.
  794. self deny: binding isIdempotent.
  795. self assert: (binding alias includesSubString: 'bzzz').
  796. self assert: (binding alias ~= 'bzzz')
  797. !
  798. testTempVar
  799. | binding |
  800. binding := MethodLexicalScope new
  801. addTemp: 'bzzz';
  802. bindingFor: 'bzzz'.
  803. self assert: binding isAssignable.
  804. self deny: binding isIdempotent.
  805. self assert: binding alias equals: 'bzzz'
  806. !
  807. testUnknownVar
  808. self assert: (MethodLexicalScope new bindingFor: 'bzzz') isNil
  809. ! !
  810. TestCase subclass: #SemanticAnalyzerTest
  811. slots: {#analyzer}
  812. package: 'Compiler-Tests'!
  813. !SemanticAnalyzerTest methodsFor: 'running'!
  814. setUp
  815. analyzer := SemanticAnalyzer on: Object
  816. ! !
  817. !SemanticAnalyzerTest methodsFor: 'tests'!
  818. testAssignment
  819. | src ast |
  820. src := 'foo self := 1'.
  821. ast := Smalltalk parse: src.
  822. self should: [analyzer visit: ast] raise: InvalidAssignmentError
  823. !
  824. testNonLocalReturn
  825. | src ast |
  826. src := 'foo | a | a + 1. ^ a'.
  827. ast := Smalltalk parse: src.
  828. analyzer visit: ast.
  829. self deny: ast scope hasNonLocalReturn
  830. !
  831. testNonLocalReturn2
  832. | src ast |
  833. src := 'foo | a | a + 1. [ [ ^ a] ]'.
  834. ast := Smalltalk parse: src.
  835. analyzer visit: ast.
  836. self assert: ast scope hasNonLocalReturn
  837. !
  838. testScope
  839. | src ast |
  840. src := 'foo | a | a + 1. [ | b | b := a ]'.
  841. ast := Smalltalk parse: src.
  842. analyzer visit: ast.
  843. self deny: ast sequenceNode dagChildren last scope == ast scope.
  844. !
  845. testScope2
  846. | src ast |
  847. src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
  848. ast := Smalltalk parse: src.
  849. analyzer visit: ast.
  850. self deny: ast sequenceNode dagChildren last sequenceNode dagChildren first scope == ast scope.
  851. !
  852. testScopeLevel
  853. | src ast |
  854. src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.
  855. ast := Smalltalk parse: src.
  856. analyzer visit: ast.
  857. self assert: ast scope scopeLevel equals: 1.
  858. self assert: ast sequenceNode dagChildren last sequenceNode dagChildren first scope scopeLevel equals: 3
  859. !
  860. testUnknownVariables
  861. | src ast |
  862. src := 'foo | a | b + a'.
  863. ast := Smalltalk parse: src.
  864. self should: [ analyzer visit: ast ] raise: UnknownVariableError
  865. !
  866. testUnknownVariablesWithScope
  867. | src ast |
  868. src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.
  869. ast := Smalltalk parse: src.
  870. self should: [ analyzer visit: ast ] raise: UnknownVariableError
  871. !
  872. testVariableShadowing
  873. | src ast |
  874. src := 'foo | a | a + 1'.
  875. ast := Smalltalk parse: src.
  876. analyzer visit: ast
  877. !
  878. testVariableShadowing2
  879. | src ast |
  880. src := 'foo | a | a + 1. [ | a | a := 2 ]'.
  881. ast := Smalltalk parse: src.
  882. self should: [analyzer visit: ast] raise: ShadowingVariableError
  883. !
  884. testVariableShadowing3
  885. | src ast |
  886. src := 'foo | a | a + 1. [ | b | b := 2 ]'.
  887. ast := Smalltalk parse: src.
  888. analyzer visit: ast
  889. !
  890. testVariableShadowing4
  891. | src ast |
  892. src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.
  893. ast := Smalltalk parse: src.
  894. analyzer visit: ast
  895. !
  896. testVariableShadowing5
  897. | src ast |
  898. src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.
  899. ast := Smalltalk parse: src.
  900. self should: [analyzer visit: ast] raise: ShadowingVariableError
  901. !
  902. testVariablesLookup
  903. | src ast |
  904. src := 'foo | a | a + 1. [ | b | b := a ]'.
  905. ast := Smalltalk parse: src.
  906. analyzer visit: ast.
  907. "Binding for `a` in the message send"
  908. self assert: ast sequenceNode dagChildren first receiver binding isAssignable.
  909. self assert: ast sequenceNode dagChildren first receiver binding alias equals: 'a'.
  910. self assert: ast sequenceNode dagChildren first receiver binding scope == ast scope.
  911. "Binding for `b`"
  912. self assert: ast sequenceNode dagChildren last sequenceNode dagChildren first left binding isAssignable.
  913. self assert: ast sequenceNode dagChildren last sequenceNode dagChildren first left binding alias equals: 'b'.
  914. self assert: ast sequenceNode dagChildren last sequenceNode dagChildren first left binding scope == ast sequenceNode dagChildren last scope.
  915. ! !
  916. SemanticAnalyzerTest subclass: #AISemanticAnalyzerTest
  917. slots: {}
  918. package: 'Compiler-Tests'!
  919. !AISemanticAnalyzerTest methodsFor: 'running'!
  920. setUp
  921. analyzer := (AISemanticAnalyzer on: Object)
  922. context: (AIContext new
  923. defineLocal: 'local';
  924. localAt: 'local' put: 3;
  925. yourself);
  926. yourself
  927. ! !
  928. !AISemanticAnalyzerTest methodsFor: 'tests'!
  929. testContextVariables
  930. | src ast |
  931. src := 'foo | a | local + a'.
  932. ast := Smalltalk parse: src.
  933. self shouldnt: [ analyzer visit: ast ] raise: UnknownVariableError
  934. ! !
  935. Trait named: #TASTCompilingTest
  936. package: 'Compiler-Tests'!
  937. !TASTCompilingTest methodsFor: 'accessing'!
  938. codeGeneratorClass
  939. self subclassResponsibility
  940. ! !
  941. !TASTCompilingTest methodsFor: 'compiling'!
  942. install: aString forClass: aClass
  943. ^ self compiler
  944. install: aString
  945. forClass: aClass
  946. protocol: 'tests'
  947. ! !
  948. !TASTCompilingTest methodsFor: 'factory'!
  949. compiler
  950. ^ Compiler new
  951. codeGeneratorClass: self codeGeneratorClass;
  952. yourself
  953. ! !
  954. !TASTCompilingTest methodsFor: 'testing'!
  955. while: aString inClass: aClass should: aBlock
  956. | method |
  957. [
  958. method := self install: aString forClass: aClass.
  959. aBlock value: method ]
  960. ensure: [ method ifNotNil: [ aClass removeCompiledMethod: method ] ]
  961. !
  962. while: aString should: aBlock
  963. self while: aString inClass: self receiver class should: aBlock
  964. ! !
  965. Trait named: #TASTParsingTest
  966. package: 'Compiler-Tests'!
  967. !TASTParsingTest methodsFor: 'parsing'!
  968. parse: aString forClass: aClass
  969. ^ Compiler new
  970. ast: aString
  971. forClass: aClass
  972. protocol: 'test'
  973. ! !
  974. Trait named: #TCTDebugged
  975. package: 'Compiler-Tests'!
  976. !TCTDebugged methodsFor: 'private'!
  977. interpret: aString forClass: aClass receiver: anObject withArguments: aDictionary
  978. "The food is a methodNode. Interpret the sequenceNode only"
  979. | ctx |
  980. ctx := self prepareContextFor: aString class: aClass receiver: anObject withArguments: aDictionary.
  981. ^ (ASTDebugger context: ctx) proceed; result
  982. ! !
  983. Trait named: #TCTExecuted
  984. package: 'Compiler-Tests'!
  985. !TCTExecuted methodsFor: 'testing'!
  986. while: aString inClass: aClass should: aBlock
  987. super
  988. while: aString
  989. inClass: aClass
  990. should: [ :method | aBlock value: [
  991. self receiver perform: method selector withArguments: self arguments ] ]
  992. ! !
  993. Trait named: #TCTInlined
  994. package: 'Compiler-Tests'!
  995. !TCTInlined methodsFor: 'accessing'!
  996. codeGeneratorClass
  997. ^ InliningCodeGenerator
  998. ! !
  999. Trait named: #TCTInterpreted
  1000. package: 'Compiler-Tests'!
  1001. !TCTInterpreted methodsFor: 'private'!
  1002. interpret: aString forClass: aClass receiver: anObject withArguments: aDictionary
  1003. "The food is a methodNode. Interpret the sequenceNode only"
  1004. | ctx |
  1005. ctx := self prepareContextFor: aString class: aClass receiver: anObject withArguments: aDictionary.
  1006. ^ ctx interpreter proceed; result
  1007. !
  1008. prepareContextFor: aString class: aClass receiver: anObject withArguments: anArray
  1009. "The food is a methodNode. Interpret the sequenceNode only"
  1010. | ctx ast |
  1011. ast := self parse: aString forClass: aClass.
  1012. ctx := AIContext new
  1013. receiver: anObject;
  1014. selector: ast selector;
  1015. interpreter: ASTInterpreter new;
  1016. yourself.
  1017. "Define locals for the context"
  1018. ast sequenceNode ifNotNil: [ :sequence |
  1019. sequence temps do: [ :each |
  1020. ctx defineLocal: each ] ].
  1021. ast arguments with: anArray do: [ :key :value |
  1022. ctx defineLocal: key; localAt: key put: value ].
  1023. ctx interpreter
  1024. context: ctx;
  1025. node: ast;
  1026. enterNode.
  1027. ^ctx
  1028. ! !
  1029. !TCTInterpreted methodsFor: 'testing'!
  1030. while: aString inClass: aClass should: aBlock
  1031. super
  1032. while: aString
  1033. inClass: aClass
  1034. should: [ aBlock value: [
  1035. self
  1036. interpret: aString
  1037. forClass: aClass
  1038. receiver: self receiver
  1039. withArguments: self arguments ] ]
  1040. ! !
  1041. Trait named: #TCTNonInlined
  1042. package: 'Compiler-Tests'!
  1043. !TCTNonInlined methodsFor: 'accessing'!
  1044. codeGeneratorClass
  1045. ^ CodeGenerator
  1046. ! !
  1047. TASTCompilingTest setTraitComposition: {TASTParsingTest} asTraitComposition!
  1048. TCTDebugged setTraitComposition: {TCTInterpreted} asTraitComposition!
  1049. ASTMethodRunningTest setTraitComposition: {TASTCompilingTest} asTraitComposition!
  1050. ASTDebuggerTest setTraitComposition: {TCTNonInlined. TCTDebugged} asTraitComposition!
  1051. ASTInterpreterTest setTraitComposition: {TCTNonInlined. TCTInterpreted} asTraitComposition!
  1052. CodeGeneratorTest setTraitComposition: {TCTNonInlined. TCTExecuted} asTraitComposition!
  1053. InliningCodeGeneratorTest setTraitComposition: {TCTInlined. TCTExecuted} asTraitComposition!
  1054. AbstractJavaScriptGatewayTest setTraitComposition: {TClassBuildingTest} asTraitComposition!
  1055. DebuggedJSGTest setTraitComposition: {TCTNonInlined. TCTDebugged} asTraitComposition!
  1056. InlinedJSGTest setTraitComposition: {TCTInlined. TCTExecuted} asTraitComposition!
  1057. InterpretedJSGTest setTraitComposition: {TCTNonInlined. TCTInterpreted} asTraitComposition!
  1058. PlainJSGTest setTraitComposition: {TCTNonInlined. TCTExecuted} asTraitComposition!
  1059. ASTPCNodeVisitorTest setTraitComposition: {TASTParsingTest} asTraitComposition!
  1060. ASTPositionTest setTraitComposition: {TASTParsingTest} asTraitComposition!
  1061. AbstractCodeGeneratorInstallTest setTraitComposition: {TASTCompilingTest} asTraitComposition!
  1062. CodeGeneratorInstallTest setTraitComposition: {TCTNonInlined} asTraitComposition!
  1063. InliningCodeGeneratorInstallTest setTraitComposition: {TCTInlined} asTraitComposition!
  1064. ! !