Skip to content

Commit d489f1d

Browse files
fix: Provide native function reordering like standard functions
fix: Provide inline functions source when error
1 parent ccf9290 commit d489f1d

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

dist/gpu-browser-core.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.10.0
8-
* @date Tue Aug 25 2020 14:05:30 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.10.5
8+
* @date Thu Nov 12 2020 14:04:03 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -2091,12 +2091,12 @@ class FunctionBuilder {
20912091
functionBuilder.trackFunctionCall(functionName, calleeFunctionName, args);
20922092
};
20932093

2094-
const onNestedFunction = (ast, returnType) => {
2094+
const onNestedFunction = (ast, source) => {
20952095
const argumentNames = [];
20962096
for (let i = 0; i < ast.params.length; i++) {
20972097
argumentNames.push(ast.params[i].name);
20982098
}
2099-
const nestedFunction = new FunctionNode(null, Object.assign({}, nodeOptions, {
2099+
const nestedFunction = new FunctionNode(source, Object.assign({}, nodeOptions, {
21002100
returnType: null,
21012101
ast,
21022102
name: ast.id.name,
@@ -2259,8 +2259,12 @@ class FunctionBuilder {
22592259
retList = retList || [];
22602260

22612261
if (this.nativeFunctionNames.indexOf(functionName) > -1) {
2262-
if (retList.indexOf(functionName) === -1) {
2262+
const nativeFunctionIndex = retList.indexOf(functionName);
2263+
if (nativeFunctionIndex === -1) {
22632264
retList.push(functionName);
2265+
} else {
2266+
const dependantNativeFunctionName = retList.splice(nativeFunctionIndex, 1)[0];
2267+
retList.push(dependantNativeFunctionName);
22642268
}
22652269
return retList;
22662270
}
@@ -2551,6 +2555,7 @@ class FunctionBuilder {
25512555
module.exports = {
25522556
FunctionBuilder
25532557
};
2558+
25542559
},{}],9:[function(require,module,exports){
25552560
const acorn = require('acorn');
25562561
const { utils } = require('../utils');
@@ -2772,7 +2777,7 @@ class FunctionNode {
27722777
}
27732778

27742779
for (let i = 0; i < functions.length; i++) {
2775-
this.onNestedFunction(functions[i]);
2780+
this.onNestedFunction(functions[i], this.source);
27762781
}
27772782
}
27782783

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.10.0
8-
* @date Tue Aug 25 2020 14:05:30 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.10.5
8+
* @date Thu Nov 12 2020 14:04:02 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -6700,12 +6700,12 @@ class FunctionBuilder {
67006700
functionBuilder.trackFunctionCall(functionName, calleeFunctionName, args);
67016701
};
67026702

6703-
const onNestedFunction = (ast, returnType) => {
6703+
const onNestedFunction = (ast, source) => {
67046704
const argumentNames = [];
67056705
for (let i = 0; i < ast.params.length; i++) {
67066706
argumentNames.push(ast.params[i].name);
67076707
}
6708-
const nestedFunction = new FunctionNode(null, Object.assign({}, nodeOptions, {
6708+
const nestedFunction = new FunctionNode(source, Object.assign({}, nodeOptions, {
67096709
returnType: null,
67106710
ast,
67116711
name: ast.id.name,
@@ -6868,8 +6868,12 @@ class FunctionBuilder {
68686868
retList = retList || [];
68696869

68706870
if (this.nativeFunctionNames.indexOf(functionName) > -1) {
6871-
if (retList.indexOf(functionName) === -1) {
6871+
const nativeFunctionIndex = retList.indexOf(functionName);
6872+
if (nativeFunctionIndex === -1) {
68726873
retList.push(functionName);
6874+
} else {
6875+
const dependantNativeFunctionName = retList.splice(nativeFunctionIndex, 1)[0];
6876+
retList.push(dependantNativeFunctionName);
68736877
}
68746878
return retList;
68756879
}
@@ -7160,6 +7164,7 @@ class FunctionBuilder {
71607164
module.exports = {
71617165
FunctionBuilder
71627166
};
7167+
71637168
},{}],10:[function(require,module,exports){
71647169
const acorn = require('acorn');
71657170
const { utils } = require('../utils');
@@ -7381,7 +7386,7 @@ class FunctionNode {
73817386
}
73827387

73837388
for (let i = 0; i < functions.length; i++) {
7384-
this.onNestedFunction(functions[i]);
7389+
this.onNestedFunction(functions[i], this.source);
73857390
}
73867391
}
73877392

dist/gpu-browser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.10.4",
3+
"version": "2.10.5",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=8.0.0"

src/backend/function-builder.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ class FunctionBuilder {
8787
functionBuilder.trackFunctionCall(functionName, calleeFunctionName, args);
8888
};
8989

90-
const onNestedFunction = (ast, returnType) => {
90+
const onNestedFunction = (ast, source) => {
9191
const argumentNames = [];
9292
for (let i = 0; i < ast.params.length; i++) {
9393
argumentNames.push(ast.params[i].name);
9494
}
95-
const nestedFunction = new FunctionNode(null, Object.assign({}, nodeOptions, {
95+
const nestedFunction = new FunctionNode(source, Object.assign({}, nodeOptions, {
9696
returnType: null,
9797
ast,
9898
name: ast.id.name,
@@ -276,8 +276,17 @@ class FunctionBuilder {
276276
retList = retList || [];
277277

278278
if (this.nativeFunctionNames.indexOf(functionName) > -1) {
279-
if (retList.indexOf(functionName) === -1) {
279+
const nativeFunctionIndex = retList.indexOf(functionName);
280+
if (nativeFunctionIndex === -1) {
280281
retList.push(functionName);
282+
} else {
283+
/**
284+
* https://github.com/gpujs/gpu.js/issues/207
285+
* if dependent function is already in the list, because a function depends on it, and because it has
286+
* already been traced, we know that we must move the dependent function to the end of the the retList.
287+
* */
288+
const dependantNativeFunctionName = retList.splice(nativeFunctionIndex, 1)[0];
289+
retList.push(dependantNativeFunctionName);
281290
}
282291
return retList;
283292
}

src/backend/function-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class FunctionNode {
255255
}
256256

257257
for (let i = 0; i < functions.length; i++) {
258-
this.onNestedFunction(functions[i]);
258+
this.onNestedFunction(functions[i], this.source);
259259
}
260260
}
261261

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export interface IFunctionSettings {
508508
returnType?: string;
509509
isRootKernel?: boolean;
510510
isSubKernel?: boolean;
511-
onNestedFunction?(source: string, returnType: string): void;
511+
onNestedFunction?(ast: any, source: string): void;
512512
lookupReturnType?(functionName: string, ast: any, node: FunctionNode): void;
513513
plugins?: any[];
514514

0 commit comments

Comments
 (0)