Trapped-Backend.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. smalltalk.addPackage('Trapped-Backend', {});
  2. smalltalk.addClass('EavModel', smalltalk.Object, ['getBlock', 'putBlock'], 'Trapped-Backend');
  3. smalltalk.EavModel.comment="External actor value model."
  4. smalltalk.addMethod(
  5. "_getBlock_",
  6. smalltalk.method({
  7. selector: "getBlock:",
  8. category: 'accessing',
  9. fn: function (aBlock){
  10. var self=this;
  11. self["@getBlock"]=aBlock;
  12. return self},
  13. args: ["aBlock"],
  14. source: "getBlock: aBlock\x0a\x0agetBlock := aBlock",
  15. messageSends: [],
  16. referencedClasses: []
  17. }),
  18. smalltalk.EavModel);
  19. smalltalk.addMethod(
  20. "_initialize",
  21. smalltalk.method({
  22. selector: "initialize",
  23. category: 'initialization',
  24. fn: function (){
  25. var self=this;
  26. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  27. self["@getBlock"]=(function(){
  28. return smalltalk.send(self,"_error_",["No getter block."]);
  29. });
  30. self["@putBlock"]=(function(){
  31. return smalltalk.send(self,"_error_",["No putter block."]);
  32. });
  33. return self},
  34. args: [],
  35. source: "initialize\x0a\x09super initialize.\x0a\x09getBlock := [ self error: 'No getter block.' ].\x0a\x09putBlock := [ self error: 'No putter block.' ].",
  36. messageSends: ["initialize", "error:"],
  37. referencedClasses: []
  38. }),
  39. smalltalk.EavModel);
  40. smalltalk.addMethod(
  41. "_on_",
  42. smalltalk.method({
  43. selector: "on:",
  44. category: 'accessing',
  45. fn: function (anObject){
  46. var self=this;
  47. var $1;
  48. $1=smalltalk.send(self["@getBlock"],"_value_",[anObject]);
  49. return $1;
  50. },
  51. args: ["anObject"],
  52. source: "on: anObject\x0a\x22Returns value of model applied on object\x22\x0a\x0a^getBlock value: anObject",
  53. messageSends: ["value:"],
  54. referencedClasses: []
  55. }),
  56. smalltalk.EavModel);
  57. smalltalk.addMethod(
  58. "_on_put_",
  59. smalltalk.method({
  60. selector: "on:put:",
  61. category: 'accessing',
  62. fn: function (anObject,anObject2){
  63. var self=this;
  64. var $1;
  65. $1=smalltalk.send(self["@putBlock"],"_value_value_",[anObject,anObject2]);
  66. return $1;
  67. },
  68. args: ["anObject", "anObject2"],
  69. source: "on: anObject put: anObject2\x0a\x22Puts a value via model applied on object\x22\x0a\x0a^putBlock value: anObject value: anObject2",
  70. messageSends: ["value:value:"],
  71. referencedClasses: []
  72. }),
  73. smalltalk.EavModel);
  74. smalltalk.addMethod(
  75. "_putBlock_",
  76. smalltalk.method({
  77. selector: "putBlock:",
  78. category: 'accessing',
  79. fn: function (aBlock){
  80. var self=this;
  81. self["@putBlock"]=aBlock;
  82. return self},
  83. args: ["aBlock"],
  84. source: "putBlock: aBlock\x0a\x0aputBlock := aBlock",
  85. messageSends: [],
  86. referencedClasses: []
  87. }),
  88. smalltalk.EavModel);
  89. smalltalk.addClass('Isolator', smalltalk.Object, ['root'], 'Trapped-Backend');
  90. smalltalk.addMethod(
  91. "_model_modify_",
  92. smalltalk.method({
  93. selector: "model:modify:",
  94. category: 'action',
  95. fn: function (anEavModel,aBlock){
  96. var self=this;
  97. var newValue;
  98. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(anEavModel,"_on_",[self])]);
  99. smalltalk.send(anEavModel,"_on_put_",[self,smalltalk.send(newValue,"_deepCopy",[])]);
  100. return self},
  101. args: ["anEavModel", "aBlock"],
  102. source: "model: anEavModel modify: aBlock\x0a\x0a| newValue |\x0anewValue := aBlock value: (anEavModel on: self).\x0aanEavModel on: self put: newValue deepCopy\x0a",
  103. messageSends: ["value:", "on:", "on:put:", "deepCopy"],
  104. referencedClasses: []
  105. }),
  106. smalltalk.Isolator);
  107. smalltalk.addMethod(
  108. "_model_read_",
  109. smalltalk.method({
  110. selector: "model:read:",
  111. category: 'action',
  112. fn: function (anEavModel,aBlock){
  113. var self=this;
  114. smalltalk.send(aBlock,"_value_",[smalltalk.send(smalltalk.send(anEavModel,"_on_",[self]),"_deepCopy",[])]);
  115. return self},
  116. args: ["anEavModel", "aBlock"],
  117. source: "model: anEavModel read: aBlock\x0a\x0aaBlock value: (anEavModel on: self) deepCopy",
  118. messageSends: ["value:", "deepCopy", "on:"],
  119. referencedClasses: []
  120. }),
  121. smalltalk.Isolator);
  122. smalltalk.addMethod(
  123. "_root",
  124. smalltalk.method({
  125. selector: "root",
  126. category: 'accessing',
  127. fn: function (){
  128. var self=this;
  129. return self["@root"];
  130. },
  131. args: [],
  132. source: "root\x0a\x0a^root\x0a",
  133. messageSends: [],
  134. referencedClasses: []
  135. }),
  136. smalltalk.Isolator);
  137. smalltalk.addMethod(
  138. "_root_",
  139. smalltalk.method({
  140. selector: "root:",
  141. category: 'accessing',
  142. fn: function (anObject){
  143. var self=this;
  144. self["@root"]=anObject;
  145. return self},
  146. args: ["anObject"],
  147. source: "root: anObject\x0a\x0aroot := anObject",
  148. messageSends: [],
  149. referencedClasses: []
  150. }),
  151. smalltalk.Isolator);
  152. smalltalk.addMethod(
  153. "_on_",
  154. smalltalk.method({
  155. selector: "on:",
  156. category: 'instance creation',
  157. fn: function (anObject){
  158. var self=this;
  159. var $1;
  160. $1=smalltalk.send(smalltalk.send(self,"_new",[]),"_root_",[anObject]);
  161. return $1;
  162. },
  163. args: ["anObject"],
  164. source: "on: anObject\x0a^self new root: anObject",
  165. messageSends: ["root:", "new"],
  166. referencedClasses: []
  167. }),
  168. smalltalk.Isolator.klass);
  169. smalltalk.addMethod(
  170. "_reverseTrapAt_",
  171. smalltalk.method({
  172. selector: "reverseTrapAt:",
  173. category: '*Trapped-Backend',
  174. fn: function (anObject){
  175. var self=this;
  176. return nil;
  177. },
  178. args: ["anObject"],
  179. source: "reverseTrapAt: anObject\x0a\x09^nil",
  180. messageSends: [],
  181. referencedClasses: []
  182. }),
  183. smalltalk.Object);
  184. smalltalk.addMethod(
  185. "_reverseTrapAt_put_",
  186. smalltalk.method({
  187. selector: "reverseTrapAt:put:",
  188. category: '*Trapped-Backend',
  189. fn: function (anObject,value){
  190. var self=this;
  191. smalltalk.send(self,"_error_",[smalltalk.send(smalltalk.send("Trapped cannot put at ","__comma",[smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[])]),"__comma",[" type key."])]);
  192. return self},
  193. args: ["anObject", "value"],
  194. source: "reverseTrapAt: anObject put: value\x0a\x09self error: 'Trapped cannot put at ', self class name, ' type key.'",
  195. messageSends: ["error:", ",", "name", "class"],
  196. referencedClasses: []
  197. }),
  198. smalltalk.Object);
  199. smalltalk.addMethod(
  200. "_asEavModel",
  201. smalltalk.method({
  202. selector: "asEavModel",
  203. category: '*Trapped-Backend',
  204. fn: function (){
  205. var self=this;
  206. var $1;
  207. var model;
  208. model=smalltalk.send((smalltalk.EavModel || EavModel),"_new",[]);
  209. smalltalk.send(model,"_getBlock_",[(function(anObject){
  210. return smalltalk.send(self,"_inject_into_",[anObject,(function(soFar,segment){
  211. if(($receiver = soFar) == nil || $receiver == undefined){
  212. return soFar;
  213. } else {
  214. return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
  215. };
  216. })]);
  217. })]);
  218. $1=smalltalk.send(self,"_isEmpty",[]);
  219. if(! smalltalk.assert($1)){
  220. smalltalk.send(model,"_putBlock_",[(function(anObject,value){
  221. var penultimate;
  222. penultimate=smalltalk.send(smalltalk.send(self,"_allButLast",[]),"_inject_into_",[anObject,(function(soFar,segment){
  223. if(($receiver = soFar) == nil || $receiver == undefined){
  224. return soFar;
  225. } else {
  226. return smalltalk.send(segment,"_reverseTrapAt_",[soFar]);
  227. };
  228. })]);
  229. penultimate;
  230. return smalltalk.send(smalltalk.send(self,"_last",[]),"_reverseTrapAt_put_",[penultimate,value]);
  231. })]);
  232. };
  233. return model;
  234. },
  235. args: [],
  236. source: "asEavModel\x0a | model |\x0a model := EavModel new.\x0a model getBlock: [ :anObject |\x0a self inject: anObject into: [ :soFar :segment |\x0a soFar ifNotNil: [ segment reverseTrapAt: soFar ]]].\x0a self isEmpty ifFalse: [\x0a model putBlock: [ :anObject :value | | penultimate |\x0a penultimate := self allButLast inject: anObject into: [ :soFar :segment |\x0a soFar ifNotNil: [ segment reverseTrapAt: soFar ]].\x0a self last reverseTrapAt: penultimate put: value ]].\x0a ^model",
  237. messageSends: ["new", "getBlock:", "inject:into:", "ifNotNil:", "reverseTrapAt:", "ifFalse:", "putBlock:", "allButLast", "reverseTrapAt:put:", "last", "isEmpty"],
  238. referencedClasses: ["EavModel"]
  239. }),
  240. smalltalk.SequenceableCollection);
  241. smalltalk.addMethod(
  242. "_reverseTrapAt_",
  243. smalltalk.method({
  244. selector: "reverseTrapAt:",
  245. category: '*Trapped-Backend',
  246. fn: function (anObject){
  247. var self=this;
  248. var $1;
  249. $1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
  250. return nil;
  251. })]);
  252. return $1;
  253. },
  254. args: ["anObject"],
  255. source: "reverseTrapAt: anObject\x0a\x09^anObject at: self ifAbsent: [nil]",
  256. messageSends: ["at:ifAbsent:"],
  257. referencedClasses: []
  258. }),
  259. smalltalk.String);
  260. smalltalk.addMethod(
  261. "_reverseTrapAt_put_",
  262. smalltalk.method({
  263. selector: "reverseTrapAt:put:",
  264. category: '*Trapped-Backend',
  265. fn: function (anObject,value){
  266. var self=this;
  267. var $1;
  268. $1=smalltalk.send(anObject,"_at_put_",[self,value]);
  269. return $1;
  270. },
  271. args: ["anObject", "value"],
  272. source: "reverseTrapAt: anObject put: value\x0a\x09^anObject at: self put: value",
  273. messageSends: ["at:put:"],
  274. referencedClasses: []
  275. }),
  276. smalltalk.String);
  277. smalltalk.addMethod(
  278. "_reverseTrapAt_",
  279. smalltalk.method({
  280. selector: "reverseTrapAt:",
  281. category: '*Trapped-Backend',
  282. fn: function (anObject){
  283. var self=this;
  284. var $1;
  285. var $early={};
  286. try {
  287. $1=smalltalk.send((function(){
  288. return smalltalk.send(anObject,"_perform_",[self]);
  289. }),"_on_do_",[(smalltalk.MessageNotUnderstood || MessageNotUnderstood),(function(){
  290. throw $early=[nil];
  291. })]);
  292. return $1;
  293. }
  294. catch(e) {if(e===$early)return e[0]; throw e}
  295. },
  296. args: ["anObject"],
  297. source: "reverseTrapAt: anObject\x0a\x09^[anObject perform: self] on: MessageNotUnderstood do: [^nil]",
  298. messageSends: ["on:do:", "perform:"],
  299. referencedClasses: ["MessageNotUnderstood"]
  300. }),
  301. smalltalk.Symbol);
  302. smalltalk.addMethod(
  303. "_reverseTrapAt_put_",
  304. smalltalk.method({
  305. selector: "reverseTrapAt:put:",
  306. category: '*Trapped-Backend',
  307. fn: function (anObject,value){
  308. var self=this;
  309. var $1;
  310. $1=smalltalk.send(anObject,"_perform_withArguments_",[smalltalk.send(smalltalk.send(self,"__comma",[":"]),"_asSymbol",[]),[value]]);
  311. return $1;
  312. },
  313. args: ["anObject", "value"],
  314. source: "reverseTrapAt: anObject put: value\x0a ^anObject perform: (self, ':') asSymbol withArguments: { value }",
  315. messageSends: ["perform:withArguments:", "asSymbol", ","],
  316. referencedClasses: []
  317. }),
  318. smalltalk.Symbol);
  319. smalltalk.addMethod(
  320. "_reverseTrapAt_",
  321. smalltalk.method({
  322. selector: "reverseTrapAt:",
  323. category: '*Trapped-Backend',
  324. fn: function (anObject){
  325. var self=this;
  326. var $1;
  327. $1=smalltalk.send(anObject,"_at_ifAbsent_",[self,(function(){
  328. return nil;
  329. })]);
  330. return $1;
  331. },
  332. args: ["anObject"],
  333. source: "reverseTrapAt: anObject\x0a\x09^anObject at: self ifAbsent: [nil]",
  334. messageSends: ["at:ifAbsent:"],
  335. referencedClasses: []
  336. }),
  337. smalltalk.Number);
  338. smalltalk.addMethod(
  339. "_reverseTrapAt_put_",
  340. smalltalk.method({
  341. selector: "reverseTrapAt:put:",
  342. category: '*Trapped-Backend',
  343. fn: function (anObject,value){
  344. var self=this;
  345. var $1;
  346. $1=smalltalk.send(anObject,"_at_put_",[self,value]);
  347. return $1;
  348. },
  349. args: ["anObject", "value"],
  350. source: "reverseTrapAt: anObject put: value\x0a\x09^anObject at: self put: value",
  351. messageSends: ["at:put:"],
  352. referencedClasses: []
  353. }),
  354. smalltalk.Number);