Skip to content

Commit

Permalink
fix: Provide native function reordering like standard functions
Browse files Browse the repository at this point in the history
fix: Provide inline functions source when error
  • Loading branch information
robertleeplummerjr authored and ammyk9 committed Aug 6, 2024
1 parent 1598260 commit e8a6f6d
Show file tree
Hide file tree
Showing 8 changed files with 961 additions and 238 deletions.
702 changes: 580 additions & 122 deletions dist/gpu-browser-core.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/gpu-browser-core.min.js

Large diffs are not rendered by default.

464 changes: 360 additions & 104 deletions dist/gpu-browser.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/gpu-browser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gpu.js",
"version": "2.10.4",
"version": "2.10.5",
"description": "GPU Accelerated JavaScript",
"engines": {
"node": ">=8.0.0"
Expand Down
15 changes: 12 additions & 3 deletions src/backend/function-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class FunctionBuilder {
functionBuilder.trackFunctionCall(functionName, calleeFunctionName, args);
};

const onNestedFunction = (ast, returnType) => {
const onNestedFunction = (ast, source) => {
const argumentNames = [];
for (let i = 0; i < ast.params.length; i++) {
argumentNames.push(ast.params[i].name);
}
const nestedFunction = new FunctionNode(null, Object.assign({}, nodeOptions, {
const nestedFunction = new FunctionNode(source, Object.assign({}, nodeOptions, {
returnType: null,
ast,
name: ast.id.name,
Expand Down Expand Up @@ -276,8 +276,17 @@ class FunctionBuilder {
retList = retList || [];

if (this.nativeFunctionNames.indexOf(functionName) > -1) {
if (retList.indexOf(functionName) === -1) {
const nativeFunctionIndex = retList.indexOf(functionName);
if (nativeFunctionIndex === -1) {
retList.push(functionName);
} else {
/**
* https://github.com/gpujs/gpu.js/issues/207
* if dependent function is already in the list, because a function depends on it, and because it has
* already been traced, we know that we must move the dependent function to the end of the the retList.
* */
const dependantNativeFunctionName = retList.splice(nativeFunctionIndex, 1)[0];
retList.push(dependantNativeFunctionName);
}
return retList;
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class FunctionNode {
}

for (let i = 0; i < functions.length; i++) {
this.onNestedFunction(functions[i]);
this.onNestedFunction(functions[i], this.source);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export interface IFunctionSettings {
returnType?: string;
isRootKernel?: boolean;
isSubKernel?: boolean;
onNestedFunction?(source: string, returnType: string): void;
onNestedFunction?(ast: any, source: string): void;
lookupReturnType?(functionName: string, ast: any, node: FunctionNode): void;
plugins?: any[];

Expand Down

0 comments on commit e8a6f6d

Please sign in to comment.