Kernel-Methods.st 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
  2. Object subclass: #CompiledMethod
  3. instanceVariableNames: ''
  4. category: 'Kernel-Methods'!
  5. !CompiledMethod commentStamp!
  6. CompiledMethod hold the source and compiled code of a class method.
  7. You can get a CompiledMethod using `Behavior>>methodAt:`
  8. String methodAt: 'lines'
  9. and read the source code
  10. (String methodAt: 'lines') source
  11. See referenced classes:
  12. (String methodAt: 'lines') referencedClasses
  13. or messages sent from this method:
  14. (String methodAt: 'lines') messageSends!
  15. !CompiledMethod methodsFor: 'accessing'!
  16. source
  17. ^(self basicAt: 'source') ifNil: ['']
  18. !
  19. source: aString
  20. self basicAt: 'source' put: aString
  21. !
  22. category
  23. ^(self basicAt: 'category') ifNil: ['']
  24. !
  25. category: aString
  26. self basicAt: 'category' put: aString
  27. !
  28. selector
  29. ^self basicAt: 'selector'
  30. !
  31. selector: aString
  32. self basicAt: 'selector' put: aString
  33. !
  34. fn
  35. ^self basicAt: 'fn'
  36. !
  37. fn: aBlock
  38. self basicAt: 'fn' put: aBlock
  39. !
  40. messageSends
  41. ^self basicAt: 'messageSends'
  42. !
  43. methodClass
  44. ^self basicAt: 'methodClass'
  45. !
  46. referencedClasses
  47. ^self basicAt: 'referencedClasses'
  48. !
  49. arguments
  50. <return self.args || []>
  51. ! !
  52. Object subclass: #BlockClosure
  53. instanceVariableNames: ''
  54. category: 'Kernel-Methods'!
  55. !BlockClosure commentStamp!
  56. A BlockClosure is a lexical closure.
  57. The JavaScript representation is a function.
  58. A BlockClosure is evaluated with the `#value*` methods in the 'evaluating' protocol.!
  59. !BlockClosure methodsFor: 'accessing'!
  60. compiledSource
  61. <return self.toString()>
  62. !
  63. numArgs
  64. <return self.length>
  65. ! !
  66. !BlockClosure methodsFor: 'controlling'!
  67. whileTrue: aBlock
  68. "inlined in the Compiler"
  69. <while(self()) {aBlock()}>
  70. !
  71. whileFalse: aBlock
  72. "inlined in the Compiler"
  73. <while(!!self()) {aBlock()}>
  74. !
  75. whileFalse
  76. "inlined in the Compiler"
  77. self whileFalse: []
  78. !
  79. whileTrue
  80. "inlined in the Compiler"
  81. self whileTrue: []
  82. ! !
  83. !BlockClosure methodsFor: 'error handling'!
  84. on: anErrorClass do: aBlock
  85. ^self try: self catch: [:error |
  86. (error isKindOf: anErrorClass)
  87. ifTrue: [aBlock value: error]
  88. ifFalse: [error signal]]
  89. ! !
  90. !BlockClosure methodsFor: 'evaluating'!
  91. value
  92. "inlined in the Compiler"
  93. <return self();>
  94. !
  95. value: anArg
  96. "inlined in the Compiler"
  97. <return self(anArg);>
  98. !
  99. value: firstArg value: secondArg
  100. "inlined in the Compiler"
  101. <return self(firstArg, secondArg);>
  102. !
  103. value: firstArg value: secondArg value: thirdArg
  104. "inlined in the Compiler"
  105. <return self(firstArg, secondArg, thirdArg);>
  106. !
  107. valueWithPossibleArguments: aCollection
  108. <return self.apply(null, aCollection);>
  109. !
  110. new
  111. "Use the receiver as a JS constructor.
  112. *Do not* use this method to instanciate Smalltalk objects!!"
  113. <return new self()>
  114. !
  115. applyTo: anObject arguments: aCollection
  116. <return self.apply(anObject, aCollection)>
  117. !
  118. timeToRun
  119. "Answer the number of milliseconds taken to execute this block."
  120. ^ Date millisecondsToRun: self
  121. !
  122. ensure: aBlock
  123. | success |
  124. success := false.
  125. ^[self value. success := true. aBlock value]
  126. on: Error
  127. do: [:ex |
  128. success ifFalse: [aBlock value].
  129. ex signal]
  130. !
  131. newValue: anObject
  132. "Use the receiver as a JS constructor.
  133. *Do not* use this method to instanciate Smalltalk objects!!"
  134. <return new self(anObject)>
  135. !
  136. newValue: anObject value: anObject2
  137. "Use the receiver as a JS constructor.
  138. *Do not* use this method to instanciate Smalltalk objects!!"
  139. <return new self(anObject, anObject2)>
  140. !
  141. newValue: anObject value: anObject2 value: anObject3
  142. "Use the receiver as a JS constructor.
  143. *Do not* use this method to instanciate Smalltalk objects!!"
  144. <return new self(anObject, anObject2)>
  145. ! !
  146. !BlockClosure methodsFor: 'timeout/interval'!
  147. valueWithTimeout: aNumber
  148. <return setTimeout(self, aNumber)>
  149. !
  150. valueWithInterval: aNumber
  151. <return setInterval(self, aNumber)>
  152. ! !
  153. Object subclass: #MethodContext
  154. instanceVariableNames: ''
  155. category: 'Kernel-Methods'!
  156. !MethodContext commentStamp!
  157. MethodContext holds all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.
  158. MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
  159. Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
  160. !MethodContext methodsFor: 'accessing'!
  161. receiver
  162. <return self.receiver>
  163. !
  164. selector
  165. <return smalltalk.convertSelector(self.selector)>
  166. !
  167. home
  168. <return self.homeContext>
  169. !
  170. temps
  171. <return self.temps>
  172. !
  173. printString
  174. ^super printString, '(', self asString, ')'
  175. !
  176. asString
  177. ^self receiver class printString, ' >> ', self selector
  178. ! !
  179. Object subclass: #Message
  180. instanceVariableNames: 'selector arguments'
  181. category: 'Kernel-Methods'!
  182. !Message commentStamp!
  183. Generally, the system does not use instances of Message for efficiency reasons.
  184. However, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission.
  185. This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
  186. See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
  187. !Message methodsFor: 'accessing'!
  188. selector
  189. ^selector
  190. !
  191. selector: aString
  192. selector := aString
  193. !
  194. arguments: anArray
  195. arguments := anArray
  196. !
  197. arguments
  198. ^arguments
  199. ! !
  200. !Message methodsFor: 'printing'!
  201. printString
  202. ^ String streamContents: [:aStream|
  203. aStream
  204. nextPutAll: super printString;
  205. nextPutAll: '(';
  206. nextPutAll: selector;
  207. nextPutAll: ')' ]
  208. ! !
  209. !Message class methodsFor: 'instance creation'!
  210. selector: aString arguments: anArray
  211. ^self new
  212. selector: aString;
  213. arguments: anArray;
  214. yourself
  215. ! !