4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.0.0-rc.16
8
- * @date Thu Jun 20 2019 10:09:00 GMT-0400 (Eastern Daylight Time)
7
+ * @version 2.0.0-rc.17
8
+ * @date Mon Jun 24 2019 21: 10:10 GMT-0400 (Eastern Daylight Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
@@ -1677,12 +1677,16 @@ class FunctionBuilder {
1677
1677
dynamicOutput,
1678
1678
} = kernel ;
1679
1679
1680
- const lookupReturnType = ( functionName , ast , requestingNode ) => {
1681
- return functionBuilder . lookupReturnType ( functionName , ast , requestingNode ) ;
1680
+ const needsArgumentType = ( functionName , index ) => {
1681
+ return functionBuilder . needsArgumentType ( functionName , index ) ;
1682
1682
} ;
1683
1683
1684
- const lookupArgumentType = ( argumentName , requestingNode ) => {
1685
- return functionBuilder . lookupArgumentType ( argumentName , requestingNode ) ;
1684
+ const assignArgumentType = ( functionName , index , type ) => {
1685
+ functionBuilder . assignArgumentType ( functionName , index , type ) ;
1686
+ } ;
1687
+
1688
+ const lookupReturnType = ( functionName , ast , requestingNode ) => {
1689
+ return functionBuilder . lookupReturnType ( functionName , ast , requestingNode ) ;
1686
1690
} ;
1687
1691
1688
1692
const lookupFunctionArgumentTypes = ( functionName ) => {
@@ -1724,10 +1728,11 @@ class FunctionBuilder {
1724
1728
name : ast . id . name ,
1725
1729
argumentNames,
1726
1730
lookupReturnType,
1727
- lookupArgumentType,
1728
1731
lookupFunctionArgumentTypes,
1729
1732
lookupFunctionArgumentName,
1730
1733
lookupFunctionArgumentBitRatio,
1734
+ needsArgumentType,
1735
+ assignArgumentType,
1731
1736
triggerImplyArgumentType,
1732
1737
triggerTrackArgumentSynonym,
1733
1738
lookupArgumentSynonym,
@@ -1741,10 +1746,11 @@ class FunctionBuilder {
1741
1746
isRootKernel : false ,
1742
1747
onNestedFunction,
1743
1748
lookupReturnType,
1744
- lookupArgumentType,
1745
1749
lookupFunctionArgumentTypes,
1746
1750
lookupFunctionArgumentName,
1747
1751
lookupFunctionArgumentBitRatio,
1752
+ needsArgumentType,
1753
+ assignArgumentType,
1748
1754
triggerImplyArgumentType,
1749
1755
triggerTrackArgumentSynonym,
1750
1756
lookupArgumentSynonym,
@@ -1791,10 +1797,11 @@ class FunctionBuilder {
1791
1797
optimizeFloatMemory,
1792
1798
precision,
1793
1799
lookupReturnType,
1794
- lookupArgumentType,
1795
1800
lookupFunctionArgumentTypes,
1796
1801
lookupFunctionArgumentName,
1797
1802
lookupFunctionArgumentBitRatio,
1803
+ needsArgumentType,
1804
+ assignArgumentType,
1798
1805
triggerImplyArgumentType,
1799
1806
triggerTrackArgumentSynonym,
1800
1807
lookupArgumentSynonym,
@@ -1974,37 +1981,6 @@ class FunctionBuilder {
1974
1981
return this . getStringFromFunctionNames ( Object . keys ( this . functionMap ) ) ;
1975
1982
}
1976
1983
1977
- lookupArgumentType ( argumentName , requestingNode ) {
1978
- const index = requestingNode . argumentNames . indexOf ( argumentName ) ;
1979
- if ( index === - 1 ) {
1980
- return null ;
1981
- }
1982
- if ( this . lookupChain . length === 0 ) {
1983
- return null ;
1984
- }
1985
- let link = this . lookupChain [ this . lookupChain . length - 1 - this . argumentChain . length ] ;
1986
- if ( ! link ) {
1987
- return null ;
1988
- }
1989
- const {
1990
- ast,
1991
- requestingNode : parentRequestingNode
1992
- } = link ;
1993
- if ( ast . arguments . length === 0 ) {
1994
- return null ;
1995
- }
1996
- const usedArgument = ast . arguments [ index ] ;
1997
- if ( ! usedArgument ) {
1998
- return null ;
1999
- }
2000
-
2001
- this . argumentChain . push ( argumentName ) ;
2002
-
2003
- const type = parentRequestingNode . getType ( usedArgument ) ;
2004
- this . argumentChain . pop ( ) ;
2005
- return type ;
2006
- }
2007
-
2008
1984
lookupReturnType ( functionName , ast , requestingNode ) {
2009
1985
if ( ast . type !== 'CallExpression' ) {
2010
1986
throw new Error ( `expected ast type of "CallExpression", but is ${ ast . type } ` ) ;
@@ -2047,6 +2023,7 @@ class FunctionBuilder {
2047
2023
}
2048
2024
2049
2025
return null ;
2026
+
2050
2027
}
2051
2028
2052
2029
_getFunction ( functionName ) {
@@ -2113,6 +2090,12 @@ class FunctionBuilder {
2113
2090
}
2114
2091
}
2115
2092
2093
+ needsArgumentType ( functionName , i ) {
2094
+ if ( ! this . _isFunction ( functionName ) ) return false ;
2095
+ const fnNode = this . _getFunction ( functionName ) ;
2096
+ return ! fnNode . argumentTypes [ i ] ;
2097
+ }
2098
+
2116
2099
assignArgumentType ( functionName , i , argumentType , requestingNode ) {
2117
2100
if ( ! this . _isFunction ( functionName ) ) return ;
2118
2101
const fnNode = this . _getFunction ( functionName ) ;
@@ -2228,8 +2211,9 @@ class FunctionNode {
2228
2211
this . contexts = null ;
2229
2212
this . functionCalls = null ;
2230
2213
this . states = [ ] ;
2214
+ this . needsArgumentType = null ;
2215
+ this . assignArgumentType = null ;
2231
2216
this . lookupReturnType = null ;
2232
- this . lookupArgumentType = null ;
2233
2217
this . lookupFunctionArgumentTypes = null ;
2234
2218
this . lookupFunctionArgumentBitRatio = null ;
2235
2219
this . triggerImplyArgumentType = null ;
@@ -2462,12 +2446,6 @@ class FunctionNode {
2462
2446
const argumentType = this . argumentTypes [ argumentIndex ] ;
2463
2447
if ( argumentType ) {
2464
2448
type = argumentType ;
2465
- } else if ( this . lookupArgumentType ) {
2466
- const foundArgumentType = this . lookupArgumentType ( ast . name , this ) ;
2467
- if ( ! this . argumentTypes [ argumentIndex ] ) {
2468
- this . argumentTypes [ argumentIndex ] = foundArgumentType ;
2469
- }
2470
- type = foundArgumentType ;
2471
2449
}
2472
2450
}
2473
2451
if ( ! type && this . strictTypingChecking ) {
@@ -2561,12 +2539,16 @@ class FunctionNode {
2561
2539
}
2562
2540
if ( ! ast . callee || ! ast . callee . name ) {
2563
2541
if ( ast . callee . type === 'SequenceExpression' && ast . callee . expressions [ ast . callee . expressions . length - 1 ] . property . name ) {
2564
- return this . lookupReturnType ( ast . callee . expressions [ ast . callee . expressions . length - 1 ] . property . name , ast , this ) ;
2542
+ const functionName = ast . callee . expressions [ ast . callee . expressions . length - 1 ] . property . name ;
2543
+ this . inferArgumentTypesIfNeeded ( functionName , ast . arguments ) ;
2544
+ return this . lookupReturnType ( functionName , ast , this ) ;
2565
2545
}
2566
2546
throw this . astErrorOutput ( 'Unknown call expression' , ast ) ;
2567
2547
}
2568
2548
if ( ast . callee && ast . callee . name ) {
2569
- return this . lookupReturnType ( ast . callee . name , ast , this ) ;
2549
+ const functionName = ast . callee . name ;
2550
+ this . inferArgumentTypesIfNeeded ( functionName , ast . arguments ) ;
2551
+ return this . lookupReturnType ( functionName , ast , this ) ;
2570
2552
}
2571
2553
throw this . astErrorOutput ( `Unhandled getType Type "${ ast . type } "` , ast ) ;
2572
2554
case 'BinaryExpression' :
@@ -2717,6 +2699,17 @@ class FunctionNode {
2717
2699
}
2718
2700
}
2719
2701
2702
+ inferArgumentTypesIfNeeded ( functionName , args ) {
2703
+ for ( let i = 0 ; i < args . length ; i ++ ) {
2704
+ if ( ! this . needsArgumentType ( functionName , i ) ) continue ;
2705
+ const type = this . getType ( args [ i ] ) ;
2706
+ if ( ! type ) {
2707
+ throw this . astErrorOutput ( `Unable to infer argument ${ i } ` , args [ i ] ) ;
2708
+ }
2709
+ this . assignArgumentType ( functionName , i , type ) ;
2710
+ }
2711
+ }
2712
+
2720
2713
isAstMathVariable ( ast ) {
2721
2714
const mathProperties = [
2722
2715
'E' ,
@@ -7334,7 +7327,7 @@ class WebGLFunctionNode extends FunctionNode {
7334
7327
}
7335
7328
break ;
7336
7329
}
7337
- throw this . astErrorOutput ( `Unhandled argument combination of ${ argumentType } and ${ targetType } ` , ast ) ;
7330
+ throw this . astErrorOutput ( `Unhandled argument combination of ${ argumentType } and ${ targetType } for argument named " ${ argument . name } " ` , ast ) ;
7338
7331
}
7339
7332
}
7340
7333
retArr . push ( ')' ) ;
@@ -12018,11 +12011,15 @@ const utils = {
12018
12011
const start = ast . loc . start ;
12019
12012
const end = ast . loc . end ;
12020
12013
const result = [ ] ;
12021
- result . push ( lines [ start . line - 1 ] . slice ( start . column ) ) ;
12022
- for ( let i = start . line ; i < end . line - 1 ; i ++ ) {
12023
- result . push ( lines [ i ] ) ;
12014
+ if ( start . line === end . line ) {
12015
+ result . push ( lines [ start . line - 1 ] . substring ( start . column , end . column ) ) ;
12016
+ } else {
12017
+ result . push ( lines [ start . line - 1 ] . slice ( start . column ) ) ;
12018
+ for ( let i = start . line ; i < end . line ; i ++ ) {
12019
+ result . push ( lines [ i ] ) ;
12020
+ }
12021
+ result . push ( lines [ end . line - 1 ] . slice ( 0 , end . column ) ) ;
12024
12022
}
12025
- result . push ( lines [ end . line - 1 ] . slice ( 0 , end . column ) ) ;
12026
12023
return result . join ( '\n' ) ;
12027
12024
} ,
12028
12025
0 commit comments