@@ -8274,6 +8274,7 @@ VariableFrame.prototype.allNames = function (upTo, includeHidden) {
8274
8274
8275
8275
function JSCompiler ( outerScope ) {
8276
8276
this . implicitParamCount = 0 ;
8277
+ this . implicitMultiArgCount = 0 ;
8277
8278
this . params = 0 ;
8278
8279
this . gensymArgIndexes = new Map ( ) ;
8279
8280
this . scope = new Map ( ) ;
@@ -8286,17 +8287,19 @@ function JSCompiler(outerScope) {
8286
8287
this . scope . outerScope = outerScope ;
8287
8288
}
8288
8289
8289
- JSCompiler . prototype . C = Object . freeze ( {
8290
+ JSCompiler . prototype . C = {
8290
8291
// functions used in compiled rings
8291
- '__proto__' : null ,
8292
8292
'ring' : ( func , ...inputs ) => ( func . inputs = inputs , func ) ,
8293
8293
'invoke' : ( proc , func , argsList ) =>
8294
8294
func ? (
8295
8295
typeof func === 'function' ?
8296
- func . apply ( null , argsList . itemsArray ( ) . concat ( proc ) ) :
8296
+ func . apply (
8297
+ proc . blockReceiver ( ) ,
8298
+ argsList . itemsArray ( ) . concat ( proc )
8299
+ ) :
8297
8300
invoke ( func , argsList )
8298
8301
) : null
8299
- } ) ;
8302
+ } ;
8300
8303
8301
8304
JSCompiler . prototype . toString = ( ) => 'a JSCompiler' ;
8302
8305
@@ -8335,8 +8338,15 @@ JSCompiler.prototype.functionHead = function () {
8335
8338
str1 += 'proc=params.pop();\n' ;
8336
8339
switch ( params ) {
8337
8340
case - 1 :
8341
+ params = this . implicitParamCount ;
8338
8342
// implicit parameters mode
8339
- switch ( params = this . implicitParamCount ) {
8343
+ if ( this . implicitMultiArgCount ) {
8344
+ if ( params === this . implicitMultiArgCount ) {
8345
+ return str1 + 'var plist=new List(params);\n' ;
8346
+ }
8347
+ str1 += 'var plist=new List(params.slice());\n' ;
8348
+ }
8349
+ switch ( params ) {
8340
8350
case 0 :
8341
8351
return str1 ;
8342
8352
case 1 :
@@ -8392,6 +8402,9 @@ JSCompiler.prototype.findEmptySlot = function findEmptySlot(m) {
8392
8402
// don't look in rings (they are not current scope)
8393
8403
return false ;
8394
8404
}
8405
+ if ( m . selector === 'reportJSFunction' ) {
8406
+ return false ;
8407
+ }
8395
8408
m = m . children ;
8396
8409
var i = m . length ;
8397
8410
while ( i ) {
@@ -8407,8 +8420,8 @@ JSCompiler.prototype.compileFunctionBody = function (aContext) {
8407
8420
parameters = aContext . inputs ,
8408
8421
code ;
8409
8422
8410
- if ( block instanceof Array ) {
8411
- throw new Error ( 'can\'t compile empty ring ' ) ;
8423
+ if ( ! ( block instanceof BlockMorph ) ) {
8424
+ throw new Error ( 'compiling does not yet support\nempty rings ' ) ;
8412
8425
}
8413
8426
8414
8427
if ( parameters . length ) {
@@ -8554,6 +8567,24 @@ JSCompiler.prototype.compileExpression = function (block) {
8554
8567
')' ;
8555
8568
case 'reportNot' :
8556
8569
return '!' + this . compileInput ( inputs [ 0 ] ) ;
8570
+ case 'reifyScript' :
8571
+ case 'reifyReporter' :
8572
+ case 'reifyPredicate' :
8573
+ return new JSCompiler ( this . scope ) . compileFunctionBody ( {
8574
+ 'expression' : inputs [ 0 ] . children [ 0 ] ,
8575
+ 'inputs' : inputs [ 1 ] . inputs ( ) . map ( x => x . children [ 0 ] . blockSpec ) ,
8576
+ } ) ;
8577
+ case 'reportJSFunction' :
8578
+ //don't fill empty slots inside JavaScript function block
8579
+ target = this . params ;
8580
+ this . params = - 2 ;
8581
+ selector = 'proc.reportJSFunction(' +
8582
+ this . compileInput ( inputs [ 0 ] ) +
8583
+ ',' +
8584
+ this . compileInput ( inputs [ 1 ] ) +
8585
+ ')' ;
8586
+ this . params = target ;
8587
+ return selector ;
8557
8588
default :
8558
8589
if ( Process . prototype [ selector ] ) {
8559
8590
if ( selector . substring ( 0 , 6 ) === 'report' ) {
@@ -8599,17 +8630,18 @@ JSCompiler.prototype.compileInput = function (inp) {
8599
8630
if ( inp . isEmptySlot != null && inp . isEmptySlot ( ) ) {
8600
8631
if ( this . params === - 1 ) {
8601
8632
// implicit parameter
8633
+ if ( inp instanceof MultiArgMorph ) {
8634
+ this . implicitParamCount += 1 ;
8635
+ this . implicitMultiArgCount += 1 ;
8636
+ return 'plist' ;
8637
+ }
8602
8638
return 'params[' + this . implicitParamCount ++ + ']' ;
8603
8639
}
8640
+ if ( inp instanceof MultiArgMorph ) {
8641
+ return 'new List()' ;
8642
+ }
8604
8643
return '""' ;
8605
8644
}
8606
- if ( inp instanceof RingMorph ) {
8607
- inp = inp . children ;
8608
- return new JSCompiler ( this . scope ) . compileFunctionBody ( {
8609
- 'expression' : inp [ 0 ] . children [ 0 ] ,
8610
- 'inputs' : inp [ 1 ] . inputs ( ) . map ( x => x . children [ 0 ] . blockSpec ) ,
8611
- } ) ;
8612
- }
8613
8645
if ( inp instanceof MultiArgMorph ) {
8614
8646
return 'new List([' + this . compileInputs ( inp . inputs ( ) ) + '])' ;
8615
8647
}
0 commit comments