Nemo.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. smalltalk.addPackage('Nemo', {});
  2. smalltalk.addClass('NemoConnection', smalltalk.Object, ['socket'], 'Nemo');
  3. smalltalk.addMethod(
  4. "_close",
  5. smalltalk.method({
  6. selector: "close",
  7. category: 'not yet classified',
  8. fn: function (){
  9. var self=this;
  10. smalltalk.send(self['@socket'], "_close", []);
  11. (self['@socket']=nil);
  12. return self;},
  13. args: [],
  14. source: "close\x0a\x09socket close.\x0a\x09socket := nil",
  15. messageSends: ["close"],
  16. referencedClasses: []
  17. }),
  18. smalltalk.NemoConnection);
  19. smalltalk.addMethod(
  20. "_createDefaultSocket",
  21. smalltalk.method({
  22. selector: "createDefaultSocket",
  23. category: 'not yet classified',
  24. fn: function (){
  25. var self=this;
  26. smalltalk.send(self, "_createSocketOn_", [smalltalk.send(self, "_defaultURL", [])]);
  27. return self;},
  28. args: [],
  29. source: "createDefaultSocket\x0a\x09\x0a\x09self createSocketOn: self defaultURL.",
  30. messageSends: ["createSocketOn:", "defaultURL"],
  31. referencedClasses: []
  32. }),
  33. smalltalk.NemoConnection);
  34. smalltalk.addMethod(
  35. "_createLocalSocketOn_",
  36. smalltalk.method({
  37. selector: "createLocalSocketOn:",
  38. category: 'not yet classified',
  39. fn: function (aPort){
  40. var self=this;
  41. return smalltalk.send(self, "_createSocketOn_", [smalltalk.send(smalltalk.send("ws://localhost:", "__comma", [smalltalk.send(aPort, "_asString", [])]), "__comma", ["/nemo"])]);
  42. return self;},
  43. args: ["aPort"],
  44. source: "createLocalSocketOn: aPort\x0a\x0a\x09^ self createSocketOn: 'ws://localhost:',aPort asString,'/nemo'",
  45. messageSends: ["createSocketOn:", ",", "asString"],
  46. referencedClasses: []
  47. }),
  48. smalltalk.NemoConnection);
  49. smalltalk.addMethod(
  50. "_createSocketOn_",
  51. smalltalk.method({
  52. selector: "createSocketOn:",
  53. category: 'not yet classified',
  54. fn: function (uri){
  55. var self=this;
  56. (self['@socket']=new WebSocket(uri));
  57. smalltalk.send(self['@socket'], "_at_put_", ["onmessage", (function(message){return smalltalk.send(self, "_handleMessage_", [message]);})]);
  58. smalltalk.send(self['@socket'], "_at_put_", ["onerror", (function(err){return smalltalk.send((typeof console == 'undefined' ? nil : console), "_log_", [err]);})]);
  59. return self;},
  60. args: ["uri"],
  61. source: "createSocketOn: uri\x0a\x09socket := <new WebSocket(uri)>.\x0a\x09socket at: 'onmessage' put: [ :message | self handleMessage: message ].\x0a\x09socket at: 'onerror' put: [ :err | console log: err ]",
  62. messageSends: ["at:put:", "handleMessage:", "log:"],
  63. referencedClasses: []
  64. }),
  65. smalltalk.NemoConnection);
  66. smalltalk.addMethod(
  67. "_defaultURL",
  68. smalltalk.method({
  69. selector: "defaultURL",
  70. category: 'not yet classified',
  71. fn: function (){
  72. var self=this;
  73. return smalltalk.send(smalltalk.send(self, "_class", []), "_defaultURL", []);
  74. return self;},
  75. args: [],
  76. source: "defaultURL\x0a\x0a\x09^ self class defaultURL",
  77. messageSends: ["defaultURL", "class"],
  78. referencedClasses: []
  79. }),
  80. smalltalk.NemoConnection);
  81. smalltalk.addMethod(
  82. "_handleMessage_",
  83. smalltalk.method({
  84. selector: "handleMessage:",
  85. category: 'not yet classified',
  86. fn: function (aMessage){
  87. var self=this;
  88. var $early={};
  89. try{var string=nil;
  90. var result=nil;
  91. (string=smalltalk.send(aMessage, "_data", []));
  92. ((($receiver = smalltalk.send(string, "_isString", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw $early=[self]})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw $early=[self]})();})]));
  93. smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [string]);
  94. (result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_evaluateExpression_", [string]));
  95. smalltalk.send((typeof console == 'undefined' ? nil : console), "_log_", [result]);
  96. smalltalk.send((typeof console == 'undefined' ? nil : console), "_log_", [smalltalk.send(result, "_asNemoString", [])]);
  97. smalltalk.send(self['@socket'], "_send_", [smalltalk.send(result, "_asNemoString", [])]);
  98. return self;
  99. } catch(e) {if(e===$early)return e[0]; throw e}},
  100. args: ["aMessage"],
  101. source: "handleMessage: aMessage\x0a\x09| string result |\x0a\x0a\x09string := aMessage data.\x0a\x09string isString ifFalse: [ ^ self ].\x0a\x0a\x09Transcript show: string.\x0a\x0a\x09result := Compiler new evaluateExpression: string.\x0a\x09console log: result.\x0a\x09console log: result asNemoString.\x0a\x09socket send: result asNemoString",
  102. messageSends: ["data", "ifFalse:", "isString", "show:", "evaluateExpression:", "new", "log:", "asNemoString", "send:"],
  103. referencedClasses: ["Transcript", "Compiler"]
  104. }),
  105. smalltalk.NemoConnection);
  106. smalltalk.addMethod(
  107. "_send_",
  108. smalltalk.method({
  109. selector: "send:",
  110. category: 'not yet classified',
  111. fn: function (aString){
  112. var self=this;
  113. smalltalk.send(self['@socket'], "_send_", [aString]);
  114. return self;},
  115. args: ["aString"],
  116. source: "send: aString\x0a\x09socket send: aString",
  117. messageSends: ["send:"],
  118. referencedClasses: []
  119. }),
  120. smalltalk.NemoConnection);
  121. smalltalk.NemoConnection.klass.iVarNames = ['default'];
  122. smalltalk.addMethod(
  123. "_default",
  124. smalltalk.method({
  125. selector: "default",
  126. category: 'not yet classified',
  127. fn: function (){
  128. var self=this;
  129. return (($receiver = self['@default']) == nil || $receiver == undefined) ? (function(){return (self['@default']=smalltalk.send(self, "_new", []));})() : $receiver;
  130. return self;},
  131. args: [],
  132. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  133. messageSends: ["ifNil:", "new"],
  134. referencedClasses: []
  135. }),
  136. smalltalk.NemoConnection.klass);
  137. smalltalk.addMethod(
  138. "_defaultURL",
  139. smalltalk.method({
  140. selector: "defaultURL",
  141. category: 'not yet classified',
  142. fn: function (){
  143. var self=this;
  144. return "ws://localhost:8010/nemo";
  145. return self;},
  146. args: [],
  147. source: "defaultURL\x0a\x0a\x09^ 'ws://localhost:8010/nemo'",
  148. messageSends: [],
  149. referencedClasses: []
  150. }),
  151. smalltalk.NemoConnection.klass);
  152. smalltalk.addMethod(
  153. "_asNemo",
  154. smalltalk.method({
  155. selector: "asNemo",
  156. category: '*Nemo',
  157. fn: function (){
  158. var self=this;
  159. return smalltalk.send(self, "_asJSON", []);
  160. return self;},
  161. args: [],
  162. source: "asNemo\x0a\x09^ self asJSON",
  163. messageSends: ["asJSON"],
  164. referencedClasses: []
  165. }),
  166. smalltalk.Object);
  167. smalltalk.addMethod(
  168. "_asNemoString",
  169. smalltalk.method({
  170. selector: "asNemoString",
  171. category: '*Nemo',
  172. fn: function (){
  173. var self=this;
  174. return smalltalk.send((smalltalk.JSON || JSON), "_stringify_", [smalltalk.send(self, "_asNemo", [])]);
  175. return self;},
  176. args: [],
  177. source: "asNemoString\x0a\x09^JSON stringify: self asNemo",
  178. messageSends: ["stringify:", "asNemo"],
  179. referencedClasses: ["JSON"]
  180. }),
  181. smalltalk.Object);
  182. smalltalk.addMethod(
  183. "_asNemo",
  184. smalltalk.method({
  185. selector: "asNemo",
  186. category: '*Nemo',
  187. fn: function (){
  188. var self=this;
  189. return (function($rec){smalltalk.send($rec, "_at_put_", ["name", smalltalk.send(self, "_name", [])]);smalltalk.send($rec, "_at_put_", ["superclass", (($receiver = smalltalk.send(self, "_superclass", [])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(smalltalk.send(self, "_superclass", []), "_name", []);})() : nil]);smalltalk.send($rec, "_at_put_", ["classComment", smalltalk.send(self, "_comment", [])]);smalltalk.send($rec, "_at_put_", ["definition", smalltalk.send(self, "_definition", [])]);smalltalk.send($rec, "_at_put_", ["package", smalltalk.send(self, "_category", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  190. return self;},
  191. args: [],
  192. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'name' put: self name;\x0a\x09\x09at: 'superclass' put: (self superclass ifNotNil: [ self superclass name ]);\x0a\x09\x09at: 'classComment' put: self comment;\x0a\x09\x09at: 'definition' put: self definition;\x0a\x09\x09at: 'package' put: self category;\x0a\x09\x09asNemo",
  193. messageSends: ["at:put:", "name", "ifNotNil:", "superclass", "comment", "definition", "category", "asNemo", "new"],
  194. referencedClasses: ["Dictionary"]
  195. }),
  196. smalltalk.Class);
  197. smalltalk.addMethod(
  198. "_asNemo",
  199. smalltalk.method({
  200. selector: "asNemo",
  201. category: '*Nemo',
  202. fn: function (){
  203. var self=this;
  204. return smalltalk.send(smalltalk.send(self, "_asArray", []), "_collect_", [(function(each){return smalltalk.send(each, "_asNemo", []);})]);
  205. return self;},
  206. args: [],
  207. source: "asNemo\x0a\x09^self asArray collect: [:each | each asNemo]",
  208. messageSends: ["collect:", "asArray", "asNemo"],
  209. referencedClasses: []
  210. }),
  211. smalltalk.Collection);
  212. smalltalk.addMethod(
  213. "_asNemo",
  214. smalltalk.method({
  215. selector: "asNemo",
  216. category: '*Nemo',
  217. fn: function (){
  218. var self=this;
  219. var c=nil;
  220. (c=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []));
  221. smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return smalltalk.send(c, "_at_put_", [key, smalltalk.send(value, "_asNemo", [])]);})]);
  222. return c;
  223. return self;},
  224. args: [],
  225. source: "asNemo\x0a\x09| c |\x0a\x09c := self class new.\x0a\x09self keysAndValuesDo: [:key :value |\x0a\x09\x09c at: key put: value asNemo].\x0a\x09^c",
  226. messageSends: ["new", "class", "keysAndValuesDo:", "at:put:", "asNemo"],
  227. referencedClasses: []
  228. }),
  229. smalltalk.HashedCollection);
  230. smalltalk.addMethod(
  231. "_asNemo",
  232. smalltalk.method({
  233. selector: "asNemo",
  234. category: '*Nemo',
  235. fn: function (){
  236. var self=this;
  237. return smalltalk.send(smalltalk.send(self, "_asHashedCollection", []), "_asNemo", []);
  238. return self;},
  239. args: [],
  240. source: "asNemo\x0a\x09^self asHashedCollection asNemo",
  241. messageSends: ["asNemo", "asHashedCollection"],
  242. referencedClasses: []
  243. }),
  244. smalltalk.Dictionary);
  245. smalltalk.addMethod(
  246. "_asNemo",
  247. smalltalk.method({
  248. selector: "asNemo",
  249. category: '*Nemo',
  250. fn: function (){
  251. var self=this;
  252. return self;
  253. return self;},
  254. args: [],
  255. source: "asNemo\x0a\x09^ self",
  256. messageSends: [],
  257. referencedClasses: []
  258. }),
  259. smalltalk.String);
  260. smalltalk.addMethod(
  261. "_asNemo",
  262. smalltalk.method({
  263. selector: "asNemo",
  264. category: '*Nemo',
  265. fn: function (){
  266. var self=this;
  267. return (function($rec){smalltalk.send($rec, "_at_put_", ["name", smalltalk.send(self, "_name", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  268. return self;},
  269. args: [],
  270. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'name' put: self name;\x0a\x09\x09asNemo",
  271. messageSends: ["at:put:", "name", "asNemo", "new"],
  272. referencedClasses: ["Dictionary"]
  273. }),
  274. smalltalk.Package);