Kernel-Methods.st 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. self basicAt: 'category' put: aString
  125. !
  126. fn
  127. ^self basicAt: 'fn'
  128. !
  129. fn: aBlock
  130. self basicAt: 'fn' put: aBlock
  131. !
  132. messageSends
  133. ^self basicAt: 'messageSends'
  134. !
  135. methodClass
  136. ^self basicAt: 'methodClass'
  137. !
  138. protocol
  139. ^ self category
  140. !
  141. referencedClasses
  142. ^self basicAt: 'referencedClasses'
  143. !
  144. selector
  145. ^self basicAt: 'selector'
  146. !
  147. selector: aString
  148. self basicAt: 'selector' put: aString
  149. !
  150. source
  151. ^(self basicAt: 'source') ifNil: ['']
  152. !
  153. source: aString
  154. self basicAt: 'source' put: aString
  155. ! !
  156. Object subclass: #Message
  157. instanceVariableNames: 'selector arguments'
  158. package: 'Kernel-Methods'!
  159. !Message commentStamp!
  160. Generally, the system does not use instances of Message for efficiency reasons.
  161. 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.
  162. This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
  163. See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
  164. !Message methodsFor: 'accessing'!
  165. arguments
  166. ^arguments
  167. !
  168. arguments: anArray
  169. arguments := anArray
  170. !
  171. selector
  172. ^selector
  173. !
  174. selector: aString
  175. selector := aString
  176. ! !
  177. !Message methodsFor: 'printing'!
  178. printString
  179. ^ String streamContents: [:aStream|
  180. aStream
  181. nextPutAll: super printString;
  182. nextPutAll: '(';
  183. nextPutAll: selector;
  184. nextPutAll: ')' ]
  185. !
  186. sendTo: anObject
  187. ^ Smalltalk current send: self selector to: anObject arguments: self arguments
  188. ! !
  189. !Message class methodsFor: 'instance creation'!
  190. selector: aString arguments: anArray
  191. ^self new
  192. selector: aString;
  193. arguments: anArray;
  194. yourself
  195. ! !
  196. Object subclass: #MethodContext
  197. instanceVariableNames: ''
  198. package: 'Kernel-Methods'!
  199. !MethodContext commentStamp!
  200. 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.
  201. MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
  202. Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
  203. !MethodContext methodsFor: 'accessing'!
  204. asString
  205. ^self receiver class printString, ' >> ', self selector
  206. !
  207. home
  208. <return self.homeContext>
  209. !
  210. pc
  211. <return self.pc>
  212. !
  213. printString
  214. ^super printString, '(', self asString, ')'
  215. !
  216. receiver
  217. <return self.receiver>
  218. !
  219. selector
  220. <return smalltalk.convertSelector(self.selector)>
  221. !
  222. temps
  223. <return self.temps>
  224. ! !