Skip to content

Commit

Permalink
feat(shader-ast): add buildCallGraph(), add deps
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 18, 2019
1 parent da8d16d commit 4017284
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/shader-ast/package.json
Expand Up @@ -35,6 +35,7 @@
"@thi.ng/api": "^6.2.0",
"@thi.ng/checks": "^2.1.6",
"@thi.ng/defmulti": "^1.0.9",
"@thi.ng/dgraph": "^1.1.9",
"@thi.ng/matrices": "^0.4.0",
"@thi.ng/vectors": "^2.5.6"
},
Expand Down
18 changes: 18 additions & 0 deletions packages/shader-ast/src/ast.ts
Expand Up @@ -6,6 +6,7 @@ import {
Select4
} from "@thi.ng/api";
import { isArray, isNumber, isString } from "@thi.ng/checks";
import { DGraph } from "@thi.ng/dgraph";
import { illegalArgs } from "@thi.ng/errors";
import {
Arg,
Expand Down Expand Up @@ -179,6 +180,23 @@ export const walk = <T>(
return acc;
};

/**
* Builds dependency graph of given function.
*
* @param fn
* @param graph
*/
export const buildCallGraph = (
fn: Func<any>,
graph: DGraph<Func<any>> = new DGraph()
): DGraph<Func<any>> =>
fn.deps
? fn.deps.reduce(
(graph, d) => buildCallGraph(d, graph.addDependency(fn, d)),
graph
)
: graph;

export function sym<T extends Type>(init: Term<T>): Sym<T>;
export function sym<T extends Type>(type: T): Sym<T>;
export function sym<T extends Type>(type: T, opts: SymOpts): Sym<T>;
Expand Down

0 comments on commit 4017284

Please sign in to comment.