Kernel-Methods.st 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. Smalltalk current createPackage: 'Kernel-Methods' properties: #{}!
  2. Object subclass: #CompiledMethod
  3. instanceVariableNames: ''
  4. category: 'Kernel-Methods'!
  5. !CompiledMethod methodsFor: 'accessing'!
  6. source
  7. ^(self basicAt: 'source') ifNil: ['']
  8. !
  9. source: aString
  10. self basicAt: 'source' put: aString
  11. !
  12. category
  13. ^(self basicAt: 'category') ifNil: ['']
  14. !
  15. category: aString
  16. self basicAt: 'category' put: aString
  17. !
  18. selector
  19. ^self basicAt: 'selector'
  20. !
  21. selector: aString
  22. self basicAt: 'selector' put: aString
  23. !
  24. fn
  25. ^self basicAt: 'fn'
  26. !
  27. fn: aBlock
  28. self basicAt: 'fn' put: aBlock
  29. !
  30. messageSends
  31. ^self basicAt: 'messageSends'
  32. !
  33. methodClass
  34. ^self basicAt: 'methodClass'
  35. !
  36. referencedClasses
  37. ^self basicAt: 'referencedClasses'
  38. !
  39. arguments
  40. <return self.args || []>
  41. ! !
  42. Object subclass: #BlockClosure
  43. instanceVariableNames: ''
  44. category: 'Kernel-Methods'!
  45. !BlockClosure commentStamp!
  46. A BlockClosure is a lexical closure.
  47. The JavaScript representation is a function.
  48. A BlockClosure is evaluated with the #value* methods in the 'evaluating' protocol.!
  49. !BlockClosure methodsFor: 'accessing'!
  50. compiledSource
  51. <return self.toString()>
  52. !
  53. numArgs
  54. <return self.length>
  55. ! !
  56. !BlockClosure methodsFor: 'controlling'!
  57. whileTrue: aBlock
  58. "inlined in the Compiler"
  59. <while(self()) {aBlock()}>
  60. !
  61. whileFalse: aBlock
  62. "inlined in the Compiler"
  63. <while(!!self()) {aBlock()}>
  64. !
  65. whileFalse
  66. "inlined in the Compiler"
  67. self whileFalse: []
  68. !
  69. whileTrue
  70. "inlined in the Compiler"
  71. self whileTrue: []
  72. ! !
  73. !BlockClosure methodsFor: 'error handling'!
  74. on: anErrorClass do: aBlock
  75. ^self try: self catch: [:error |
  76. (error isKindOf: anErrorClass)
  77. ifTrue: [aBlock value: error]
  78. ifFalse: [error signal]]
  79. ! !
  80. !BlockClosure methodsFor: 'evaluating'!
  81. value
  82. "inlined in the Compiler"
  83. <return self();>
  84. !
  85. value: anArg
  86. "inlined in the Compiler"
  87. <return self(anArg);>
  88. !
  89. value: firstArg value: secondArg
  90. "inlined in the Compiler"
  91. <return self(firstArg, secondArg);>
  92. !
  93. value: firstArg value: secondArg value: thirdArg
  94. "inlined in the Compiler"
  95. <return self(firstArg, secondArg, thirdArg);>
  96. !
  97. valueWithPossibleArguments: aCollection
  98. <return self.apply(null, aCollection);>
  99. !
  100. new
  101. "Use the receiver as a JS constructor.
  102. *Do not* use this method to instanciate Smalltalk objects!!"
  103. <return new self()>
  104. !
  105. applyTo: anObject arguments: aCollection
  106. <return self.apply(anObject, aCollection)>
  107. !
  108. timeToRun
  109. "Answer the number of milliseconds taken to execute this block."
  110. ^ Date millisecondsToRun: self
  111. !
  112. ensure: aBlock
  113. | success |
  114. success := false.
  115. ^[self value. success := true. aBlock value]
  116. on: Error
  117. do: [:ex |
  118. success ifFalse: [aBlock value].
  119. ex signal]
  120. ! !
  121. !BlockClosure methodsFor: 'timeout/interval'!
  122. valueWithTimeout: aNumber
  123. <return setTimeout(self, aNumber)>
  124. !
  125. valueWithInterval: aNumber
  126. <return setInterval(self, aNumber)>
  127. ! !
  128. Object subclass: #MethodContext
  129. instanceVariableNames: ''
  130. category: 'Kernel-Methods'!
  131. !MethodContext methodsFor: 'accessing'!
  132. receiver
  133. <return self.receiver>
  134. !
  135. selector
  136. <return smalltalk.convertSelector(self.selector)>
  137. !
  138. home
  139. <return self.homeContext>
  140. !
  141. temps
  142. <return self.temps>
  143. !
  144. printString
  145. ^super printString, '(', self asString, ')'
  146. !
  147. asString
  148. ^self receiver class printString, ' >> ', self selector
  149. ! !
  150. Object subclass: #Message
  151. instanceVariableNames: 'selector arguments'
  152. category: 'Kernel-Methods'!
  153. !Message methodsFor: 'accessing'!
  154. selector
  155. ^selector
  156. !
  157. selector: aString
  158. selector := aString
  159. !
  160. arguments: anArray
  161. arguments := anArray
  162. !
  163. arguments
  164. ^arguments
  165. ! !
  166. !Message methodsFor: 'printing'!
  167. printString
  168. ^ String streamContents: [:aStream|
  169. aStream
  170. nextPutAll: super printString;
  171. nextPutAll: '(';
  172. nextPutAll: selector;
  173. nextPutAll: ')' ]
  174. ! !
  175. !Message class methodsFor: 'instance creation'!
  176. selector: aString arguments: anArray
  177. ^self new
  178. selector: aString;
  179. arguments: anArray;
  180. yourself
  181. ! !