Kernel-Methods.st 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
  2. Object subclass: #CompiledMethod
  3. instanceVariableNames: ''
  4. category: 'Kernel-Methods'!
  5. !CompiledMethod methodsFor: 'accessing'!
  6. source
  7. ^(self basicAt: 'source') ifNil: ['']
  8. !
  9. source: aString
  10. self basicAt: 'source' put: aString
  11. !
  12. category
  13. ^(self basicAt: 'category') ifNil: ['']
  14. !
  15. category: aString
  16. self basicAt: 'category' put: aString
  17. !
  18. selector
  19. ^self basicAt: 'selector'
  20. !
  21. selector: aString
  22. self basicAt: 'selector' put: aString
  23. !
  24. fn
  25. ^self basicAt: 'fn'
  26. !
  27. fn: aBlock
  28. self basicAt: 'fn' put: aBlock
  29. !
  30. messageSends
  31. ^self basicAt: 'messageSends'
  32. !
  33. methodClass
  34. ^self basicAt: 'methodClass'
  35. !
  36. referencedClasses
  37. ^self basicAt: 'referencedClasses'
  38. !
  39. arguments
  40. <return self.args || []>
  41. ! !
  42. Object subclass: #BlockClosure
  43. instanceVariableNames: ''
  44. category: 'Kernel-Methods'!
  45. !BlockClosure commentStamp!
  46. A BlockClosure is a lexical closure.
  47. The JavaScript representation is a function.
  48. A BlockClosure is evaluated with the #value* methods in the 'evaluating' protocol.!
  49. !BlockClosure methodsFor: 'accessing'!
  50. compiledSource
  51. <return self.toString()>
  52. !
  53. numArgs
  54. <return self.length>
  55. ! !
  56. !BlockClosure methodsFor: 'controlling'!
  57. whileTrue: aBlock
  58. "inlined in the Compiler"
  59. <while(self()) {aBlock()}>
  60. !
  61. whileFalse: aBlock
  62. "inlined in the Compiler"
  63. <while(!!self()) {aBlock()}>
  64. !
  65. whileFalse
  66. "inlined in the Compiler"
  67. self whileFalse: []
  68. !
  69. whileTrue
  70. "inlined in the Compiler"
  71. self whileTrue: []
  72. ! !
  73. !BlockClosure methodsFor: 'error handling'!
  74. on: anErrorClass do: aBlock
  75. ^self try: self catch: [:error |
  76. (error isKindOf: anErrorClass)
  77. ifTrue: [aBlock value: error]
  78. ifFalse: [error signal]]
  79. ! !
  80. !BlockClosure methodsFor: 'evaluating'!
  81. value
  82. "inlined in the Compiler"
  83. <return self();>
  84. !
  85. value: anArg
  86. "inlined in the Compiler"
  87. <return self(anArg);>
  88. !
  89. value: firstArg value: secondArg
  90. "inlined in the Compiler"
  91. <return self(firstArg, secondArg);>
  92. !
  93. value: firstArg value: secondArg value: thirdArg
  94. "inlined in the Compiler"
  95. <return self(firstArg, secondArg, thirdArg);>
  96. !
  97. valueWithPossibleArguments: aCollection
  98. <return self.apply(null, aCollection);>
  99. !
  100. new
  101. "Use the receiver as a JS constructor.
  102. *Do not* use this method to instanciate Smalltalk objects!!"
  103. <return new self()>
  104. !
  105. applyTo: anObject arguments: aCollection
  106. <return self.apply(anObject, aCollection)>
  107. !
  108. timeToRun
  109. "Answer the number of milliseconds taken to execute this block."
  110. ^ Date millisecondsToRun: self
  111. !
  112. ensure: aBlock
  113. | success |
  114. success := false.
  115. ^[self value. success := true. aBlock value]
  116. on: Error
  117. do: [:ex |
  118. success ifFalse: [aBlock value].
  119. ex signal]
  120. !
  121. newValue: anObject
  122. "Use the receiver as a JS constructor.
  123. *Do not* use this method to instanciate Smalltalk objects!!"
  124. <return new self(anObject)>
  125. !
  126. newValue: anObject value: anObject2
  127. "Use the receiver as a JS constructor.
  128. *Do not* use this method to instanciate Smalltalk objects!!"
  129. <return new self(anObject, anObject2)>
  130. !
  131. newValue: anObject value: anObject2 value: anObject3
  132. "Use the receiver as a JS constructor.
  133. *Do not* use this method to instanciate Smalltalk objects!!"
  134. <return new self(anObject, anObject2)>
  135. ! !
  136. !BlockClosure methodsFor: 'timeout/interval'!
  137. valueWithTimeout: aNumber
  138. <return setTimeout(self, aNumber)>
  139. !
  140. valueWithInterval: aNumber
  141. <return setInterval(self, aNumber)>
  142. ! !
  143. Object subclass: #MethodContext
  144. instanceVariableNames: ''
  145. category: 'Kernel-Methods'!
  146. !MethodContext methodsFor: 'accessing'!
  147. receiver
  148. <return self.receiver>
  149. !
  150. selector
  151. <return smalltalk.convertSelector(self.selector)>
  152. !
  153. home
  154. <return self.homeContext>
  155. !
  156. temps
  157. <return self.temps>
  158. !
  159. printString
  160. ^super printString, '(', self asString, ')'
  161. !
  162. asString
  163. ^self receiver class printString, ' >> ', self selector
  164. ! !
  165. Object subclass: #Message
  166. instanceVariableNames: 'selector arguments'
  167. category: 'Kernel-Methods'!
  168. !Message methodsFor: 'accessing'!
  169. selector
  170. ^selector
  171. !
  172. selector: aString
  173. selector := aString
  174. !
  175. arguments: anArray
  176. arguments := anArray
  177. !
  178. arguments
  179. ^arguments
  180. ! !
  181. !Message methodsFor: 'printing'!
  182. printString
  183. ^ String streamContents: [:aStream|
  184. aStream
  185. nextPutAll: super printString;
  186. nextPutAll: '(';
  187. nextPutAll: selector;
  188. nextPutAll: ')' ]
  189. ! !
  190. !Message class methodsFor: 'instance creation'!
  191. selector: aString arguments: anArray
  192. ^self new
  193. selector: aString;
  194. arguments: anArray;
  195. yourself
  196. ! !