AmberRack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +74 -0
  2. data/.rvmrc +4 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +62 -0
  5. data/README.md +17 -0
  6. data/Rakefile +24 -0
  7. data/amber-rack.gemspec +33 -0
  8. data/app/amber_app.rb +35 -0
  9. data/app/javascripts/Benchfib.deploy.js +159 -0
  10. data/app/javascripts/Benchfib.js +159 -0
  11. data/app/javascripts/Canvas.deploy.js +1464 -0
  12. data/app/javascripts/Canvas.js +1464 -0
  13. data/app/javascripts/Compiler.deploy.js +1587 -0
  14. data/app/javascripts/Compiler.js +1587 -0
  15. data/app/javascripts/Examples.deploy.js +800 -0
  16. data/app/javascripts/Examples.js +800 -0
  17. data/app/javascripts/IDE.deploy.js +3457 -0
  18. data/app/javascripts/IDE.js +3457 -0
  19. data/app/javascripts/IDE.js.bak +3420 -0
  20. data/app/javascripts/JQuery.deploy.js +898 -0
  21. data/app/javascripts/JQuery.js +898 -0
  22. data/app/javascripts/Kernel.deploy.js +6761 -0
  23. data/app/javascripts/Kernel.js +6761 -0
  24. data/app/javascripts/Parser.deploy.js +1655 -0
  25. data/app/javascripts/Parser.js +1655 -0
  26. data/app/javascripts/Raphael-Core.js +0 -0
  27. data/app/javascripts/Raphael-Graph.js +0 -0
  28. data/app/javascripts/SUnit.deploy.js +1059 -0
  29. data/app/javascripts/SUnit.js +1059 -0
  30. data/app/javascripts/application.js +2 -0
  31. data/app/javascripts/boot.js +466 -0
  32. data/app/javascripts/init.js +2 -0
  33. data/app/javascripts/jquery-1.4.4.min.js +167 -0
  34. data/app/javascripts/jquery-ui-1.8.9.custom.min.js +781 -0
  35. data/app/javascripts/jquery.textarea.js +267 -0
  36. data/app/javascripts/jtalk.js +78 -0
  37. data/app/javascripts/lib/CodeMirror/LICENSE +19 -0
  38. data/app/javascripts/lib/CodeMirror/README.md +6 -0
  39. data/app/javascripts/lib/CodeMirror/compress.html +92 -0
  40. data/app/javascripts/lib/CodeMirror/css/baboon.png +0 -0
  41. data/app/javascripts/lib/CodeMirror/css/baboon_vector.svg +153 -0
  42. data/app/javascripts/lib/CodeMirror/css/docs.css +154 -0
  43. data/app/javascripts/lib/CodeMirror/demo/activeline.html +72 -0
  44. data/app/javascripts/lib/CodeMirror/demo/changemode.html +51 -0
  45. data/app/javascripts/lib/CodeMirror/demo/complete.html +79 -0
  46. data/app/javascripts/lib/CodeMirror/demo/complete.js +151 -0
  47. data/app/javascripts/lib/CodeMirror/demo/fullscreen.html +158 -0
  48. data/app/javascripts/lib/CodeMirror/demo/marker.html +53 -0
  49. data/app/javascripts/lib/CodeMirror/demo/mustache.html +57 -0
  50. data/app/javascripts/lib/CodeMirror/demo/preview.html +75 -0
  51. data/app/javascripts/lib/CodeMirror/demo/resize.html +44 -0
  52. data/app/javascripts/lib/CodeMirror/demo/runmode.html +50 -0
  53. data/app/javascripts/lib/CodeMirror/demo/search.html +106 -0
  54. data/app/javascripts/lib/CodeMirror/demo/theme.html +53 -0
  55. data/app/javascripts/lib/CodeMirror/index.html +239 -0
  56. data/app/javascripts/lib/CodeMirror/internals.html +389 -0
  57. data/app/javascripts/lib/CodeMirror/lib/codemirror.css +67 -0
  58. data/app/javascripts/lib/CodeMirror/lib/codemirror.js +2144 -0
  59. data/app/javascripts/lib/CodeMirror/lib/overlay.js +51 -0
  60. data/app/javascripts/lib/CodeMirror/lib/runmode.js +27 -0
  61. data/app/javascripts/lib/CodeMirror/manual.html +854 -0
  62. data/app/javascripts/lib/CodeMirror/mode/clike/clike.js +247 -0
  63. data/app/javascripts/lib/CodeMirror/mode/clike/index.html +102 -0
  64. data/app/javascripts/lib/CodeMirror/mode/css/css.js +124 -0
  65. data/app/javascripts/lib/CodeMirror/mode/css/index.html +56 -0
  66. data/app/javascripts/lib/CodeMirror/mode/diff/diff.css +3 -0
  67. data/app/javascripts/lib/CodeMirror/mode/diff/diff.js +13 -0
  68. data/app/javascripts/lib/CodeMirror/mode/diff/index.html +99 -0
  69. data/app/javascripts/lib/CodeMirror/mode/haskell/haskell.js +242 -0
  70. data/app/javascripts/lib/CodeMirror/mode/haskell/index.html +60 -0
  71. data/app/javascripts/lib/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
  72. data/app/javascripts/lib/CodeMirror/mode/htmlmixed/index.html +52 -0
  73. data/app/javascripts/lib/CodeMirror/mode/javascript/index.html +78 -0
  74. data/app/javascripts/lib/CodeMirror/mode/javascript/javascript.js +348 -0
  75. data/app/javascripts/lib/CodeMirror/mode/lua/index.html +72 -0
  76. data/app/javascripts/lib/CodeMirror/mode/lua/lua.js +138 -0
  77. data/app/javascripts/lib/CodeMirror/mode/php/index.html +49 -0
  78. data/app/javascripts/lib/CodeMirror/mode/php/php.js +110 -0
  79. data/app/javascripts/lib/CodeMirror/mode/plsql/index.html +63 -0
  80. data/app/javascripts/lib/CodeMirror/mode/plsql/plsql.js +217 -0
  81. data/app/javascripts/lib/CodeMirror/mode/python/LICENSE.txt +21 -0
  82. data/app/javascripts/lib/CodeMirror/mode/python/index.html +123 -0
  83. data/app/javascripts/lib/CodeMirror/mode/python/python.js +321 -0
  84. data/app/javascripts/lib/CodeMirror/mode/rst/index.html +526 -0
  85. data/app/javascripts/lib/CodeMirror/mode/rst/rst.css +75 -0
  86. data/app/javascripts/lib/CodeMirror/mode/rst/rst.js +333 -0
  87. data/app/javascripts/lib/CodeMirror/mode/scheme/index.html +65 -0
  88. data/app/javascripts/lib/CodeMirror/mode/scheme/scheme.js +181 -0
  89. data/app/javascripts/lib/CodeMirror/mode/smalltalk/index.html +56 -0
  90. data/app/javascripts/lib/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
  91. data/app/javascripts/lib/CodeMirror/mode/sparql/index.html +41 -0
  92. data/app/javascripts/lib/CodeMirror/mode/sparql/sparql.js +143 -0
  93. data/app/javascripts/lib/CodeMirror/mode/stex/index.html +96 -0
  94. data/app/javascripts/lib/CodeMirror/mode/stex/stex.js +167 -0
  95. data/app/javascripts/lib/CodeMirror/mode/xml/index.html +42 -0
  96. data/app/javascripts/lib/CodeMirror/mode/xml/xml.js +231 -0
  97. data/app/javascripts/lib/CodeMirror/mode/yaml/index.html +68 -0
  98. data/app/javascripts/lib/CodeMirror/mode/yaml/yaml.js +95 -0
  99. data/app/javascripts/lib/CodeMirror/oldrelease.html +178 -0
  100. data/app/javascripts/lib/CodeMirror/test/index.html +29 -0
  101. data/app/javascripts/lib/CodeMirror/test/test.js +249 -0
  102. data/app/javascripts/lib/CodeMirror/theme/default.css +18 -0
  103. data/app/javascripts/lib/CodeMirror/theme/elegant.css +9 -0
  104. data/app/javascripts/lib/CodeMirror/theme/jtalk.css +21 -0
  105. data/app/javascripts/lib/CodeMirror/theme/neat.css +8 -0
  106. data/app/javascripts/lib/CodeMirror/theme/night.css +20 -0
  107. data/app/javascripts/lib/jQuery/jquery-1.4.4.min.js +167 -0
  108. data/app/javascripts/lib/jQuery/jquery-ui-1.8.9.custom.min.js +781 -0
  109. data/app/javascripts/lib/jQuery/jquery.textarea.js +267 -0
  110. data/app/smalltalk/Canvas.st +481 -0
  111. data/app/smalltalk/IDE.st +1752 -0
  112. data/config.ru +2 -0
  113. data/lib/amber-rack.rb +4 -0
  114. data/lib/amber-rack/version.rb +3 -0
  115. data/public/CodeMirror/LICENSE +19 -0
  116. data/public/CodeMirror/README.md +6 -0
  117. data/public/CodeMirror/compress.html +92 -0
  118. data/public/CodeMirror/css/baboon.png +0 -0
  119. data/public/CodeMirror/css/baboon_vector.svg +153 -0
  120. data/public/CodeMirror/css/docs.css +154 -0
  121. data/public/CodeMirror/demo/activeline.html +72 -0
  122. data/public/CodeMirror/demo/changemode.html +51 -0
  123. data/public/CodeMirror/demo/complete.html +79 -0
  124. data/public/CodeMirror/demo/complete.js +151 -0
  125. data/public/CodeMirror/demo/fullscreen.html +158 -0
  126. data/public/CodeMirror/demo/marker.html +53 -0
  127. data/public/CodeMirror/demo/mustache.html +57 -0
  128. data/public/CodeMirror/demo/preview.html +75 -0
  129. data/public/CodeMirror/demo/resize.html +44 -0
  130. data/public/CodeMirror/demo/runmode.html +50 -0
  131. data/public/CodeMirror/demo/search.html +106 -0
  132. data/public/CodeMirror/demo/theme.html +53 -0
  133. data/public/CodeMirror/index.html +239 -0
  134. data/public/CodeMirror/internals.html +389 -0
  135. data/public/CodeMirror/lib/codemirror.css +67 -0
  136. data/public/CodeMirror/lib/codemirror.js +2144 -0
  137. data/public/CodeMirror/lib/overlay.js +51 -0
  138. data/public/CodeMirror/lib/runmode.js +27 -0
  139. data/public/CodeMirror/manual.html +854 -0
  140. data/public/CodeMirror/mode/clike/clike.js +247 -0
  141. data/public/CodeMirror/mode/clike/index.html +102 -0
  142. data/public/CodeMirror/mode/css/css.js +124 -0
  143. data/public/CodeMirror/mode/css/index.html +56 -0
  144. data/public/CodeMirror/mode/diff/diff.css +3 -0
  145. data/public/CodeMirror/mode/diff/diff.js +13 -0
  146. data/public/CodeMirror/mode/diff/index.html +99 -0
  147. data/public/CodeMirror/mode/haskell/haskell.js +242 -0
  148. data/public/CodeMirror/mode/haskell/index.html +60 -0
  149. data/public/CodeMirror/mode/htmlmixed/htmlmixed.js +79 -0
  150. data/public/CodeMirror/mode/htmlmixed/index.html +52 -0
  151. data/public/CodeMirror/mode/javascript/index.html +78 -0
  152. data/public/CodeMirror/mode/javascript/javascript.js +348 -0
  153. data/public/CodeMirror/mode/lua/index.html +72 -0
  154. data/public/CodeMirror/mode/lua/lua.js +138 -0
  155. data/public/CodeMirror/mode/php/index.html +49 -0
  156. data/public/CodeMirror/mode/php/php.js +110 -0
  157. data/public/CodeMirror/mode/plsql/index.html +63 -0
  158. data/public/CodeMirror/mode/plsql/plsql.js +217 -0
  159. data/public/CodeMirror/mode/python/LICENSE.txt +21 -0
  160. data/public/CodeMirror/mode/python/index.html +123 -0
  161. data/public/CodeMirror/mode/python/python.js +321 -0
  162. data/public/CodeMirror/mode/rst/index.html +526 -0
  163. data/public/CodeMirror/mode/rst/rst.css +75 -0
  164. data/public/CodeMirror/mode/rst/rst.js +333 -0
  165. data/public/CodeMirror/mode/scheme/index.html +65 -0
  166. data/public/CodeMirror/mode/scheme/scheme.js +181 -0
  167. data/public/CodeMirror/mode/smalltalk/index.html +56 -0
  168. data/public/CodeMirror/mode/smalltalk/smalltalk.js +134 -0
  169. data/public/CodeMirror/mode/sparql/index.html +41 -0
  170. data/public/CodeMirror/mode/sparql/sparql.js +143 -0
  171. data/public/CodeMirror/mode/stex/index.html +96 -0
  172. data/public/CodeMirror/mode/stex/stex.js +167 -0
  173. data/public/CodeMirror/mode/xml/index.html +42 -0
  174. data/public/CodeMirror/mode/xml/xml.js +231 -0
  175. data/public/CodeMirror/mode/yaml/index.html +68 -0
  176. data/public/CodeMirror/mode/yaml/yaml.js +95 -0
  177. data/public/CodeMirror/oldrelease.html +178 -0
  178. data/public/CodeMirror/test/index.html +29 -0
  179. data/public/CodeMirror/test/test.js +249 -0
  180. data/public/CodeMirror/theme/default.css +18 -0
  181. data/public/CodeMirror/theme/elegant.css +9 -0
  182. data/public/CodeMirror/theme/jtalk.css +21 -0
  183. data/public/CodeMirror/theme/neat.css +8 -0
  184. data/public/CodeMirror/theme/night.css +20 -0
  185. data/public/css/jtalk.css +362 -0
  186. data/public/css/style.css +456 -0
  187. data/public/css/sunit.css +66 -0
  188. data/public/ide/fork_me.png +0 -0
  189. data/public/ide/screen2.png +0 -0
  190. data/public/ide/style.css +456 -0
  191. data/public/ide/syntax.css +61 -0
  192. data/public/ide/text_header.png +0 -0
  193. data/public/ide/title_container1.png +0 -0
  194. data/public/images/background_box.png +0 -0
  195. data/public/images/background_header.png +0 -0
  196. data/public/images/balloon_header.png +0 -0
  197. data/views/index.haml +66 -0
  198. metadata +341 -0
@@ -0,0 +1,2 @@
1
+ //= require <jtalk>
2
+ loadJtalk();
@@ -0,0 +1,466 @@
1
+ /* ====================================================================
2
+ |
3
+ | Jtalk Smalltalk
4
+ | http://jtalk-project.org
5
+ |
6
+ ======================================================================
7
+
8
+ ======================================================================
9
+ |
10
+ | Copyright (c) 2010-2011
11
+ | Nicolas Petton <petton.nicolas@gmail.com>
12
+ |
13
+ | Jtalk is released under the MIT license
14
+ |
15
+ | Permission is hereby granted, free of charge, to any person obtaining
16
+ | a copy of this software and associated documentation files (the
17
+ | 'Software'), to deal in the Software without restriction, including
18
+ | without limitation the rights to use, copy, modify, merge, publish,
19
+ | distribute, sublicense, and/or sell copies of the Software, and to
20
+ | permit persons to whom the Software is furnished to do so, subject to
21
+ | the following conditions:
22
+ |
23
+ | The above copyright notice and this permission notice shall be
24
+ | included in all copies or substantial portions of the Software.
25
+ |
26
+ | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
27
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
+ | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29
+ | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30
+ | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31
+ | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32
+ | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
+ |
34
+ ==================================================================== */
35
+
36
+ /* Smalltalk constructors definition */
37
+
38
+ function SmalltalkObject(){};
39
+ function SmalltalkBehavior(){};
40
+ function SmalltalkClass(){};
41
+ function SmalltalkMetaclass(){
42
+ this.meta = true;
43
+ };
44
+ function SmalltalkMethod(){};
45
+ function SmalltalkNil(){};
46
+
47
+ function Smalltalk(){
48
+
49
+ var st = this;
50
+
51
+ /* Smalltalk class creation. A class is an instance of an automatically
52
+ created metaclass object. Newly created classes (not their metaclass)
53
+ should be added to the smalltalk object, see smalltalk.addClass().
54
+ Superclass linking is *not* handled here, see smalltalk.init() */
55
+
56
+ function klass(spec) {
57
+ var spec = spec || {};
58
+ var that;
59
+ if(spec.meta) {
60
+ that = new SmalltalkMetaclass();
61
+ } else {
62
+ that = new (klass({meta: true})).fn;
63
+ that.klass.instanceClass = that;
64
+ that.className = spec.className;
65
+ that.klass.className = that.className + ' class';
66
+ }
67
+
68
+ that.fn = spec.fn || function(){};
69
+ that.superclass = spec.superclass;
70
+ that.iVarNames = spec.iVarNames || [];
71
+ if(that.superclass) {
72
+ that.klass.superclass = that.superclass.klass;
73
+ }
74
+ that.category = spec.category || "";
75
+ that.fn.prototype.methods = {};
76
+ that.fn.prototype.inheritedMethods = {};
77
+ that.fn.prototype.klass = that;
78
+
79
+ return that;
80
+ };
81
+
82
+ /* Smalltalk method object. To add a method to a class,
83
+ use smalltalk.addMethod() */
84
+
85
+ st.method = function(spec) {
86
+ var that = new SmalltalkMethod();
87
+ that.selector = spec.selector;
88
+ that.jsSelector = spec.jsSelector;
89
+ that.category = spec.category;
90
+ that.source = spec.source;
91
+ that.messageSends = spec.messageSends || [];
92
+ that.referencedClasses = spec.referencedClasses || [];
93
+ that.fn = spec.fn;
94
+ return that
95
+ };
96
+
97
+ /* Initialize a class in its class hierarchy. Handle both class and
98
+ metaclasses. */
99
+
100
+ st.init = function(klass) {
101
+ var subclasses = st.subclasses(klass);
102
+ var methods;
103
+
104
+ if(klass.superclass && klass.superclass !== nil) {
105
+ methods = st.methods(klass.superclass);
106
+
107
+ //Methods linking
108
+ for(var i in methods) {
109
+ if(!klass.fn.prototype.methods[i]) {
110
+ klass.fn.prototype.inheritedMethods[i] = methods[i];
111
+ klass.fn.prototype[methods[i].jsSelector] = methods[i].fn;
112
+ }
113
+ }
114
+ }
115
+
116
+ for(var i=0;i<subclasses.length;i++) {
117
+ st.init(subclasses[i]);
118
+ }
119
+ if(klass.klass && !klass.meta) {
120
+ st.init(klass.klass);
121
+ }
122
+ };
123
+
124
+ /* Answer all registered Smalltalk classes */
125
+
126
+ st.classes = function() {
127
+ var classes = [];
128
+ for(var i in st) {
129
+ if(i.search(/^[A-Z]/g) != -1) {
130
+ classes.push(st[i]);
131
+ }
132
+
133
+ }
134
+ return classes
135
+ };
136
+
137
+ /* Answer all methods (included inherited ones) of klass. */
138
+
139
+ st.methods = function(klass) {
140
+ var methods = {};
141
+ for(var i in klass.fn.prototype.methods) {
142
+ methods[i] = klass.fn.prototype.methods[i]
143
+ }
144
+ for(var i in klass.fn.prototype.inheritedMethods) {
145
+ methods[i] = klass.fn.prototype.inheritedMethods[i]
146
+ }
147
+ return methods;
148
+ }
149
+
150
+ /* Answer the direct subclasses of klass. */
151
+
152
+ st.subclasses = function(klass) {
153
+ var subclasses = [];
154
+ var classes = st.classes();
155
+ for(var i in classes) {
156
+ if(classes[i].fn) {
157
+ //Metaclasses
158
+ if(classes[i].klass && classes[i].klass.superclass === klass) {
159
+ subclasses.push(classes[i].klass);
160
+ }
161
+ //Classes
162
+ if(classes[i].superclass === klass) {
163
+ subclasses.push(classes[i]);
164
+ }
165
+ }
166
+ }
167
+ return subclasses;
168
+ };
169
+
170
+ /* Create a new class wrapping a JavaScript constructor, and add it to the
171
+ global smalltalk object. */
172
+
173
+ st.mapClassName = function(className, category, fn, superclass) {
174
+ st[className] = klass({
175
+ className: className,
176
+ category: category,
177
+ superclass: superclass,
178
+ fn: fn
179
+ });
180
+ };
181
+
182
+ /* Add a class to the smalltalk object, creating a new one if needed. */
183
+
184
+ st.addClass = function(className, superclass, iVarNames, category) {
185
+ if(st[className]) {
186
+ st[className].superclass = superclass;
187
+ st[className].iVarNames = iVarNames;
188
+ st[className].category = category || st[className].category;
189
+ } else {
190
+ st[className] = klass({
191
+ className: className,
192
+ iVarNames: iVarNames,
193
+ superclass: superclass
194
+ });
195
+ st[className].category = category || '';
196
+ }
197
+ };
198
+
199
+ /* Add a method to a class */
200
+
201
+ st.addMethod = function(jsSelector, method, klass) {
202
+ klass.fn.prototype[jsSelector] = method.fn;
203
+ klass.fn.prototype.methods[method.selector] = method;
204
+ method.methodClass = klass;
205
+ method.jsSelector = jsSelector;
206
+ };
207
+
208
+ /* Handles Smalltalk message send. Automatically converts undefined to the nil object.
209
+ If the receiver does not understand the selector, call its #doesNotUnderstand: method */
210
+
211
+ sendWithoutContext = function(receiver, selector, args, klass) {
212
+ if(typeof receiver === "undefined") {
213
+ receiver = nil;
214
+ }
215
+ if(!klass && receiver.klass && receiver[selector]) {
216
+ return receiver[selector].apply(receiver, args);
217
+ } else if(klass && klass.fn.prototype[selector]) {
218
+ return klass.fn.prototype[selector].apply(receiver, args)
219
+ }
220
+ return messageNotUnderstood(receiver, selector, args);
221
+ };
222
+
223
+
224
+ /* Handles unhandled errors during message sends */
225
+
226
+ sendWithContext = function(receiver, selector, args, klass) {
227
+ if(thisContext) {
228
+ return withContextSend(receiver, selector, args, klass);
229
+ } else {
230
+ try {return withContextSend(receiver, selector, args, klass)}
231
+ catch(error) {
232
+ // Reset the context stack in any case
233
+ thisContext = undefined;
234
+ if(error.smalltalkError) {
235
+ handleError(error);
236
+ } else {
237
+ throw(error);
238
+ }
239
+ }
240
+ }
241
+ };
242
+
243
+ /* Same as sendWithoutContext but creates a methodContext. */
244
+
245
+ withContextSend = function(receiver, selector, args, klass) {
246
+ var call, context;
247
+ if(typeof receiver === "undefined") {
248
+ receiver = nil;
249
+ }
250
+ if(!klass && receiver.klass && receiver[selector]) {
251
+ context = pushContext(receiver, selector, args);
252
+ call = receiver[selector].apply(receiver, args);
253
+ popContext(context);
254
+ return call;
255
+ } else if(klass && klass.fn.prototype[selector]) {
256
+ context = pushContext(receiver, selector, args);
257
+ call = klass.fn.prototype[selector].apply(receiver, args);
258
+ popContext(context);
259
+ return call;
260
+ }
261
+ return messageNotUnderstood(receiver, selector, args);
262
+ };
263
+
264
+ /* Handles Smalltalk errors. Triggers the registered ErrorHandler
265
+ (See the Smalltalk class ErrorHandler and its subclasses */
266
+
267
+ function handleError(error) {
268
+ thisContext = undefined;
269
+ smalltalk.ErrorHandler._current()._handleError_(error);
270
+ }
271
+
272
+ /* Handles #dnu: *and* JavaScript method calls.
273
+ if the receiver has no klass, we consider it a JS object (outside of the
274
+ Jtalk system). Else assume that the receiver understands #doesNotUnderstand: */
275
+
276
+ function messageNotUnderstood(receiver, selector, args) {
277
+ /* Handles JS method calls. */
278
+ if(receiver.klass === undefined || receiver.allowJavaScriptCalls) {
279
+ return callJavaScriptMethod(receiver, selector, args);
280
+ }
281
+
282
+ /* Handles not understood messages. Also see the Jtalk counter-part
283
+ Object>>doesNotUnderstand: */
284
+
285
+ return receiver._doesNotUnderstand_(
286
+ st.Message._new()
287
+ ._selector_(st.convertSelector(selector))
288
+ ._arguments_(args)
289
+ );
290
+ };
291
+
292
+ function callJavaScriptMethod(receiver, selector, args) {
293
+ /* Call a method of a JS object, or answer a property.
294
+
295
+ Converts keyword-based selectors by using the first
296
+ keyword only, but keeping all message arguments.
297
+
298
+ Example:
299
+ "self do: aBlock with: anObject" -> "self.do(aBlock, anObject)" */
300
+
301
+ var jsSelector = selector
302
+ .replace(/^_/, '')
303
+ .replace(/_.*/g, '');
304
+ var jsProperty = receiver[jsSelector];
305
+ if(typeof jsProperty === "function") {
306
+ return jsProperty.apply(receiver, args);
307
+ } else if(jsProperty !== undefined) {
308
+ if(args[0]) {
309
+ receiver[jsSelector] = args[0];
310
+ return nil;
311
+ } else {
312
+ return jsProperty
313
+ }
314
+ }
315
+ smalltalk.Error._signal_(receiver + ' is not a Jtalk object and "' + jsSelector + '" is undefined')
316
+ };
317
+
318
+
319
+ /* Handle thisContext pseudo variable */
320
+
321
+ pushContext = function(receiver, selector, temps) {
322
+ if(thisContext) {
323
+ return thisContext = thisContext.newContext({receiver: receiver, selector: selector, temps: temps});
324
+ } else {
325
+ return thisContext = new SmalltalkMethodContext({receiver: receiver, selector: selector, temps: temps});
326
+ }
327
+ };
328
+
329
+ popContext = function(context) {
330
+ if(context) {
331
+ context.removeYourself();
332
+ }
333
+ };
334
+
335
+ /* Convert a string to a valid smalltalk selector.
336
+ if you modify the following functions, also change String>>asSelector
337
+ accordingly */
338
+
339
+ st.convertSelector = function(selector) {
340
+ if(selector.match(/__/)) {
341
+ return convertBinarySelector(selector);
342
+ } else {
343
+ return convertKeywordSelector(selector);
344
+ }
345
+ };
346
+
347
+ function convertKeywordSelector(selector) {
348
+ return selector.replace(/^_/, '').replace(/_/g, ':');
349
+ };
350
+
351
+ function convertBinarySelector(selector) {
352
+ return selector
353
+ .replace(/^_/, '')
354
+ .replace(/_plus/, '+')
355
+ .replace(/_minus/, '-')
356
+ .replace(/_star/, '*')
357
+ .replace(/_slash/, '/')
358
+ .replace(/_gt/, '>')
359
+ .replace(/_lt/, '<')
360
+ .replace(/_eq/, '=')
361
+ .replace(/_comma/, ',')
362
+ .replace(/_at/, '@')
363
+ };
364
+
365
+ /* Converts a JavaScript object to valid Smalltalk Object */
366
+ st.readJSObject = function(js) {
367
+ var object = js;
368
+ var readObject = (js.constructor === Object);
369
+ var readArray = (js.constructor === Array);
370
+
371
+ if(readObject) {
372
+ object = smalltalk.Dictionary._new();
373
+ }
374
+ for(var i in js) {
375
+ if(readObject) {
376
+ object._at_put_(i, st.readJSObject(js[i]));
377
+ }
378
+ if(readArray) {
379
+ object[i] = st.readJSObject(js[i]);
380
+ }
381
+ }
382
+ return object;
383
+ };
384
+
385
+ /* Toggle deployment mode (no context will be handled during message send */
386
+ st.setDeploymentMode = function() {
387
+ st.send = sendWithoutContext;
388
+ };
389
+
390
+ st.setDevelopmentMode = function() {
391
+ st.send = sendWithContext;
392
+ }
393
+
394
+ /* Set development mode by default */
395
+ st.setDevelopmentMode();
396
+ }
397
+
398
+ function SmalltalkMethodContext(spec) {
399
+ var that = this;
400
+ spec = spec || {};
401
+ that.homeContext = spec.homeContext;
402
+ that.selector = spec.selector;
403
+ that.receiver = spec.receiver;
404
+ that.temps = spec.temps || {};
405
+
406
+ that.newContext = function(spec) {
407
+ spec = spec || {};
408
+ return new SmalltalkMethodContext({homeContext: that, receiver: spec.receiver, selector: spec.selector, temps: spec.temps});
409
+ }
410
+
411
+ that.removeYourself = function() {
412
+ thisContext = that.homeContext;
413
+ }
414
+ }
415
+
416
+ /* Global Smalltalk objects. nil and thisContext shouldn't be globals. */
417
+
418
+ var nil = new SmalltalkNil();
419
+ var smalltalk = new Smalltalk();
420
+ var thisContext = undefined;
421
+
422
+
423
+ /* Utilities */
424
+
425
+ Array.prototype.remove = function(s){
426
+ var index = this.indexOf(s);
427
+ if(this.indexOf(s) != -1)this.splice(index, 1);
428
+ }
429
+
430
+ if(this.jQuery) {
431
+ this.jQuery.allowJavaScriptCalls = true;
432
+ }
433
+
434
+ /****************************************************************************************/
435
+
436
+
437
+ /* Base classes mapping. If you edit this part, do not forget to set the superclass of the
438
+ object metaclass to Class after the definition of Object */
439
+
440
+ smalltalk.mapClassName("Object", "Kernel", SmalltalkObject);
441
+ smalltalk.mapClassName("Smalltalk", "Kernel", Smalltalk, smalltalk.Object);
442
+ smalltalk.mapClassName("Behavior", "Kernel", SmalltalkBehavior, smalltalk.Object);
443
+ smalltalk.mapClassName("Class", "Kernel", SmalltalkClass, smalltalk.Behavior);
444
+ smalltalk.mapClassName("Metaclass", "Kernel", SmalltalkMetaclass, smalltalk.Behavior);
445
+ smalltalk.mapClassName("CompiledMethod", "Kernel", SmalltalkMethod, smalltalk.Object);
446
+
447
+ smalltalk.Object.klass.superclass = smalltalk.Class
448
+
449
+ smalltalk.mapClassName("Number", "Kernel", Number, smalltalk.Object);
450
+ smalltalk.mapClassName("BlockClosure", "Kernel", Function, smalltalk.Object);
451
+ smalltalk.mapClassName("Boolean", "Kernel", Boolean, smalltalk.Object);
452
+ smalltalk.mapClassName("Date", "Kernel", Date, smalltalk.Object);
453
+ smalltalk.mapClassName("UndefinedObject", "Kernel", SmalltalkNil, smalltalk.Object);
454
+
455
+ smalltalk.mapClassName("Collection", "Kernel", null, smalltalk.Object);
456
+ smalltalk.mapClassName("SequenceableCollection", "Kernel", null, smalltalk.Collection);
457
+ smalltalk.mapClassName("String", "Kernel", String, smalltalk.SequenceableCollection);
458
+ smalltalk.mapClassName("Array", "Kernel", Array, smalltalk.SequenceableCollection);
459
+ smalltalk.mapClassName("RegularExpression", "Kernel", RegExp, smalltalk.String);
460
+
461
+ smalltalk.mapClassName("Error", "Kernel", Error, smalltalk.Object);
462
+ smalltalk.mapClassName("MethodContext", "Kernel", SmalltalkMethodContext, smalltalk.Object);
463
+
464
+ if(this.CanvasRenderingContext2D) {
465
+ smalltalk.mapClassName("CanvasRenderingContext", "Canvas", CanvasRenderingContext2D, smalltalk.Object);
466
+ }