Axxord.st 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. Smalltalk createPackage: 'Axxord'!
  2. (Smalltalk packageAt: 'Axxord') imports: {'axxord/Axxord-Axon'}!
  3. Object subclass: #Axes
  4. instanceVariableNames: ''
  5. package: 'Axxord'!
  6. !Axes class methodsFor: 'delegated'!
  7. on: anObject at: aCollection consume: aBlock
  8. | value |
  9. value := anObject atAxes: aCollection ifAbsent: [ ^ anObject ].
  10. ^ aBlock value: value
  11. !
  12. on: anObject at: aCollection ifAbsent: aBlock
  13. ^ aCollection inject: anObject into: [ :soFar :segment |
  14. segment asAxisIn: soFar ifAbsent: [ ^ aBlock value ]]
  15. !
  16. on: anObject at: aCollection ifAbsent: aBlock put: value
  17. | penultimate |
  18. penultimate := anObject atAxes: aCollection allButLast ifAbsent: aBlock.
  19. ^ aCollection last asAxisIn: penultimate ifAbsent: aBlock put: value
  20. !
  21. on: anObject at: aCollection transform: aBlock
  22. | value newValue |
  23. value := anObject atAxes: aCollection ifAbsent: [ ^ anObject ].
  24. newValue := aBlock value: value.
  25. value == newValue ifFalse: [ anObject atAxes: aCollection ifAbsent: [ ^ anObject ] put: newValue ].
  26. anObject axxord ifNotNil: [:axon | axon changed: aCollection]
  27. ! !
  28. !Axes class methodsFor: 'factory'!
  29. newInterestThru: anAspect doing: aBlock
  30. ^ PluggableInterest new
  31. accept: [ :aspect | aspect size <= anAspect size
  32. ifTrue: [ aspect = (anAspect copyFrom: 1 to: aspect size) ]
  33. ifFalse: [ anAspect = (aspect copyFrom: 1 to: anAspect size) ] ]
  34. enact: aBlock
  35. !
  36. newInterestUpTo: anAspect doing: aBlock
  37. ^ PluggableInterest new
  38. accept: [ :changedAspect | changedAspect size <= anAspect size and:
  39. [changedAspect = (anAspect copyFrom: 1 to: changedAspect size)] ]
  40. enact: aBlock
  41. ! !
  42. !Axes class methodsFor: 'parsing'!
  43. parse: message
  44. | result stack anArray |
  45. anArray := message tokenize: ' '.
  46. result := #().
  47. stack := { result }.
  48. anArray do: [ :each |
  49. | asNum inner close |
  50. close := 0.
  51. inner := each.
  52. [ inner notEmpty and: [ inner first = '(' ]] whileTrue: [ inner := inner allButFirst. stack add: (stack last add: #()) ].
  53. [ inner notEmpty and: [ inner last = ')' ]] whileTrue: [ inner := inner allButLast. close := close + 1 ].
  54. (inner notEmpty and: [ inner first = '~' ]) ifTrue: [ inner := { inner allButFirst } ].
  55. asNum := inner isString ifTrue: [ (inner ifEmpty: [ 'NaN' ]) asNumber ] ifFalse: [ inner ].
  56. asNum = asNum ifTrue: [ stack last add: asNum ] ifFalse: [
  57. inner ifNotEmpty: [ stack last add: inner ] ].
  58. close timesRepeat: [ stack removeLast ] ].
  59. ^ result
  60. ! !
  61. Object subclass: #Axolator
  62. instanceVariableNames: 'root'
  63. package: 'Axxord'!
  64. !Axolator methodsFor: 'accessing'!
  65. root
  66. ^root
  67. !
  68. root: anObject
  69. root := anObject
  70. ! !
  71. !Axolator methodsFor: 'action'!
  72. model: anEavModel modify: aBlock
  73. | newValue |
  74. newValue := aBlock value: (anEavModel on: self).
  75. anEavModel on: self put: newValue deepCopy
  76. !
  77. model: anEavModel read: aBlock
  78. aBlock value: (anEavModel on: self) deepCopy
  79. ! !
  80. !Axolator class methodsFor: 'instance creation'!
  81. on: anObject
  82. ^self new root: anObject
  83. ! !
  84. !Array methodsFor: '*Axxord'!
  85. asAxisIn: anObject ifAbsent: aBlock
  86. | receiver selector result |
  87. selector := self first.
  88. receiver := anObject yourself. "JSObjectProxy hack"
  89. [ result := receiver perform: selector ]
  90. on: MessageNotUnderstood do: [ :mnu |
  91. ((mnu message selector = selector
  92. and: [ mnu receiver == receiver ])
  93. and: [ mnu message arguments isEmpty ])
  94. ifFalse: [ mnu resignal ].
  95. ^ aBlock value ].
  96. ^ result
  97. !
  98. asAxisIn: anObject ifAbsent: aBlock put: anotherObject
  99. | receiver selector arguments result |
  100. selector := self first asMutator.
  101. receiver := anObject yourself. "JSObjectProxy hack"
  102. arguments := { anotherObject }.
  103. [ result := receiver perform: selector withArguments: arguments ]
  104. on: MessageNotUnderstood do: [ :mnu |
  105. ((mnu message selector = selector
  106. and: [ mnu receiver == receiver ])
  107. and: [ mnu message arguments = arguments ])
  108. ifFalse: [ mnu resignal ].
  109. ^ aBlock value ].
  110. ^ result
  111. ! !
  112. !JSObjectProxy methodsFor: '*Axxord'!
  113. asAxisIn: anObject ifAbsent: aBlock
  114. ^ aBlock value
  115. !
  116. asAxisIn: anObject ifAbsent: aBlock put: anotherObject
  117. ^ aBlock value
  118. !
  119. atAxes: aCollection ifAbsent: aBlock
  120. ^ Axes on: self at: aCollection ifAbsent: aBlock
  121. !
  122. atAxes: aCollection ifAbsent: aBlock put: value
  123. ^ Axes on: self at: aCollection ifAbsent: aBlock put: value
  124. !
  125. axes: aCollection consume: aBlock
  126. ^ Axes on: self at: aCollection consume: aBlock
  127. !
  128. axes: aCollection transform: aBlock
  129. ^ Axes on: self at: aCollection transform: aBlock
  130. !
  131. axxord
  132. <inlineJS: 'return $self["@jsObject"].$axxord$'>
  133. !
  134. axxord: anAxon
  135. <inlineJS: '$self["@jsObject"].$axxord$ = anAxon'>
  136. ! !
  137. !Number methodsFor: '*Axxord'!
  138. asAxisIn: anObject ifAbsent: aBlock
  139. (anObject respondsTo: #at:ifAbsent:)
  140. ifTrue: [ ^ anObject at: self ifAbsent: aBlock ]
  141. ifFalse: aBlock
  142. !
  143. asAxisIn: anObject ifAbsent: aBlock put: anotherObject
  144. (anObject respondsTo: #at:put:)
  145. ifTrue: [ ^ anObject at: self put: anotherObject ]
  146. ifFalse: aBlock
  147. ! !
  148. !Object methodsFor: '*Axxord'!
  149. asAxisIn: anObject ifAbsent: aBlock
  150. ^ aBlock value
  151. !
  152. asAxisIn: anObject ifAbsent: aBlock put: anotherObject
  153. ^ aBlock value
  154. !
  155. atAxes: aCollection ifAbsent: aBlock
  156. ^ Axes on: self at: aCollection ifAbsent: aBlock
  157. !
  158. atAxes: aCollection ifAbsent: aBlock put: value
  159. ^ Axes on: self at: aCollection ifAbsent: aBlock put: value
  160. !
  161. axes: aCollection consume: aBlock
  162. ^ Axes on: self at: aCollection consume: aBlock
  163. !
  164. axes: aCollection transform: aBlock
  165. ^ Axes on: self at: aCollection transform: aBlock
  166. !
  167. axxord
  168. <inlineJS: 'return self.$axxord$'>
  169. !
  170. axxord: anAxon
  171. <inlineJS: 'self.$axxord$ = anAxon'>
  172. ! !
  173. !String methodsFor: '*Axxord'!
  174. asAxisIn: anObject ifAbsent: aBlock
  175. (anObject respondsTo: #at:ifAbsent:)
  176. ifTrue: [ ^ anObject at: self ifAbsent: aBlock ]
  177. ifFalse: aBlock
  178. !
  179. asAxisIn: anObject ifAbsent: aBlock put: anotherObject
  180. (anObject respondsTo: #at:put:)
  181. ifTrue: [ ^ anObject at: self put: anotherObject ]
  182. ifFalse: aBlock
  183. ! !