Nemo.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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((function(){return (result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_evaluateExpression_", [string]));}), "_on_do_", [(smalltalk.Error || Error), (function(ex){return (function(){throw $early=[smalltalk.send(self['@socket'], "_send_", [smalltalk.send(ex, "_asNemoString", [])])]})();})]);
  94. smalltalk.send(self['@socket'], "_send_", [smalltalk.send(result, "_asNemoString", [])]);
  95. return self;
  96. } catch(e) {if(e===$early)return e[0]; throw e}},
  97. args: ["aMessage"],
  98. source: "handleMessage: aMessage\x0a\x09| string result |\x0a\x0a\x09string := aMessage data.\x0a\x09string isString ifFalse: [ ^ self ].\x0a\x0a\x09[ result := Compiler new evaluateExpression: string ]\x0a\x09\x09on: Error\x0a\x09\x09do: [ :ex | ^ socket send: ex asNemoString ].\x0a\x09socket send: result asNemoString",
  99. messageSends: ["data", "ifFalse:", "isString", "on:do:", "evaluateExpression:", "new", "send:", "asNemoString"],
  100. referencedClasses: ["Compiler", "Error"]
  101. }),
  102. smalltalk.NemoConnection);
  103. smalltalk.addMethod(
  104. "_send_",
  105. smalltalk.method({
  106. selector: "send:",
  107. category: 'not yet classified',
  108. fn: function (aString){
  109. var self=this;
  110. smalltalk.send(self['@socket'], "_send_", [aString]);
  111. return self;},
  112. args: ["aString"],
  113. source: "send: aString\x0a\x09socket send: aString",
  114. messageSends: ["send:"],
  115. referencedClasses: []
  116. }),
  117. smalltalk.NemoConnection);
  118. smalltalk.NemoConnection.klass.iVarNames = ['default'];
  119. smalltalk.addMethod(
  120. "_default",
  121. smalltalk.method({
  122. selector: "default",
  123. category: 'not yet classified',
  124. fn: function (){
  125. var self=this;
  126. return (($receiver = self['@default']) == nil || $receiver == undefined) ? (function(){return (self['@default']=smalltalk.send(self, "_new", []));})() : $receiver;
  127. return self;},
  128. args: [],
  129. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  130. messageSends: ["ifNil:", "new"],
  131. referencedClasses: []
  132. }),
  133. smalltalk.NemoConnection.klass);
  134. smalltalk.addMethod(
  135. "_defaultURL",
  136. smalltalk.method({
  137. selector: "defaultURL",
  138. category: 'not yet classified',
  139. fn: function (){
  140. var self=this;
  141. return "ws://localhost:8010/nemo";
  142. return self;},
  143. args: [],
  144. source: "defaultURL\x0a\x0a\x09^ 'ws://localhost:8010/nemo'",
  145. messageSends: [],
  146. referencedClasses: []
  147. }),
  148. smalltalk.NemoConnection.klass);
  149. smalltalk.addMethod(
  150. "_asNemo",
  151. smalltalk.method({
  152. selector: "asNemo",
  153. category: '*Nemo',
  154. fn: function (){
  155. var self=this;
  156. return smalltalk.send(self, "_asJSON", []);
  157. return self;},
  158. args: [],
  159. source: "asNemo\x0a\x09^ self asJSON",
  160. messageSends: ["asJSON"],
  161. referencedClasses: []
  162. }),
  163. smalltalk.Object);
  164. smalltalk.addMethod(
  165. "_asNemoString",
  166. smalltalk.method({
  167. selector: "asNemoString",
  168. category: '*Nemo',
  169. fn: function (){
  170. var self=this;
  171. return smalltalk.send((smalltalk.JSON || JSON), "_stringify_", [smalltalk.send(self, "_asNemo", [])]);
  172. return self;},
  173. args: [],
  174. source: "asNemoString\x0a\x09^JSON stringify: self asNemo",
  175. messageSends: ["stringify:", "asNemo"],
  176. referencedClasses: ["JSON"]
  177. }),
  178. smalltalk.Object);
  179. smalltalk.addMethod(
  180. "_asNemo",
  181. smalltalk.method({
  182. selector: "asNemo",
  183. category: '*Nemo',
  184. fn: function (){
  185. var self=this;
  186. 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", [])]);smalltalk.send($rec, "_at_put_", ["instVarNames", smalltalk.send(self, "_instanceVariableNames", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  187. return self;},
  188. args: [],
  189. 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\x09at: 'instVarNames' put: self instanceVariableNames;\x0a\x09\x09asNemo",
  190. messageSends: ["at:put:", "name", "ifNotNil:", "superclass", "comment", "definition", "category", "instanceVariableNames", "asNemo", "new"],
  191. referencedClasses: ["Dictionary"]
  192. }),
  193. smalltalk.Class);
  194. smalltalk.addMethod(
  195. "_asNemo",
  196. smalltalk.method({
  197. selector: "asNemo",
  198. category: '*Nemo',
  199. fn: function (){
  200. var self=this;
  201. return (function($rec){smalltalk.send($rec, "_at_put_", ["definition", smalltalk.send(self, "_definition", [])]);smalltalk.send($rec, "_at_put_", ["instVarNames", smalltalk.send(self, "_instanceVariableNames", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  202. return self;},
  203. args: [],
  204. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'definition' put: self definition;\x0a\x09\x09at: 'instVarNames' put: self instanceVariableNames;\x0a\x09\x09asNemo",
  205. messageSends: ["at:put:", "definition", "instanceVariableNames", "asNemo", "new"],
  206. referencedClasses: ["Dictionary"]
  207. }),
  208. smalltalk.Metaclass);
  209. smalltalk.addMethod(
  210. "_asNemo",
  211. smalltalk.method({
  212. selector: "asNemo",
  213. category: '*Nemo',
  214. fn: function (){
  215. var self=this;
  216. return smalltalk.send(smalltalk.send(self, "_asArray", []), "_collect_", [(function(each){return smalltalk.send(each, "_asNemo", []);})]);
  217. return self;},
  218. args: [],
  219. source: "asNemo\x0a\x09^self asArray collect: [:each | each asNemo]",
  220. messageSends: ["collect:", "asArray", "asNemo"],
  221. referencedClasses: []
  222. }),
  223. smalltalk.Collection);
  224. smalltalk.addMethod(
  225. "_asNemo",
  226. smalltalk.method({
  227. selector: "asNemo",
  228. category: '*Nemo',
  229. fn: function (){
  230. var self=this;
  231. var c=nil;
  232. (c=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []));
  233. smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return smalltalk.send(c, "_at_put_", [key, smalltalk.send(value, "_asNemo", [])]);})]);
  234. return c;
  235. return self;},
  236. args: [],
  237. 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",
  238. messageSends: ["new", "class", "keysAndValuesDo:", "at:put:", "asNemo"],
  239. referencedClasses: []
  240. }),
  241. smalltalk.HashedCollection);
  242. smalltalk.addMethod(
  243. "_asNemo",
  244. smalltalk.method({
  245. selector: "asNemo",
  246. category: '*Nemo',
  247. fn: function (){
  248. var self=this;
  249. return smalltalk.send(smalltalk.send(self, "_asHashedCollection", []), "_asNemo", []);
  250. return self;},
  251. args: [],
  252. source: "asNemo\x0a\x09^self asHashedCollection asNemo",
  253. messageSends: ["asNemo", "asHashedCollection"],
  254. referencedClasses: []
  255. }),
  256. smalltalk.Dictionary);
  257. smalltalk.addMethod(
  258. "_asNemo",
  259. smalltalk.method({
  260. selector: "asNemo",
  261. category: '*Nemo',
  262. fn: function (){
  263. var self=this;
  264. return self;
  265. return self;},
  266. args: [],
  267. source: "asNemo\x0a\x09^ self",
  268. messageSends: [],
  269. referencedClasses: []
  270. }),
  271. smalltalk.String);
  272. smalltalk.addMethod(
  273. "_asNemo",
  274. smalltalk.method({
  275. selector: "asNemo",
  276. category: '*Nemo',
  277. fn: function (){
  278. var self=this;
  279. return (function($rec){smalltalk.send($rec, "_at_put_", ["name", smalltalk.send(self, "_selector", [])]);smalltalk.send($rec, "_at_put_", ["protocol", smalltalk.send(self, "_category", [])]);smalltalk.send($rec, "_at_put_", ["sourceCode", smalltalk.send(self, "_source", [])]);smalltalk.send($rec, "_at_put_", ["compiledSource", smalltalk.send(smalltalk.send(self, "_fn", []), "_compiledSource", [])]);smalltalk.send($rec, "_at_put_", ["messageSends", smalltalk.send(self, "_messageSends", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  280. return self;},
  281. args: [],
  282. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'name' put: self selector;\x0a\x09\x09at: 'protocol' put: self category;\x0a\x09\x09at: 'sourceCode' put: self source;\x0a\x09\x09at: 'compiledSource' put: self fn compiledSource;\x0a\x09\x09at: 'messageSends' put: self messageSends;\x0a\x09\x09asNemo",
  283. messageSends: ["at:put:", "selector", "category", "source", "compiledSource", "fn", "messageSends", "asNemo", "new"],
  284. referencedClasses: ["Dictionary"]
  285. }),
  286. smalltalk.CompiledMethod);
  287. smalltalk.addMethod(
  288. "_asNemo",
  289. smalltalk.method({
  290. selector: "asNemo",
  291. category: '*Nemo',
  292. fn: function (){
  293. var self=this;
  294. return (function($rec){smalltalk.send($rec, "_at_put_", ["error", smalltalk.send(self, "_messageText", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  295. return self;},
  296. args: [],
  297. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'error' put: self messageText;\x0a\x09\x09asNemo",
  298. messageSends: ["at:put:", "messageText", "asNemo", "new"],
  299. referencedClasses: ["Dictionary"]
  300. }),
  301. smalltalk.Error);
  302. smalltalk.addMethod(
  303. "_asNemo",
  304. smalltalk.method({
  305. selector: "asNemo",
  306. category: '*Nemo',
  307. fn: function (){
  308. var self=this;
  309. return (function($rec){smalltalk.send($rec, "_at_put_", ["name", smalltalk.send(self, "_name", [])]);return smalltalk.send($rec, "_asNemo", []);})(smalltalk.send((smalltalk.Dictionary || Dictionary), "_new", []));
  310. return self;},
  311. args: [],
  312. source: "asNemo\x0a\x09^ Dictionary new\x0a\x09\x09at: 'name' put: self name;\x0a\x09\x09asNemo",
  313. messageSends: ["at:put:", "name", "asNemo", "new"],
  314. referencedClasses: ["Dictionary"]
  315. }),
  316. smalltalk.Package);