Kernel-Methods.st 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. <try{self()}finally{return aBlock._value()}>
  46. !
  47. new
  48. "Use the receiver as a JS constructor.
  49. *Do not* use this method to instanciate Smalltalk objects!!"
  50. <return new self()>
  51. !
  52. newValue: anObject
  53. "Use the receiver as a JS constructor.
  54. *Do not* use this method to instanciate Smalltalk objects!!"
  55. <return new self(anObject)>
  56. !
  57. newValue: anObject value: anObject2
  58. "Use the receiver as a JS constructor.
  59. *Do not* use this method to instanciate Smalltalk objects!!"
  60. <return new self(anObject, anObject2)>
  61. !
  62. newValue: anObject value: anObject2 value: anObject3
  63. "Use the receiver as a JS constructor.
  64. *Do not* use this method to instanciate Smalltalk objects!!"
  65. <return new self(anObject, anObject2)>
  66. !
  67. timeToRun
  68. "Answer the number of milliseconds taken to execute this block."
  69. ^ Date millisecondsToRun: self
  70. !
  71. value
  72. "inlined in the Compiler"
  73. <return self();>
  74. !
  75. value: anArg
  76. "inlined in the Compiler"
  77. <return self(anArg);>
  78. !
  79. value: firstArg value: secondArg
  80. "inlined in the Compiler"
  81. <return self(firstArg, secondArg);>
  82. !
  83. value: firstArg value: secondArg value: thirdArg
  84. "inlined in the Compiler"
  85. <return self(firstArg, secondArg, thirdArg);>
  86. !
  87. valueWithPossibleArguments: aCollection
  88. <return self.apply(null, aCollection);>
  89. ! !
  90. !BlockClosure methodsFor: 'timeout/interval'!
  91. valueWithInterval: aNumber
  92. <return setInterval(self, aNumber)>
  93. !
  94. valueWithTimeout: aNumber
  95. <return setTimeout(self, aNumber)>
  96. ! !
  97. Object subclass: #CompiledMethod
  98. instanceVariableNames: ''
  99. package: 'Kernel-Methods'!
  100. !CompiledMethod commentStamp!
  101. CompiledMethod hold the source and compiled code of a class method.
  102. You can get a CompiledMethod using `Behavior>>methodAt:`
  103. String methodAt: 'lines'
  104. and read the source code
  105. (String methodAt: 'lines') source
  106. See referenced classes:
  107. (String methodAt: 'lines') referencedClasses
  108. or messages sent from this method:
  109. (String methodAt: 'lines') messageSends!
  110. !CompiledMethod methodsFor: 'accessing'!
  111. arguments
  112. <return self.args || []>
  113. !
  114. category
  115. ^(self basicAt: 'category') ifNil: ['']
  116. !
  117. category: aString
  118. | oldCategory |
  119. oldCategory := self category.
  120. self basicAt: 'category' put: aString.
  121. self methodClass ifNotNil: [
  122. self methodClass organization addElement: aString.
  123. (self methodClass methods
  124. select: [ :each | each category = oldCategory ])
  125. ifEmpty: [ self methodClass organization removeElement: oldCategory ] ]
  126. !
  127. fn
  128. ^self basicAt: 'fn'
  129. !
  130. fn: aBlock
  131. self basicAt: 'fn' put: aBlock
  132. !
  133. messageSends
  134. ^self basicAt: 'messageSends'
  135. !
  136. methodClass
  137. ^self basicAt: 'methodClass'
  138. !
  139. protocol
  140. ^ self category
  141. !
  142. referencedClasses
  143. ^self basicAt: 'referencedClasses'
  144. !
  145. selector
  146. ^self basicAt: 'selector'
  147. !
  148. selector: aString
  149. self basicAt: 'selector' put: aString
  150. !
  151. source
  152. ^(self basicAt: 'source') ifNil: ['']
  153. !
  154. source: aString
  155. self basicAt: 'source' put: aString
  156. ! !
  157. Object subclass: #Message
  158. instanceVariableNames: 'selector arguments'
  159. package: 'Kernel-Methods'!
  160. !Message commentStamp!
  161. Generally, the system does not use instances of Message for efficiency reasons.
  162. 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.
  163. This instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.
  164. See boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`!
  165. !Message methodsFor: 'accessing'!
  166. arguments
  167. ^arguments
  168. !
  169. arguments: anArray
  170. arguments := anArray
  171. !
  172. selector
  173. ^selector
  174. !
  175. selector: aString
  176. selector := aString
  177. ! !
  178. !Message methodsFor: 'printing'!
  179. printString
  180. ^ String streamContents: [:aStream|
  181. aStream
  182. nextPutAll: super printString;
  183. nextPutAll: '(';
  184. nextPutAll: selector;
  185. nextPutAll: ')' ]
  186. !
  187. sendTo: anObject
  188. ^ Smalltalk current send: self selector to: anObject arguments: self arguments
  189. ! !
  190. !Message class methodsFor: 'instance creation'!
  191. selector: aString arguments: anArray
  192. ^self new
  193. selector: aString;
  194. arguments: anArray;
  195. yourself
  196. ! !
  197. Object subclass: #MethodContext
  198. instanceVariableNames: ''
  199. package: 'Kernel-Methods'!
  200. !MethodContext commentStamp!
  201. 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.
  202. MethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js
  203. Current limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block.!
  204. !MethodContext methodsFor: 'accessing'!
  205. asString
  206. ^self receiver class printString, ' >> ', self selector
  207. !
  208. home
  209. <return self.homeContext>
  210. !
  211. pc
  212. <return self.pc>
  213. !
  214. printString
  215. ^super printString, '(', self asString, ')'
  216. !
  217. receiver
  218. <return self.receiver>
  219. !
  220. selector
  221. <return smalltalk.convertSelector(self.selector)>
  222. !
  223. temps
  224. <return self.temps>
  225. ! !