1
0

Kernel-Methods.st 6.0 KB

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