resin 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/amber/bin/amberc +10 -350
- data/amber/js/Benchfib.deploy.js +80 -89
- data/amber/js/Benchfib.js +80 -89
- data/amber/js/Canvas.deploy.js +558 -545
- data/amber/js/Canvas.js +563 -545
- data/amber/js/Compiler-AST.deploy.js +431 -243
- data/amber/js/Compiler-AST.js +487 -244
- data/amber/js/Compiler-Core.deploy.js +201 -1045
- data/amber/js/Compiler-Core.js +208 -1207
- data/amber/js/Compiler-Exceptions.deploy.js +37 -18
- data/amber/js/Compiler-Exceptions.js +42 -18
- data/amber/js/Compiler-IR.deploy.js +1071 -774
- data/amber/js/Compiler-IR.js +1194 -848
- data/amber/js/Compiler-Inlining.deploy.js +395 -373
- data/amber/js/Compiler-Inlining.js +395 -373
- data/amber/js/Compiler-Interpreter.deploy.js +1202 -0
- data/amber/js/Compiler-Interpreter.js +1631 -0
- data/amber/js/Compiler-Semantic.deploy.js +695 -600
- data/amber/js/Compiler-Semantic.js +721 -611
- data/amber/js/Compiler-Tests.deploy.js +699 -376
- data/amber/js/Compiler-Tests.js +834 -381
- data/amber/js/Compiler.deploy.js +8563 -1805
- data/amber/js/Compiler.js +11476 -2633
- data/amber/js/Examples.deploy.js +29 -29
- data/amber/js/Examples.js +29 -29
- data/amber/js/IDE.deploy.js +3292 -2649
- data/amber/js/IDE.js +3318 -2710
- data/amber/js/Importer-Exporter.deploy.js +393 -349
- data/amber/js/Importer-Exporter.js +398 -354
- data/amber/js/Kernel-Announcements.deploy.js +53 -44
- data/amber/js/Kernel-Announcements.js +55 -44
- data/amber/js/Kernel-Classes.deploy.js +566 -368
- data/amber/js/Kernel-Classes.js +660 -402
- data/amber/js/Kernel-Collections.deploy.js +1149 -1098
- data/amber/js/Kernel-Collections.js +1183 -1116
- data/amber/js/Kernel-Exceptions.deploy.js +173 -75
- data/amber/js/Kernel-Exceptions.js +215 -77
- data/amber/js/Kernel-Methods.deploy.js +530 -313
- data/amber/js/Kernel-Methods.js +632 -338
- data/amber/js/Kernel-Objects.deploy.js +1734 -1577
- data/amber/js/Kernel-Objects.js +1867 -1654
- data/amber/js/Kernel-Tests.deploy.js +1416 -973
- data/amber/js/Kernel-Tests.js +1495 -981
- data/amber/js/Kernel-Transcript.deploy.js +23 -24
- data/amber/js/Kernel-Transcript.js +25 -26
- data/amber/js/SUnit-Tests.deploy.js +402 -0
- data/amber/js/SUnit-Tests.js +518 -0
- data/amber/js/SUnit.deploy.js +535 -237
- data/amber/js/SUnit.js +634 -246
- data/amber/js/amber.js +90 -53
- data/amber/js/boot.js +441 -255
- data/amber/js/init.js +1 -3
- data/amber/js/lib/CodeMirror/codemirror.css +3 -0
- data/amber/js/lib/CodeMirror/codemirror.js +104 -55
- data/amber/js/lib/peg-0.7.0.min.js +9 -0
- data/amber/js/parser.js +1504 -802
- data/amber/js/parser.pegjs +170 -165
- data/amber/st/Canvas.st +6 -0
- data/amber/st/Compiler-AST.st +54 -3
- data/amber/st/Compiler-Core.st +6 -551
- data/amber/st/Compiler-Exceptions.st +4 -0
- data/amber/st/Compiler-IR.st +205 -87
- data/amber/st/Compiler-Interpreter.st +597 -0
- data/amber/st/Compiler-Semantic.st +46 -21
- data/amber/st/Compiler-Tests.st +254 -7
- data/amber/st/Compiler.st +3172 -1541
- data/amber/st/IDE.st +57 -93
- data/amber/st/Importer-Exporter.st +4 -7
- data/amber/st/Kernel-Announcements.st +8 -0
- data/amber/st/Kernel-Classes.st +149 -40
- data/amber/st/Kernel-Collections.st +43 -32
- data/amber/st/Kernel-Exceptions.st +70 -1
- data/amber/st/Kernel-Methods.st +165 -27
- data/amber/st/Kernel-Objects.st +215 -140
- data/amber/st/Kernel-Tests.st +195 -10
- data/amber/st/Kernel-Transcript.st +1 -3
- data/amber/st/SUnit-Tests.st +186 -0
- data/amber/st/SUnit.st +186 -14
- data/bin/resin +6 -0
- data/lib/resin/cli.rb +19 -0
- metadata +41 -25
- data/amber/js/lib/peg-0.6.2.min.js +0 -2
- data/bin/resin-compile +0 -6
- data/bin/runresin +0 -12
data/amber/st/Compiler-Core.st
CHANGED
@@ -85,12 +85,10 @@ evaluateExpression: aString
|
|
85
85
|
!
|
86
86
|
|
87
87
|
install: aString forClass: aBehavior category: anotherString
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
self setupClass: aBehavior.
|
93
|
-
^compiled
|
88
|
+
^ ClassBuilder new
|
89
|
+
installMethod: (self eval: (self compile: aString forClass: aBehavior))
|
90
|
+
forClass: aBehavior
|
91
|
+
category: anotherString
|
94
92
|
!
|
95
93
|
|
96
94
|
parse: aString
|
@@ -105,7 +103,7 @@ recompile: aClass
|
|
105
103
|
aClass methodDictionary do: [:each |
|
106
104
|
console log: aClass name, ' >> ', each selector.
|
107
105
|
self install: each source forClass: aClass category: each category].
|
108
|
-
self setupClass: aClass.
|
106
|
+
"self setupClass: aClass."
|
109
107
|
aClass isMetaclass ifFalse: [self recompile: aClass class]
|
110
108
|
!
|
111
109
|
|
@@ -113,10 +111,6 @@ recompileAll
|
|
113
111
|
Smalltalk current classes do: [:each |
|
114
112
|
Transcript show: each; cr.
|
115
113
|
[self recompile: each] valueWithTimeout: 100]
|
116
|
-
!
|
117
|
-
|
118
|
-
setupClass: aClass
|
119
|
-
<smalltalk.init(aClass)>
|
120
114
|
! !
|
121
115
|
|
122
116
|
!Compiler class methodsFor: 'compiling'!
|
@@ -149,7 +143,7 @@ visit: aNode
|
|
149
143
|
!
|
150
144
|
|
151
145
|
visitAll: aCollection
|
152
|
-
^ aCollection
|
146
|
+
^ aCollection collect: [ :each | self visit: each ]
|
153
147
|
!
|
154
148
|
|
155
149
|
visitAssignmentNode: aNode
|
@@ -294,542 +288,3 @@ translator
|
|
294
288
|
yourself
|
295
289
|
! !
|
296
290
|
|
297
|
-
AbstractCodeGenerator subclass: #FunCodeGenerator
|
298
|
-
instanceVariableNames: 'stream nestedBlocks earlyReturn currentSelector unknownVariables tempVariables messageSends referencedClasses classReferenced argVariables'
|
299
|
-
package: 'Compiler-Core'!
|
300
|
-
|
301
|
-
!FunCodeGenerator methodsFor: 'accessing'!
|
302
|
-
|
303
|
-
argVariables
|
304
|
-
^argVariables copy
|
305
|
-
!
|
306
|
-
|
307
|
-
knownVariables
|
308
|
-
^self pseudoVariables
|
309
|
-
addAll: self tempVariables;
|
310
|
-
addAll: self argVariables;
|
311
|
-
yourself
|
312
|
-
!
|
313
|
-
|
314
|
-
tempVariables
|
315
|
-
^tempVariables copy
|
316
|
-
!
|
317
|
-
|
318
|
-
unknownVariables
|
319
|
-
^unknownVariables copy
|
320
|
-
! !
|
321
|
-
|
322
|
-
!FunCodeGenerator methodsFor: 'compiling'!
|
323
|
-
|
324
|
-
compileNode: aNode
|
325
|
-
stream := '' writeStream.
|
326
|
-
self visit: aNode.
|
327
|
-
^stream contents
|
328
|
-
! !
|
329
|
-
|
330
|
-
!FunCodeGenerator methodsFor: 'initialization'!
|
331
|
-
|
332
|
-
initialize
|
333
|
-
super initialize.
|
334
|
-
stream := '' writeStream.
|
335
|
-
unknownVariables := #().
|
336
|
-
tempVariables := #().
|
337
|
-
argVariables := #().
|
338
|
-
messageSends := #().
|
339
|
-
classReferenced := #()
|
340
|
-
! !
|
341
|
-
|
342
|
-
!FunCodeGenerator methodsFor: 'optimizations'!
|
343
|
-
|
344
|
-
checkClass: aClassName for: receiver
|
345
|
-
stream nextPutAll: '((($receiver = ', receiver, ').klass === smalltalk.', aClassName, ') ? '
|
346
|
-
!
|
347
|
-
|
348
|
-
inline: aSelector receiver: receiver argumentNodes: aCollection
|
349
|
-
| inlined |
|
350
|
-
inlined := false.
|
351
|
-
|
352
|
-
"-- Booleans --"
|
353
|
-
|
354
|
-
(aSelector = 'ifFalse:') ifTrue: [
|
355
|
-
aCollection first isBlockNode ifTrue: [
|
356
|
-
self checkClass: 'Boolean' for: receiver.
|
357
|
-
stream nextPutAll: '(!! $receiver ? '.
|
358
|
-
self visit: aCollection first.
|
359
|
-
stream nextPutAll: '() : nil)'.
|
360
|
-
inlined := true]].
|
361
|
-
|
362
|
-
(aSelector = 'ifTrue:') ifTrue: [
|
363
|
-
aCollection first isBlockNode ifTrue: [
|
364
|
-
self checkClass: 'Boolean' for: receiver.
|
365
|
-
stream nextPutAll: '($receiver ? '.
|
366
|
-
self visit: aCollection first.
|
367
|
-
stream nextPutAll: '() : nil)'.
|
368
|
-
inlined := true]].
|
369
|
-
|
370
|
-
(aSelector = 'ifTrue:ifFalse:') ifTrue: [
|
371
|
-
(aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
|
372
|
-
self checkClass: 'Boolean' for: receiver.
|
373
|
-
stream nextPutAll: '($receiver ? '.
|
374
|
-
self visit: aCollection first.
|
375
|
-
stream nextPutAll: '() : '.
|
376
|
-
self visit: aCollection second.
|
377
|
-
stream nextPutAll: '())'.
|
378
|
-
inlined := true]].
|
379
|
-
|
380
|
-
(aSelector = 'ifFalse:ifTrue:') ifTrue: [
|
381
|
-
(aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
|
382
|
-
self checkClass: 'Boolean' for: receiver.
|
383
|
-
stream nextPutAll: '(!! $receiver ? '.
|
384
|
-
self visit: aCollection first.
|
385
|
-
stream nextPutAll: '() : '.
|
386
|
-
self visit: aCollection second.
|
387
|
-
stream nextPutAll: '())'.
|
388
|
-
inlined := true]].
|
389
|
-
|
390
|
-
"-- Numbers --"
|
391
|
-
|
392
|
-
(aSelector = '<') ifTrue: [
|
393
|
-
self checkClass: 'Number' for: receiver.
|
394
|
-
stream nextPutAll: '$receiver <'.
|
395
|
-
self visit: aCollection first.
|
396
|
-
inlined := true].
|
397
|
-
|
398
|
-
(aSelector = '<=') ifTrue: [
|
399
|
-
self checkClass: 'Number' for: receiver.
|
400
|
-
stream nextPutAll: '$receiver <='.
|
401
|
-
self visit: aCollection first.
|
402
|
-
inlined := true].
|
403
|
-
|
404
|
-
(aSelector = '>') ifTrue: [
|
405
|
-
self checkClass: 'Number' for: receiver.
|
406
|
-
stream nextPutAll: '$receiver >'.
|
407
|
-
self visit: aCollection first.
|
408
|
-
inlined := true].
|
409
|
-
|
410
|
-
(aSelector = '>=') ifTrue: [
|
411
|
-
self checkClass: 'Number' for: receiver.
|
412
|
-
stream nextPutAll: '$receiver >='.
|
413
|
-
self visit: aCollection first.
|
414
|
-
inlined := true].
|
415
|
-
|
416
|
-
(aSelector = '+') ifTrue: [
|
417
|
-
self checkClass: 'Number' for: receiver.
|
418
|
-
stream nextPutAll: '$receiver +'.
|
419
|
-
self visit: aCollection first.
|
420
|
-
inlined := true].
|
421
|
-
|
422
|
-
(aSelector = '-') ifTrue: [
|
423
|
-
self checkClass: 'Number' for: receiver.
|
424
|
-
stream nextPutAll: '$receiver -'.
|
425
|
-
self visit: aCollection first.
|
426
|
-
inlined := true].
|
427
|
-
|
428
|
-
(aSelector = '*') ifTrue: [
|
429
|
-
self checkClass: 'Number' for: receiver.
|
430
|
-
stream nextPutAll: '$receiver *'.
|
431
|
-
self visit: aCollection first.
|
432
|
-
inlined := true].
|
433
|
-
|
434
|
-
(aSelector = '/') ifTrue: [
|
435
|
-
self checkClass: 'Number' for: receiver.
|
436
|
-
stream nextPutAll: '$receiver /'.
|
437
|
-
self visit: aCollection first.
|
438
|
-
inlined := true].
|
439
|
-
|
440
|
-
^inlined
|
441
|
-
!
|
442
|
-
|
443
|
-
inlineLiteral: aSelector receiverNode: anObject argumentNodes: aCollection
|
444
|
-
| inlined |
|
445
|
-
inlined := false.
|
446
|
-
|
447
|
-
"-- BlockClosures --"
|
448
|
-
|
449
|
-
(aSelector = 'whileTrue:') ifTrue: [
|
450
|
-
(anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
|
451
|
-
stream nextPutAll: '(function(){while('.
|
452
|
-
self visit: anObject.
|
453
|
-
stream nextPutAll: '()) {'.
|
454
|
-
self visit: aCollection first.
|
455
|
-
stream nextPutAll: '()}})()'.
|
456
|
-
inlined := true]].
|
457
|
-
|
458
|
-
(aSelector = 'whileFalse:') ifTrue: [
|
459
|
-
(anObject isBlockNode and: [aCollection first isBlockNode]) ifTrue: [
|
460
|
-
stream nextPutAll: '(function(){while(!!'.
|
461
|
-
self visit: anObject.
|
462
|
-
stream nextPutAll: '()) {'.
|
463
|
-
self visit: aCollection first.
|
464
|
-
stream nextPutAll: '()}})()'.
|
465
|
-
inlined := true]].
|
466
|
-
|
467
|
-
(aSelector = 'whileTrue') ifTrue: [
|
468
|
-
anObject isBlockNode ifTrue: [
|
469
|
-
stream nextPutAll: '(function(){while('.
|
470
|
-
self visit: anObject.
|
471
|
-
stream nextPutAll: '()) {}})()'.
|
472
|
-
inlined := true]].
|
473
|
-
|
474
|
-
(aSelector = 'whileFalse') ifTrue: [
|
475
|
-
anObject isBlockNode ifTrue: [
|
476
|
-
stream nextPutAll: '(function(){while(!!'.
|
477
|
-
self visit: anObject.
|
478
|
-
stream nextPutAll: '()) {}})()'.
|
479
|
-
inlined := true]].
|
480
|
-
|
481
|
-
"-- Numbers --"
|
482
|
-
|
483
|
-
(aSelector = '+') ifTrue: [
|
484
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
485
|
-
self visit: anObject.
|
486
|
-
stream nextPutAll: ' + '.
|
487
|
-
self visit: aCollection first.
|
488
|
-
inlined := true]].
|
489
|
-
|
490
|
-
(aSelector = '-') ifTrue: [
|
491
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
492
|
-
self visit: anObject.
|
493
|
-
stream nextPutAll: ' - '.
|
494
|
-
self visit: aCollection first.
|
495
|
-
inlined := true]].
|
496
|
-
|
497
|
-
(aSelector = '*') ifTrue: [
|
498
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
499
|
-
self visit: anObject.
|
500
|
-
stream nextPutAll: ' * '.
|
501
|
-
self visit: aCollection first.
|
502
|
-
inlined := true]].
|
503
|
-
|
504
|
-
(aSelector = '/') ifTrue: [
|
505
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
506
|
-
self visit: anObject.
|
507
|
-
stream nextPutAll: ' / '.
|
508
|
-
self visit: aCollection first.
|
509
|
-
inlined := true]].
|
510
|
-
|
511
|
-
(aSelector = '<') ifTrue: [
|
512
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
513
|
-
self visit: anObject.
|
514
|
-
stream nextPutAll: ' < '.
|
515
|
-
self visit: aCollection first.
|
516
|
-
inlined := true]].
|
517
|
-
|
518
|
-
(aSelector = '<=') ifTrue: [
|
519
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
520
|
-
self visit: anObject.
|
521
|
-
stream nextPutAll: ' <= '.
|
522
|
-
self visit: aCollection first.
|
523
|
-
inlined := true]].
|
524
|
-
|
525
|
-
(aSelector = '>') ifTrue: [
|
526
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
527
|
-
self visit: anObject.
|
528
|
-
stream nextPutAll: ' > '.
|
529
|
-
self visit: aCollection first.
|
530
|
-
inlined := true]].
|
531
|
-
|
532
|
-
(aSelector = '>=') ifTrue: [
|
533
|
-
(self isNode: anObject ofClass: Number) ifTrue: [
|
534
|
-
self visit: anObject.
|
535
|
-
stream nextPutAll: ' >= '.
|
536
|
-
self visit: aCollection first.
|
537
|
-
inlined := true]].
|
538
|
-
|
539
|
-
"-- UndefinedObject --"
|
540
|
-
|
541
|
-
(aSelector = 'ifNil:') ifTrue: [
|
542
|
-
aCollection first isBlockNode ifTrue: [
|
543
|
-
stream nextPutAll: '(($receiver = '.
|
544
|
-
self visit: anObject.
|
545
|
-
stream nextPutAll: ') == nil || $receiver == undefined) ? '.
|
546
|
-
self visit: aCollection first.
|
547
|
-
stream nextPutAll: '() : $receiver'.
|
548
|
-
inlined := true]].
|
549
|
-
|
550
|
-
(aSelector = 'ifNotNil:') ifTrue: [
|
551
|
-
aCollection first isBlockNode ifTrue: [
|
552
|
-
stream nextPutAll: '(($receiver = '.
|
553
|
-
self visit: anObject.
|
554
|
-
stream nextPutAll: ') !!= nil && $receiver !!= undefined) ? '.
|
555
|
-
self visit: aCollection first.
|
556
|
-
stream nextPutAll: '() : nil'.
|
557
|
-
inlined := true]].
|
558
|
-
|
559
|
-
(aSelector = 'ifNil:ifNotNil:') ifTrue: [
|
560
|
-
(aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
|
561
|
-
stream nextPutAll: '(($receiver = '.
|
562
|
-
self visit: anObject.
|
563
|
-
stream nextPutAll: ') == nil || $receiver == undefined) ? '.
|
564
|
-
self visit: aCollection first.
|
565
|
-
stream nextPutAll: '() : '.
|
566
|
-
self visit: aCollection second.
|
567
|
-
stream nextPutAll: '()'.
|
568
|
-
inlined := true]].
|
569
|
-
|
570
|
-
(aSelector = 'ifNotNil:ifNil:') ifTrue: [
|
571
|
-
(aCollection first isBlockNode and: [aCollection second isBlockNode]) ifTrue: [
|
572
|
-
stream nextPutAll: '(($receiver = '.
|
573
|
-
self visit: anObject.
|
574
|
-
stream nextPutAll: ') == nil || $receiver == undefined) ? '.
|
575
|
-
self visit: aCollection second.
|
576
|
-
stream nextPutAll: '() : '.
|
577
|
-
self visit: aCollection first.
|
578
|
-
stream nextPutAll: '()'.
|
579
|
-
inlined := true]].
|
580
|
-
|
581
|
-
^inlined
|
582
|
-
!
|
583
|
-
|
584
|
-
isNode: aNode ofClass: aClass
|
585
|
-
^aNode isValueNode and: [
|
586
|
-
aNode value class = aClass or: [
|
587
|
-
aNode value = 'self' and: [self currentClass = aClass]]]
|
588
|
-
! !
|
589
|
-
|
590
|
-
!FunCodeGenerator methodsFor: 'testing'!
|
591
|
-
|
592
|
-
performOptimizations
|
593
|
-
^self class performOptimizations
|
594
|
-
! !
|
595
|
-
|
596
|
-
!FunCodeGenerator methodsFor: 'visiting'!
|
597
|
-
|
598
|
-
send: aSelector to: aReceiver arguments: aCollection superSend: aBoolean
|
599
|
-
^String streamContents: [:str || tmp |
|
600
|
-
tmp := stream.
|
601
|
-
str nextPutAll: 'smalltalk.send('.
|
602
|
-
str nextPutAll: aReceiver.
|
603
|
-
str nextPutAll: ', "', aSelector asSelector, '", ['.
|
604
|
-
stream := str.
|
605
|
-
aCollection
|
606
|
-
do: [:each | self visit: each]
|
607
|
-
separatedBy: [stream nextPutAll: ', '].
|
608
|
-
stream := tmp.
|
609
|
-
str nextPutAll: ']'.
|
610
|
-
aBoolean ifTrue: [
|
611
|
-
str nextPutAll: ', smalltalk.', (self classNameFor: self currentClass), '.superclass || nil'].
|
612
|
-
str nextPutAll: ')']
|
613
|
-
!
|
614
|
-
|
615
|
-
visit: aNode
|
616
|
-
aNode accept: self
|
617
|
-
!
|
618
|
-
|
619
|
-
visitAssignmentNode: aNode
|
620
|
-
stream nextPutAll: '('.
|
621
|
-
self visit: aNode left.
|
622
|
-
stream nextPutAll: '='.
|
623
|
-
self visit: aNode right.
|
624
|
-
stream nextPutAll: ')'
|
625
|
-
!
|
626
|
-
|
627
|
-
visitBlockNode: aNode
|
628
|
-
stream nextPutAll: '(function('.
|
629
|
-
aNode parameters
|
630
|
-
do: [:each |
|
631
|
-
tempVariables add: each.
|
632
|
-
stream nextPutAll: each]
|
633
|
-
separatedBy: [stream nextPutAll: ', '].
|
634
|
-
stream nextPutAll: '){'.
|
635
|
-
aNode nodes do: [:each | self visit: each].
|
636
|
-
stream nextPutAll: '})'
|
637
|
-
!
|
638
|
-
|
639
|
-
visitBlockSequenceNode: aNode
|
640
|
-
| index |
|
641
|
-
nestedBlocks := nestedBlocks + 1.
|
642
|
-
aNode nodes isEmpty
|
643
|
-
ifTrue: [
|
644
|
-
stream nextPutAll: 'return nil;']
|
645
|
-
ifFalse: [
|
646
|
-
aNode temps do: [:each | | temp |
|
647
|
-
temp := self safeVariableNameFor: each.
|
648
|
-
tempVariables add: temp.
|
649
|
-
stream nextPutAll: 'var ', temp, '=nil;'; lf].
|
650
|
-
index := 0.
|
651
|
-
aNode nodes do: [:each |
|
652
|
-
index := index + 1.
|
653
|
-
index = aNode nodes size ifTrue: [
|
654
|
-
stream nextPutAll: 'return '].
|
655
|
-
self visit: each.
|
656
|
-
stream nextPutAll: ';']].
|
657
|
-
nestedBlocks := nestedBlocks - 1
|
658
|
-
!
|
659
|
-
|
660
|
-
visitCascadeNode: aNode
|
661
|
-
| index |
|
662
|
-
index := 0.
|
663
|
-
(tempVariables includes: '$rec') ifFalse: [
|
664
|
-
tempVariables add: '$rec'].
|
665
|
-
stream nextPutAll: '(function($rec){'.
|
666
|
-
aNode nodes do: [:each |
|
667
|
-
index := index + 1.
|
668
|
-
index = aNode nodes size ifTrue: [
|
669
|
-
stream nextPutAll: 'return '].
|
670
|
-
each receiver: (VariableNode new value: '$rec').
|
671
|
-
self visit: each.
|
672
|
-
stream nextPutAll: ';'].
|
673
|
-
stream nextPutAll: '})('.
|
674
|
-
self visit: aNode receiver.
|
675
|
-
stream nextPutAll: ')'
|
676
|
-
!
|
677
|
-
|
678
|
-
visitClassReferenceNode: aNode
|
679
|
-
(referencedClasses includes: aNode value) ifFalse: [
|
680
|
-
referencedClasses add: aNode value].
|
681
|
-
stream nextPutAll: '(smalltalk.', aNode value, ' || ', aNode value, ')'
|
682
|
-
!
|
683
|
-
|
684
|
-
visitDynamicArrayNode: aNode
|
685
|
-
stream nextPutAll: '['.
|
686
|
-
aNode nodes
|
687
|
-
do: [:each | self visit: each]
|
688
|
-
separatedBy: [stream nextPutAll: ','].
|
689
|
-
stream nextPutAll: ']'
|
690
|
-
!
|
691
|
-
|
692
|
-
visitDynamicDictionaryNode: aNode
|
693
|
-
stream nextPutAll: 'smalltalk.HashedCollection._fromPairs_(['.
|
694
|
-
aNode nodes
|
695
|
-
do: [:each | self visit: each]
|
696
|
-
separatedBy: [stream nextPutAll: ','].
|
697
|
-
stream nextPutAll: '])'
|
698
|
-
!
|
699
|
-
|
700
|
-
visitFailure: aFailure
|
701
|
-
self error: aFailure asString
|
702
|
-
!
|
703
|
-
|
704
|
-
visitJSStatementNode: aNode
|
705
|
-
stream nextPutAll: aNode source
|
706
|
-
!
|
707
|
-
|
708
|
-
visitMethodNode: aNode
|
709
|
-
| str currentSelector |
|
710
|
-
currentSelector := aNode selector asSelector.
|
711
|
-
nestedBlocks := 0.
|
712
|
-
earlyReturn := false.
|
713
|
-
messageSends := #().
|
714
|
-
referencedClasses := #().
|
715
|
-
unknownVariables := #().
|
716
|
-
tempVariables := #().
|
717
|
-
argVariables := #().
|
718
|
-
stream
|
719
|
-
nextPutAll: 'smalltalk.method({'; lf;
|
720
|
-
nextPutAll: 'selector: "', aNode selector, '",'; lf.
|
721
|
-
stream nextPutAll: 'source: ', self source asJavascript, ',';lf.
|
722
|
-
stream nextPutAll: 'fn: function('.
|
723
|
-
aNode arguments
|
724
|
-
do: [:each |
|
725
|
-
argVariables add: each.
|
726
|
-
stream nextPutAll: each]
|
727
|
-
separatedBy: [stream nextPutAll: ', '].
|
728
|
-
stream
|
729
|
-
nextPutAll: '){'; lf;
|
730
|
-
nextPutAll: 'var self=this;'; lf.
|
731
|
-
str := stream.
|
732
|
-
stream := '' writeStream.
|
733
|
-
aNode nodes do: [:each |
|
734
|
-
self visit: each].
|
735
|
-
earlyReturn ifTrue: [
|
736
|
-
str nextPutAll: 'var $early={};'; lf; nextPutAll: 'try{'].
|
737
|
-
str nextPutAll: stream contents.
|
738
|
-
stream := str.
|
739
|
-
stream
|
740
|
-
lf;
|
741
|
-
nextPutAll: 'return self;'.
|
742
|
-
earlyReturn ifTrue: [
|
743
|
-
stream lf; nextPutAll: '} catch(e) {if(e===$early)return e[0]; throw e}'].
|
744
|
-
stream nextPutAll: '}'.
|
745
|
-
stream
|
746
|
-
nextPutAll: ',', String lf, 'messageSends: ';
|
747
|
-
nextPutAll: messageSends asJavascript, ','; lf;
|
748
|
-
nextPutAll: 'args: ', argVariables asJavascript, ','; lf;
|
749
|
-
nextPutAll: 'referencedClasses: ['.
|
750
|
-
referencedClasses
|
751
|
-
do: [:each | stream nextPutAll: each printString]
|
752
|
-
separatedBy: [stream nextPutAll: ','].
|
753
|
-
stream nextPutAll: ']'.
|
754
|
-
stream nextPutAll: '})'
|
755
|
-
!
|
756
|
-
|
757
|
-
visitReturnNode: aNode
|
758
|
-
nestedBlocks > 0 ifTrue: [
|
759
|
-
earlyReturn := true].
|
760
|
-
nestedBlocks > 0
|
761
|
-
ifTrue: [
|
762
|
-
stream
|
763
|
-
nextPutAll: '(function(){throw $early=[']
|
764
|
-
ifFalse: [stream nextPutAll: 'return '].
|
765
|
-
aNode nodes do: [:each |
|
766
|
-
self visit: each].
|
767
|
-
nestedBlocks > 0 ifTrue: [
|
768
|
-
stream nextPutAll: ']})()']
|
769
|
-
!
|
770
|
-
|
771
|
-
visitSendNode: aNode
|
772
|
-
| str receiver superSend inlined |
|
773
|
-
str := stream.
|
774
|
-
(messageSends includes: aNode selector) ifFalse: [
|
775
|
-
messageSends add: aNode selector].
|
776
|
-
stream := '' writeStream.
|
777
|
-
self visit: aNode receiver.
|
778
|
-
superSend := stream contents = 'super'.
|
779
|
-
receiver := superSend ifTrue: ['self'] ifFalse: [stream contents].
|
780
|
-
stream := str.
|
781
|
-
|
782
|
-
self performOptimizations
|
783
|
-
ifTrue: [
|
784
|
-
(self inlineLiteral: aNode selector receiverNode: aNode receiver argumentNodes: aNode arguments) ifFalse: [
|
785
|
-
(self inline: aNode selector receiver: receiver argumentNodes: aNode arguments)
|
786
|
-
ifTrue: [stream nextPutAll: ' : ', (self send: aNode selector to: '$receiver' arguments: aNode arguments superSend: superSend), ')']
|
787
|
-
ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]]]
|
788
|
-
ifFalse: [stream nextPutAll: (self send: aNode selector to: receiver arguments: aNode arguments superSend: superSend)]
|
789
|
-
!
|
790
|
-
|
791
|
-
visitSequenceNode: aNode
|
792
|
-
aNode temps do: [:each || temp |
|
793
|
-
temp := self safeVariableNameFor: each.
|
794
|
-
tempVariables add: temp.
|
795
|
-
stream nextPutAll: 'var ', temp, '=nil;'; lf].
|
796
|
-
aNode nodes do: [:each |
|
797
|
-
self visit: each.
|
798
|
-
stream nextPutAll: ';']
|
799
|
-
separatedBy: [stream lf]
|
800
|
-
!
|
801
|
-
|
802
|
-
visitValueNode: aNode
|
803
|
-
stream nextPutAll: aNode value asJavascript
|
804
|
-
!
|
805
|
-
|
806
|
-
visitVariableNode: aNode
|
807
|
-
| varName |
|
808
|
-
(self currentClass allInstanceVariableNames includes: aNode value)
|
809
|
-
ifTrue: [stream nextPutAll: 'self[''@', aNode value, ''']']
|
810
|
-
ifFalse: [
|
811
|
-
varName := self safeVariableNameFor: aNode value.
|
812
|
-
(self knownVariables includes: varName)
|
813
|
-
ifFalse: [
|
814
|
-
unknownVariables add: aNode value.
|
815
|
-
aNode assigned
|
816
|
-
ifTrue: [stream nextPutAll: varName]
|
817
|
-
ifFalse: [stream nextPutAll: '(typeof ', varName, ' == ''undefined'' ? nil : ', varName, ')']]
|
818
|
-
ifTrue: [
|
819
|
-
aNode value = 'thisContext'
|
820
|
-
ifTrue: [stream nextPutAll: '(smalltalk.getThisContext())']
|
821
|
-
ifFalse: [stream nextPutAll: varName]]]
|
822
|
-
! !
|
823
|
-
|
824
|
-
FunCodeGenerator class instanceVariableNames: 'performOptimizations'!
|
825
|
-
|
826
|
-
!FunCodeGenerator class methodsFor: 'accessing'!
|
827
|
-
|
828
|
-
performOptimizations
|
829
|
-
^performOptimizations ifNil: [true]
|
830
|
-
!
|
831
|
-
|
832
|
-
performOptimizations: aBoolean
|
833
|
-
performOptimizations := aBoolean
|
834
|
-
! !
|
835
|
-
|