Kernel-Methods.st 6.3 KB

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