resin 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/README.markdown +2 -0
  2. data/amber/bin/nodecompile.js +3 -3
  3. data/amber/css/amber.css +47 -23
  4. data/amber/images/off.amber.png +0 -0
  5. data/amber/images/offHover.amber.png +0 -0
  6. data/amber/images/sprite.amber.png +0 -0
  7. data/amber/images/tinylogo.amber.png +0 -0
  8. data/amber/js/Benchfib.deploy.js +34 -34
  9. data/amber/js/Benchfib.js +49 -49
  10. data/amber/js/Canvas.deploy.js +937 -937
  11. data/amber/js/Canvas.js +1622 -1622
  12. data/amber/js/Compiler-Tests.deploy.js +97 -0
  13. data/amber/js/Compiler-Tests.js +137 -0
  14. data/amber/js/Compiler.deploy.js +1030 -924
  15. data/amber/js/Compiler.js +1613 -1467
  16. data/amber/js/Documentation.deploy.js +417 -417
  17. data/amber/js/Documentation.js +728 -728
  18. data/amber/js/Examples.deploy.js +24 -13
  19. data/amber/js/Examples.js +36 -19
  20. data/amber/js/IDE.deploy.js +1583 -1527
  21. data/amber/js/IDE.js +2586 -2510
  22. data/amber/js/Kernel-Announcements.deploy.js +19 -19
  23. data/amber/js/Kernel-Announcements.js +28 -28
  24. data/amber/js/Kernel-Classes.deploy.js +332 -229
  25. data/amber/js/Kernel-Classes.js +532 -384
  26. data/amber/js/Kernel-Collections.deploy.js +1516 -1712
  27. data/amber/js/Kernel-Collections.js +2436 -2712
  28. data/amber/js/Kernel-Exceptions.deploy.js +85 -62
  29. data/amber/js/Kernel-Exceptions.js +131 -98
  30. data/amber/js/Kernel-Methods.deploy.js +326 -378
  31. data/amber/js/Kernel-Methods.js +473 -525
  32. data/amber/js/Kernel-Objects.deploy.js +1777 -2428
  33. data/amber/js/Kernel-Objects.js +2599 -3426
  34. data/amber/js/Kernel-Tests.deploy.js +871 -772
  35. data/amber/js/Kernel-Tests.js +1207 -1083
  36. data/amber/js/Kernel-Transcript.deploy.js +57 -57
  37. data/amber/js/Kernel-Transcript.js +94 -94
  38. data/amber/js/SUnit.deploy.js +116 -116
  39. data/amber/js/SUnit.js +211 -211
  40. data/amber/js/amber.js +10 -11
  41. data/amber/js/boot.js +132 -156
  42. data/amber/js/init.js +2 -2
  43. data/amber/js/parser.js +2095 -3014
  44. data/amber/js/parser.pegjs +1 -1
  45. data/amber/st/Benchfib.st +22 -22
  46. data/amber/st/Canvas.st +471 -471
  47. data/amber/st/Compiler-Tests.st +471 -0
  48. data/amber/st/Compiler.st +858 -794
  49. data/amber/st/Examples.st +22 -5
  50. data/amber/st/IDE.st +1326 -1291
  51. data/amber/st/Kernel-Announcements.st +2 -2
  52. data/amber/st/Kernel-Classes.st +148 -90
  53. data/amber/st/Kernel-Collections.st +950 -1061
  54. data/amber/st/Kernel-Exceptions.st +33 -25
  55. data/amber/st/Kernel-Methods.st +151 -151
  56. data/amber/st/Kernel-Objects.st +891 -1036
  57. data/amber/st/Kernel-Tests.st +622 -544
  58. data/amber/st/Kernel-Transcript.st +38 -38
  59. data/amber/st/SUnit.st +53 -53
  60. metadata +27 -20
@@ -95,7 +95,7 @@ amber = (function() {
95
95
 
96
96
  var additionalFiles = spec.packages || spec.files;
97
97
  if (additionalFiles) {
98
- loadPackages(additionalFiles, spec.prefix);
98
+ loadPackages(additionalFiles, spec.prefix, spec.packageHome);
99
99
  }
100
100
 
101
101
  // Be sure to setup & initialize smalltalk classes
@@ -103,29 +103,32 @@ amber = (function() {
103
103
  initializeSmalltalk();
104
104
  };
105
105
 
106
- function loadPackages(names, prefix){
106
+ function loadPackages(names, prefix, urlHome){
107
107
  var name, url;
108
108
  var prefix = prefix || 'js';
109
+ var urlHome = urlHome || home;
109
110
 
110
111
  for (var i=0; i < names.length; i++) {
111
112
  name = names[i].split(/\.js$/)[0];
112
- addJSToLoad(name + '.js', prefix);
113
+ addJSToLoad(name + '.js', prefix, urlHome);
113
114
  }
114
115
  };
115
116
 
116
- function addJSToLoad(name, prefix) {
117
- jsToLoad.push(buildJSURL(name, prefix));
117
+ function addJSToLoad(name, prefix, urlHome) {
118
+ var urlHome = urlHome || home;
119
+ jsToLoad.push(buildJSURL(name, prefix, urlHome));
118
120
  };
119
121
 
120
- function buildJSURL(name, prefix) {
122
+ function buildJSURL(name, prefix, urlHome) {
121
123
  var prefix = prefix || 'js';
122
124
  var name = name;
125
+ var urlHome = urlHome || home;
123
126
 
124
127
  if (!deploy) {
125
128
  name = name + nocache;
126
129
  }
127
130
 
128
- return home + prefix + '/' + name;
131
+ return urlHome + prefix + '/' + name;
129
132
  };
130
133
 
131
134
  function loadCSS(name, prefix) {
@@ -165,10 +168,6 @@ amber = (function() {
165
168
  // This will be called after JS files have been loaded
166
169
  function initializeSmalltalk() {
167
170
  window.smalltalkReady = function() {
168
- if (deploy) {
169
- smalltalk.setDeploymentMode();
170
- }
171
-
172
171
  if (spec.ready) {
173
172
  spec.ready();
174
173
  }
@@ -45,22 +45,21 @@ if (typeof console === "undefined") {
45
45
  };
46
46
  }
47
47
 
48
-
49
48
  /* Smalltalk constructors definition */
50
49
 
51
50
  function SmalltalkObject(){}
52
- function SmalltalkBehavior(){};
51
+ function SmalltalkBehavior(){}
53
52
  function SmalltalkClass(){}
54
- function SmalltalkPackage(){};
53
+ function SmalltalkPackage(){}
55
54
  function SmalltalkMetaclass(){
56
55
  this.meta = true;
57
- };
58
- function SmalltalkMethod(){};
59
- function SmalltalkNil(){};
56
+ }
57
+ function SmalltalkMethod(){}
58
+ function SmalltalkNil(){}
60
59
 
61
60
  function SmalltalkSymbol(string){
62
61
  this.value = string;
63
- };
62
+ }
64
63
 
65
64
  function Smalltalk(){
66
65
 
@@ -107,8 +106,8 @@ function Smalltalk(){
107
106
  /* Smalltalk package creation. To add a Package, use smalltalk.addPackage() */
108
107
 
109
108
  function pkg(spec) {
110
- var that = new SmalltalkPackage();
111
- that.pkgName = spec.pkgName;
109
+ var that = new SmalltalkPackage();
110
+ that.pkgName = spec.pkgName;
112
111
  that.properties = spec.properties || {};
113
112
  return that;
114
113
  };
@@ -120,28 +119,36 @@ function Smalltalk(){
120
119
 
121
120
  function klass(spec) {
122
121
  var spec = spec || {};
123
- var that;
124
- if(spec.meta) {
125
- that = new SmalltalkMetaclass();
126
- } else {
127
- that = new (klass({meta: true})).fn;
128
- that.klass.instanceClass = that;
129
- that.className = spec.className;
130
- that.klass.className = that.className + ' class';
122
+ var meta = metaclass();
123
+ var that = setupClass(meta.instanceClass, spec);
124
+ that.className = spec.className;
125
+ meta.className = spec.className + ' class';
126
+ if(spec.superclass) {
127
+ that.superclass = spec.superclass;
128
+ meta.superclass = spec.superclass.klass;
131
129
  }
132
-
130
+ return that;
131
+ }
132
+
133
+ function metaclass() {
134
+ var meta = setupClass(new SmalltalkMetaclass(), {});
135
+ meta.instanceClass = new meta.fn;
136
+ return meta;
137
+ }
138
+
139
+ function setupClass(that, spec) {
133
140
  that.fn = spec.fn || function(){};
134
- that.superclass = spec.superclass;
135
141
  that.iVarNames = spec.iVarNames || [];
136
- that.toString = function() {return 'Smalltalk ' + that.className};
137
- if(that.superclass) {
138
- that.klass.superclass = that.superclass.klass;
139
- }
142
+ Object.defineProperty(that, "toString", {
143
+ value: function() { return 'Smalltalk ' + this.className; },
144
+ configurable: true // no writable - in par with ES6 methods
145
+ });
140
146
  that.pkg = spec.pkg;
141
- that.fn.prototype.methods = {};
142
- that.fn.prototype.inheritedMethods = {};
143
- that.fn.prototype.klass = that;
144
-
147
+ Object.defineProperties(that.fn.prototype, {
148
+ methods: { value: {}, enumerable: false, configurable: true, writable: true },
149
+ inheritedMethods: { value: {}, enumerable: false, configurable: true, writable: true },
150
+ klass: { value: that, enumerable: false, configurable: true, writable: true }
151
+ });
145
152
  return that;
146
153
  };
147
154
 
@@ -158,36 +165,44 @@ function Smalltalk(){
158
165
  that.messageSends = spec.messageSends || [];
159
166
  that.referencedClasses = spec.referencedClasses || [];
160
167
  that.fn = spec.fn;
161
- return that
168
+ return that;
162
169
  };
163
170
 
164
171
  /* Initialize a class in its class hierarchy. Handle both class and
165
172
  metaclasses. */
166
-
173
+
167
174
  st.init = function(klass) {
175
+ st.initSubTree(klass);
176
+ if(klass.klass && !klass.meta) {
177
+ st.initSubTree(klass.klass);
178
+ }
179
+ };
180
+
181
+ st.initSubTree = function(klass) {
168
182
  var subclasses = st.subclasses(klass);
169
- var methods;
183
+ var methods, proto = klass.fn.prototype;
170
184
 
171
185
  if(klass.superclass && klass.superclass !== nil) {
172
186
  methods = st.methods(klass.superclass);
173
187
 
174
188
  //Methods linking
175
- for(var i in methods) {
176
- if(!klass.fn.prototype.methods[i]) {
177
- klass.fn.prototype.inheritedMethods[i] = methods[i];
178
- klass.fn.prototype[methods[i].jsSelector] = methods[i].fn;
189
+ for(var keys=Object.keys(methods),i=0,l=keys.length; i<l; ++i) {
190
+ var k = keys[i]
191
+ if(!proto.methods[k]) {
192
+ proto.inheritedMethods[k] = methods[k];
193
+ Object.defineProperty(proto, methods[k].jsSelector, {
194
+ value: methods[k].fn, configurable: true // no writable - in par with ES6 methods
195
+ });
179
196
  }
180
197
  }
181
198
  }
182
199
 
183
200
  for(var i=0;i<subclasses.length;i++) {
184
- st.init(subclasses[i]);
185
- }
186
- if(klass.klass && !klass.meta) {
187
- st.init(klass.klass);
201
+ st.initSubTree(subclasses[i]);
188
202
  }
189
203
  };
190
204
 
205
+
191
206
  /* Answer all registered Packages as Array */
192
207
 
193
208
  st.packages.all = function() {
@@ -202,42 +217,49 @@ function Smalltalk(){
202
217
  /* Answer all registered Smalltalk classes */
203
218
 
204
219
  st.classes = function() {
205
- var classes = [];
206
- for(var i in st) {
207
- if(i.search(/^[A-Z]/g) != -1) {
208
- classes.push(st[i]);
220
+ var classes = [], names = Object.keys(st), l = names.length;
221
+ for (var i=0; i<l; ++i) {
222
+ var name = names[i];
223
+ if (name.search(/^[A-Z]/) !== -1) {
224
+ classes.push(st[name]);
209
225
  }
210
226
  }
211
- return classes
227
+ return classes;
212
228
  };
213
229
 
230
+
214
231
  /* Answer all methods (included inherited ones) of klass. */
215
232
 
216
233
  st.methods = function(klass) {
217
234
  var methods = {};
218
- for(var i in klass.fn.prototype.methods) {
219
- methods[i] = klass.fn.prototype.methods[i]
235
+ var copyFrom = klass.fn.prototype.methods;
236
+ for(var i=0, k=Object.keys(copyFrom), l=k.length; i<l; ++i) {
237
+ methods[k[i]] = copyFrom[k[i]];
220
238
  }
221
- for(var i in klass.fn.prototype.inheritedMethods) {
222
- methods[i] = klass.fn.prototype.inheritedMethods[i]
239
+ copyFrom = klass.fn.prototype.inheritedMethods;
240
+ for(var i=0, k=Object.keys(copyFrom), l=k.length; i<l; ++i) {
241
+ methods[k[i]] = copyFrom[k[i]];
223
242
  }
224
243
  return methods;
225
- }
244
+ };
245
+
226
246
 
227
247
  /* Answer the direct subclasses of klass. */
228
248
 
229
249
  st.subclasses = function(klass) {
230
250
  var subclasses = [];
231
251
  var classes = st.classes();
232
- for(var i in classes) {
233
- if(classes[i].fn) {
234
- //Metaclasses
235
- if(classes[i].klass && classes[i].klass.superclass === klass) {
236
- subclasses.push(classes[i].klass);
237
- }
252
+ for(var i=0, l=classes.length; i<l; ++i) {
253
+ var c = classes[i]
254
+ if(c.fn) {
238
255
  //Classes
239
- if(classes[i].superclass === klass) {
240
- subclasses.push(classes[i]);
256
+ if(c.superclass === klass) {
257
+ subclasses.push(c);
258
+ }
259
+ c = c.klass;
260
+ //Metaclasses
261
+ if(c && c.superclass === klass) {
262
+ subclasses.push(c);
241
263
  }
242
264
  }
243
265
  }
@@ -257,10 +279,10 @@ function Smalltalk(){
257
279
  });
258
280
  };
259
281
 
260
- /* Create an alias for an existing class */
261
- st.alias = function(klass, alias) {
262
- st[alias] = klass;
263
- }
282
+ /* Create an alias for an existing class */
283
+ st.alias = function(klass, alias) {
284
+ st[alias] = klass;
285
+ }
264
286
 
265
287
  /* Add a package to the smalltalk.packages object, creating a new one if needed.
266
288
  If pkgName is null or empty we return nil, which is an allowed package for a class.
@@ -290,7 +312,7 @@ function Smalltalk(){
290
312
  st[className].superclass = superclass;
291
313
  st[className].iVarNames = iVarNames;
292
314
  st[className].pkg = pkg || st[className].pkg;
293
- } else {
315
+ } else {
294
316
  st[className] = klass({
295
317
  className: className,
296
318
  superclass: superclass,
@@ -303,31 +325,17 @@ function Smalltalk(){
303
325
  /* Add a method to a class */
304
326
 
305
327
  st.addMethod = function(jsSelector, method, klass) {
306
- klass.fn.prototype[jsSelector] = method.fn;
328
+ Object.defineProperty(klass.fn.prototype, jsSelector, {
329
+ value: method.fn, configurable: true // not writable - in par with ES6 methods
330
+ });
307
331
  klass.fn.prototype.methods[method.selector] = method;
308
332
  method.methodClass = klass;
309
333
  method.jsSelector = jsSelector;
310
334
  };
311
335
 
312
- /* Handles Smalltalk message send. Automatically converts undefined to the nil object.
313
- If the receiver does not understand the selector, call its #doesNotUnderstand: method */
314
-
315
- sendWithoutContext = function(receiver, selector, args, klass) {
316
- if(receiver === undefined || receiver === null) {
317
- receiver = nil;
318
- }
319
- if(!klass && receiver.klass && receiver[selector]) {
320
- return receiver[selector].apply(receiver, args);
321
- } else if(klass && klass.fn.prototype[selector]) {
322
- return klass.fn.prototype[selector].apply(receiver, args)
323
- }
324
- return messageNotUnderstood(receiver, selector, args);
325
- };
326
-
327
-
328
336
  /* Handles unhandled errors during message sends */
329
337
 
330
- sendWithContext = function(receiver, selector, args, klass) {
338
+ st.send = function(receiver, selector, args, klass) {
331
339
  if(st.thisContext) {
332
340
  return withContextSend(receiver, selector, args, klass);
333
341
  } else {
@@ -344,25 +352,20 @@ function Smalltalk(){
344
352
  }
345
353
  };
346
354
 
347
- /* Same as sendWithoutContext but creates a methodContext. */
348
-
349
- withContextSend = function(receiver, selector, args, klass) {
350
- var call, context;
351
- if(receiver === undefined || receiver === null) {
355
+ function withContextSend(receiver, selector, args, klass) {
356
+ var call, imp;
357
+ if(receiver == null) {
352
358
  receiver = nil;
353
359
  }
354
- if(!klass && receiver.klass && receiver[selector]) {
355
- context = pushContext(receiver, selector, args);
356
- call = receiver[selector].apply(receiver, args);
357
- popContext(context);
358
- return call;
359
- } else if(klass && klass.fn.prototype[selector]) {
360
- context = pushContext(receiver, selector, args);
361
- call = klass.fn.prototype[selector].apply(receiver, args);
360
+ imp = klass ? klass.fn.prototype[selector] : receiver.klass && receiver[selector];
361
+ if(imp) {
362
+ var context = pushContext(receiver, selector, args);
363
+ call = imp.apply(receiver, args);
362
364
  popContext(context);
363
365
  return call;
366
+ } else {
367
+ return messageNotUnderstood(receiver, selector, args);
364
368
  }
365
- return messageNotUnderstood(receiver, selector, args);
366
369
  };
367
370
 
368
371
  /* Handles Smalltalk errors. Triggers the registered ErrorHandler
@@ -371,7 +374,7 @@ function Smalltalk(){
371
374
  function handleError(error) {
372
375
  st.thisContext = undefined;
373
376
  smalltalk.ErrorHandler._current()._handleError_(error);
374
- }
377
+ };
375
378
 
376
379
  /* Handles #dnu: *and* JavaScript method calls.
377
380
  if the receiver has no klass, we consider it a JS object (outside of the
@@ -424,9 +427,9 @@ function Smalltalk(){
424
427
  };
425
428
 
426
429
 
427
- /* Reuse old contexts stored in oldContexts */
430
+ /* Reuse one old context stored in oldContext */
428
431
 
429
- st.oldContexts = [];
432
+ st.oldContext = null;
430
433
 
431
434
 
432
435
  /* Handle thisContext pseudo variable */
@@ -434,23 +437,28 @@ function Smalltalk(){
434
437
  st.getThisContext = function() {
435
438
  if(st.thisContext) {
436
439
  return st.thisContext.copy();
437
- } else {
440
+ }/* else { // this is the default
438
441
  return undefined;
439
- }
440
- }
442
+ }*/
443
+ };
441
444
 
442
- pushContext = function(receiver, selector, temps) {
443
- if(st.thisContext) {
444
- return st.thisContext = st.thisContext.newContext(receiver, selector, temps);
445
- } else {
446
- return st.thisContext = new SmalltalkMethodContext(receiver, selector, temps);
445
+ function pushContext(receiver, selector, temps) {
446
+ var c = st.oldContext, tc = st.thisContext;
447
+ if (!c) {
448
+ return st.thisContext = new SmalltalkMethodContext(receiver, selector, temps, tc);
447
449
  }
450
+ st.oldContext = null;
451
+ c.homeContext = tc;
452
+ c.receiver = receiver;
453
+ c.selector = selector;
454
+ c.temps = temps || {};
455
+ return st.thisContext = c;
448
456
  };
449
457
 
450
- popContext = function(context) {
451
- if(context) {
452
- context.removeYourself();
453
- }
458
+ function popContext(context) {
459
+ st.thisContext = context.homeContext;
460
+ context.homeContext = undefined;
461
+ st.oldContext = context;
454
462
  };
455
463
 
456
464
  /* Convert a string to a valid smalltalk selector.
@@ -502,57 +510,25 @@ function Smalltalk(){
502
510
  }
503
511
  return object;
504
512
  };
505
-
506
- /* Toggle deployment mode (no context will be handled during message send */
507
- st.setDeploymentMode = function() {
508
- st.send = sendWithoutContext;
509
- };
510
-
511
- st.setDevelopmentMode = function() {
512
- st.send = sendWithContext;
513
- }
514
-
515
- /* Set development mode by default */
516
- st.setDevelopmentMode();
517
- }
513
+ };
518
514
 
519
515
  function SmalltalkMethodContext(receiver, selector, temps, home) {
520
- var that = this;
521
- that.receiver = receiver;
522
- that.selector = selector;
523
- that.temps = temps || {};
524
- that.homeContext = home;
525
-
526
- that.copy = function() {
527
- var home = that.homeContext;
528
- if(home) {home = home.copy()}
529
- return new SmalltalkMethodContext(
530
- that.receiver,
531
- that.selector,
532
- that.temps,
533
- home
534
- );
535
- }
536
-
537
- that.newContext = function(receiver, selector, temps) {
538
- var c = smalltalk.oldContexts.pop();
539
- if(c) {
540
- c.homeContext = that;
541
- c.receiver = receiver;
542
- c.selector = selector;
543
- c.temps = temps || {};
544
- } else {
545
- c = new SmalltalkMethodContext(receiver, selector, temps, that);
546
- }
547
- return c;
548
- }
516
+ this.receiver = receiver;
517
+ this.selector = selector;
518
+ this.temps = temps || {};
519
+ this.homeContext = home;
520
+ };
549
521
 
550
- that.removeYourself = function() {
551
- smalltalk.thisContext = that.homeContext;
552
- that.homeContext = undefined;
553
- smalltalk.oldContexts.push(that);
554
- }
555
- }
522
+ SmalltalkMethodContext.prototype.copy = function() {
523
+ var home = this.homeContext;
524
+ if(home) {home = home.copy()}
525
+ return new SmalltalkMethodContext(
526
+ this.receiver,
527
+ this.selector,
528
+ this.temps,
529
+ home
530
+ );
531
+ };
556
532
 
557
533
  /* Global Smalltalk objects. */
558
534