4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.10 .0
8
- * @date Tue Aug 25 2020 14:05:30 GMT-0400 (Eastern Daylight Time)
7
+ * @version 2.11 .0
8
+ * @date Tue Jan 05 2021 15:55:59 GMT-0500 (Eastern Standard Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
12
12
*
13
- * Copyright (c) 2020 gpu.js Team
13
+ * Copyright (c) 2021 gpu.js Team
14
14
*/ ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . GPU = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function ( ) { function r ( e , n , t ) { function o ( i , f ) { if ( ! n [ i ] ) { if ( ! e [ i ] ) { var c = "function" == typeof require && require ; if ( ! f && c ) return c ( i , ! 0 ) ; if ( u ) return u ( i , ! 0 ) ; var a = new Error ( "Cannot find module '" + i + "'" ) ; throw a . code = "MODULE_NOT_FOUND" , a } var p = n [ i ] = { exports :{ } } ; e [ i ] [ 0 ] . call ( p . exports , function ( r ) { var n = e [ i ] [ 1 ] [ r ] ; return o ( n || r ) } , p , p . exports , r , e , n , t ) } return n [ i ] . exports } for ( var u = "function" == typeof require && require , i = 0 ; i < t . length ; i ++ ) o ( t [ i ] ) ; return o } return r } ) ( ) ( { 1 :[ function ( require , module , exports ) {
15
15
16
16
} , { } ] , 2 :[ function ( require , module , exports ) {
@@ -1020,18 +1020,6 @@ class CPUFunctionNode extends FunctionNode {
1020
1020
return retArr ;
1021
1021
}
1022
1022
break ;
1023
- case 'value.value[]' :
1024
- if ( this . removeIstanbulCoverage ) {
1025
- return retArr ;
1026
- }
1027
- retArr . push ( `${ mNode . object . object . name } .${ mNode . object . property . name } [${ mNode . property . value } ]` ) ;
1028
- return retArr ;
1029
- case 'value.value[][]' :
1030
- if ( this . removeIstanbulCoverage ) {
1031
- return retArr ;
1032
- }
1033
- retArr . push ( `${ mNode . object . object . object . name } .${ mNode . object . object . property . name } [${ mNode . object . property . value } ][${ mNode . property . value } ]` ) ;
1034
- return retArr ;
1035
1023
case 'this.constants.value' :
1036
1024
case 'this.constants.value[]' :
1037
1025
case 'this.constants.value[][]' :
@@ -2039,8 +2027,6 @@ class FunctionBuilder {
2039
2027
followingReturnStatement,
2040
2028
dynamicArguments,
2041
2029
dynamicOutput,
2042
- onIstanbulCoverageVariable,
2043
- removeIstanbulCoverage,
2044
2030
} = kernel ;
2045
2031
2046
2032
const argumentTypes = new Array ( kernelArguments . length ) ;
@@ -2091,12 +2077,12 @@ class FunctionBuilder {
2091
2077
functionBuilder . trackFunctionCall ( functionName , calleeFunctionName , args ) ;
2092
2078
} ;
2093
2079
2094
- const onNestedFunction = ( ast , returnType ) => {
2080
+ const onNestedFunction = ( ast , source ) => {
2095
2081
const argumentNames = [ ] ;
2096
2082
for ( let i = 0 ; i < ast . params . length ; i ++ ) {
2097
2083
argumentNames . push ( ast . params [ i ] . name ) ;
2098
2084
}
2099
- const nestedFunction = new FunctionNode ( null , Object . assign ( { } , nodeOptions , {
2085
+ const nestedFunction = new FunctionNode ( source , Object . assign ( { } , nodeOptions , {
2100
2086
returnType : null ,
2101
2087
ast,
2102
2088
name : ast . id . name ,
@@ -2127,8 +2113,6 @@ class FunctionBuilder {
2127
2113
triggerImplyArgumentType,
2128
2114
triggerImplyArgumentBitRatio,
2129
2115
onFunctionCall,
2130
- onIstanbulCoverageVariable : onIstanbulCoverageVariable ? ( name ) => onIstanbulCoverageVariable ( name , kernel ) : null ,
2131
- removeIstanbulCoverage,
2132
2116
optimizeFloatMemory,
2133
2117
precision,
2134
2118
constants,
@@ -2181,8 +2165,6 @@ class FunctionBuilder {
2181
2165
triggerImplyArgumentBitRatio,
2182
2166
onFunctionCall,
2183
2167
onNestedFunction,
2184
- onIstanbulCoverageVariable : onIstanbulCoverageVariable ? ( name ) => onIstanbulCoverageVariable ( name , kernel ) : null ,
2185
- removeIstanbulCoverage,
2186
2168
} ) ) ;
2187
2169
}
2188
2170
@@ -2259,8 +2241,12 @@ class FunctionBuilder {
2259
2241
retList = retList || [ ] ;
2260
2242
2261
2243
if ( this . nativeFunctionNames . indexOf ( functionName ) > - 1 ) {
2262
- if ( retList . indexOf ( functionName ) === - 1 ) {
2244
+ const nativeFunctionIndex = retList . indexOf ( functionName ) ;
2245
+ if ( nativeFunctionIndex === - 1 ) {
2263
2246
retList . push ( functionName ) ;
2247
+ } else {
2248
+ const dependantNativeFunctionName = retList . splice ( nativeFunctionIndex , 1 ) [ 0 ] ;
2249
+ retList . push ( dependantNativeFunctionName ) ;
2264
2250
}
2265
2251
return retList ;
2266
2252
}
@@ -2604,8 +2590,6 @@ class FunctionNode {
2604
2590
this . dynamicArguments = null ;
2605
2591
this . strictTypingChecking = false ;
2606
2592
this . fixIntegerDivisionAccuracy = null ;
2607
- this . onIstanbulCoverageVariable = null ;
2608
- this . removeIstanbulCoverage = false ;
2609
2593
2610
2594
if ( settings ) {
2611
2595
for ( const p in settings ) {
@@ -2681,7 +2665,7 @@ class FunctionNode {
2681
2665
2682
2666
if ( ast . type === 'MemberExpression' ) {
2683
2667
if ( ast . object && ast . property ) {
2684
- if ( ast . object . hasOwnProperty ( 'name' ) && ast . object . name [ 0 ] === '_ ') {
2668
+ if ( ast . object . hasOwnProperty ( 'name' ) && ast . object . name !== 'Math ') {
2685
2669
return this . astMemberExpressionUnroll ( ast . property ) ;
2686
2670
}
2687
2671
@@ -2772,7 +2756,7 @@ class FunctionNode {
2772
2756
}
2773
2757
2774
2758
for ( let i = 0 ; i < functions . length ; i ++ ) {
2775
- this . onNestedFunction ( functions [ i ] ) ;
2759
+ this . onNestedFunction ( functions [ i ] , this . source ) ;
2776
2760
}
2777
2761
}
2778
2762
@@ -2901,6 +2885,11 @@ class FunctionNode {
2901
2885
if ( this . getVariableSignature ( ast . callee , true ) === 'this.color' ) {
2902
2886
return null ;
2903
2887
}
2888
+ if ( ast . callee . type === 'MemberExpression' && ast . callee . object && ast . callee . property && ast . callee . property . name && ast . arguments ) {
2889
+ const functionName = ast . callee . property . name ;
2890
+ this . inferArgumentTypesIfNeeded ( functionName , ast . arguments ) ;
2891
+ return this . lookupReturnType ( functionName , ast , this ) ;
2892
+ }
2904
2893
throw this . astErrorOutput ( 'Unknown call expression' , ast ) ;
2905
2894
}
2906
2895
if ( ast . callee && ast . callee . name ) {
@@ -3341,8 +3330,6 @@ class FunctionNode {
3341
3330
'value[][][]' ,
3342
3331
'value[][][][]' ,
3343
3332
'value.value' ,
3344
- 'value.value[]' ,
3345
- 'value.value[][]' ,
3346
3333
'value.thread.value' ,
3347
3334
'this.thread.value' ,
3348
3335
'this.output.value' ,
@@ -3556,20 +3543,11 @@ class FunctionNode {
3556
3543
astThisExpression ( ast , retArr ) {
3557
3544
return retArr ;
3558
3545
}
3559
- isIstanbulAST ( ast ) {
3560
- const variableSignature = this . getVariableSignature ( ast ) ;
3561
- return variableSignature === 'value.value[]' || variableSignature === 'value.value[][]' ;
3562
- }
3563
3546
astSequenceExpression ( sNode , retArr ) {
3564
3547
const { expressions } = sNode ;
3565
3548
const sequenceResult = [ ] ;
3566
3549
for ( let i = 0 ; i < expressions . length ; i ++ ) {
3567
3550
const expression = expressions [ i ] ;
3568
- if ( this . removeIstanbulCoverage ) {
3569
- if ( expression . type === 'UpdateExpression' && this . isIstanbulAST ( expression . argument ) ) {
3570
- continue ;
3571
- }
3572
- }
3573
3551
const expressionResult = [ ] ;
3574
3552
this . astGeneric ( expression , expressionResult ) ;
3575
3553
sequenceResult . push ( expressionResult . join ( '' ) ) ;
@@ -3601,12 +3579,6 @@ class FunctionNode {
3601
3579
checkAndUpconvertBitwiseUnary ( uNode , retArr ) { }
3602
3580
3603
3581
astUpdateExpression ( uNode , retArr ) {
3604
- if ( this . removeIstanbulCoverage ) {
3605
- const signature = this . getVariableSignature ( uNode . argument ) ;
3606
- if ( this . isIstanbulAST ( uNode . argument ) ) {
3607
- return retArr ;
3608
- }
3609
- }
3610
3582
if ( uNode . prefix ) {
3611
3583
retArr . push ( uNode . operator ) ;
3612
3584
this . astGeneric ( uNode . argument , retArr ) ;
@@ -3810,28 +3782,8 @@ class FunctionNode {
3810
3782
signature : variableSignature ,
3811
3783
property : ast . property ,
3812
3784
} ;
3813
- case 'value.value[]' :
3814
- if ( this . removeIstanbulCoverage ) {
3815
- return { signature : variableSignature } ;
3816
- }
3817
- if ( this . onIstanbulCoverageVariable ) {
3818
- this . onIstanbulCoverageVariable ( ast . object . object . name ) ;
3819
- return {
3820
- signature : variableSignature
3821
- } ;
3822
- }
3823
- case 'value.value[][]' :
3824
- if ( this . removeIstanbulCoverage ) {
3825
- return { signature : variableSignature } ;
3826
- }
3827
- if ( this . onIstanbulCoverageVariable ) {
3828
- this . onIstanbulCoverageVariable ( ast . object . object . object . name ) ;
3829
- return {
3830
- signature : variableSignature
3831
- } ;
3832
- }
3833
- default :
3834
- throw this . astErrorOutput ( 'Unexpected expression' , ast ) ;
3785
+ default :
3786
+ throw this . astErrorOutput ( 'Unexpected expression' , ast ) ;
3835
3787
}
3836
3788
}
3837
3789
@@ -6307,8 +6259,6 @@ class Kernel {
6307
6259
this . optimizeFloatMemory = null ;
6308
6260
this . strictIntegers = false ;
6309
6261
this . fixIntegerDivisionAccuracy = null ;
6310
- this . onIstanbulCoverageVariable = null ;
6311
- this . removeIstanbulCoverage = false ;
6312
6262
this . built = false ;
6313
6263
this . signature = null ;
6314
6264
}
@@ -6335,11 +6285,6 @@ class Kernel {
6335
6285
}
6336
6286
this [ p ] = settings [ p ] ;
6337
6287
continue ;
6338
- case 'removeIstanbulCoverage' :
6339
- if ( settings [ p ] !== null ) {
6340
- this [ p ] = settings [ p ] ;
6341
- }
6342
- continue ;
6343
6288
case 'nativeFunctions' :
6344
6289
if ( ! settings . nativeFunctions ) continue ;
6345
6290
this . nativeFunctions = [ ] ;
@@ -8334,13 +8279,8 @@ class WebGLFunctionNode extends FunctionNode {
8334
8279
retArr . push ( this . memberExpressionPropertyMarkup ( property ) ) ;
8335
8280
retArr . push ( ']' ) ;
8336
8281
return retArr ;
8337
- case 'value.value[]' :
8338
- case 'value.value[][]' :
8339
- if ( this . removeIstanbulCoverage ) {
8340
- return retArr ;
8341
- }
8342
- default :
8343
- throw this . astErrorOutput ( 'Unexpected expression' , mNode ) ;
8282
+ default :
8283
+ throw this . astErrorOutput ( 'Unexpected expression' , mNode ) ;
8344
8284
}
8345
8285
8346
8286
if ( mNode . computed === false ) {
@@ -10179,7 +10119,6 @@ class WebGLKernel extends GLKernel {
10179
10119
10180
10120
this . maxTexSize = null ;
10181
10121
this . onRequestSwitchKernel = null ;
10182
- this . removeIstanbulCoverage = true ;
10183
10122
10184
10123
this . texture = null ;
10185
10124
this . mappedTextures = null ;
@@ -10376,7 +10315,7 @@ class WebGLKernel extends GLKernel {
10376
10315
return this . createTexture ( ) ;
10377
10316
} ;
10378
10317
const onRequestIndex = ( ) => {
10379
- return textureIndexes ++ ;
10318
+ return this . constantTextureCount + textureIndexes ++ ;
10380
10319
} ;
10381
10320
const onUpdateValueMismatch = ( constructor ) => {
10382
10321
this . switchKernels ( {
@@ -13534,8 +13473,6 @@ class GPU {
13534
13473
this . functions = [ ] ;
13535
13474
this . nativeFunctions = [ ] ;
13536
13475
this . injectedNative = null ;
13537
- this . onIstanbulCoverageVariable = settings . onIstanbulCoverageVariable || null ;
13538
- this . removeIstanbulCoverage = settings . hasOwnProperty ( 'removeIstanbulCoverage' ) ? settings . removeIstanbulCoverage : null ;
13539
13476
if ( this . mode === 'dev' ) return ;
13540
13477
this . chooseKernel ( ) ;
13541
13478
if ( settings . functions ) {
@@ -13711,8 +13648,6 @@ class GPU {
13711
13648
gpu : _kernel . gpu ,
13712
13649
validate,
13713
13650
returnType : _kernel . returnType ,
13714
- onIstanbulCoverageVariable : _kernel . onIstanbulCoverageVariable ,
13715
- removeIstanbulCoverage : _kernel . removeIstanbulCoverage ,
13716
13651
tactic : _kernel . tactic ,
13717
13652
onRequestFallback,
13718
13653
onRequestSwitchKernel,
@@ -13731,8 +13666,6 @@ class GPU {
13731
13666
functions : this . functions ,
13732
13667
nativeFunctions : this . nativeFunctions ,
13733
13668
injectedNative : this . injectedNative ,
13734
- onIstanbulCoverageVariable : this . onIstanbulCoverageVariable ,
13735
- removeIstanbulCoverage : this . removeIstanbulCoverage ,
13736
13669
gpu : this ,
13737
13670
validate,
13738
13671
onRequestFallback,
0 commit comments