@thi.ng/shader-ast
Version:
DSL to define shader code in TypeScript and cross-compile to GLSL, JS and other targets
76 lines • 3.09 kB
TypeScript
import type { Fn, Fn2, Maybe } from "@thi.ng/api";
import { DGraph } from "@thi.ng/dgraph";
import type { Decl, Func, Scope, Sym, Term } from "../api/nodes.js";
import type { Type } from "../api/types.js";
/**
* Helper function for {@link walk}. Returns child nodes (incl. tests in
* conditionals) for any control flow nodes containing a child scope.
*
* {@link allChildren}
*/
export declare const scopedChildren: (t: Term<any>) => Term<any>[] | undefined;
/**
* Helper function for {@link walk}. Returns an array of all child nodes for
* a given term (if any).
*
* {@link scopedChildren}
*/
export declare const allChildren: (t: Term<any>) => any;
/**
* Traverses given AST in depth-first order and applies `visit` and
* `children` fns to each node. Descends only further if `children`
* returns an array of child nodes. The `visit` function must accept 2
* args: the accumulator (`acc`) given to {@link walk} and a tree node. The
* return value of `visit` becomes the new `acc` value, much like in a
* reduce operation. {@link walk} itself returns the final `acc`.
*
* If `pre` is true (default), the `visit` function will be called prior
* to visiting a node's children. If false, the visitor is called on the
* way back up.
*
* @param visit -
* @param children -
* @param acc -
* @param tree -
* @param pre -
*/
export declare const walk: <T>(visit: Fn2<T, Term<any>, T>, children: Fn<Term<any>, Maybe<Term<any>[]>>, acc: T, tree: Term<any> | Term<any>[], pre?: boolean) => T;
/**
* Builds dependency graph of given function, by recursively adding all
* function dependencies. Returns graph.
*
* @param fn -
* @param graph -
*/
export declare const buildCallGraph: (fn: Func<any>, graph?: DGraph<Func<any>>) => DGraph<Func<any>>;
export declare const decl: <T extends Type>(id: Sym<T>) => Decl<T>;
/**
* Wraps the given AST node array in `scope` node, optionally as global
* scope (default false). The interpretation of the global flag is
* dependent on the target code gen. I.e. for GLSL / JS, the flag
* disables wrapping the scope's body in `{}`, but else has no
* difference. In general this node type only serves as internal
* mechanism for various control flow AST nodes and should not need to
* be used directly from user land code (though might be useful to
* create custom / higher level control flow nodes).
*
* @param body -
* @param global -
*/
export declare const scope: (body: (Term<any> | null)[], global?: boolean) => Scope;
/**
* Takes an array of global sym/var definitions ({@link input}, {@link output},
* {@link uniform}) and functions defined via {@link defn}. Constructs the call
* graph of all transitively used functions and bundles everything in
* topological order within a global scope object, which is then returned to the
* user and can be passed to a target codegen for full program output.
*
* - {@link scope}
* - {@link input}
* - {@link output}
* - {@link uniform}
*
* @param body -
*/
export declare const program: (body: (Sym<any> | Func<any>)[]) => Scope;
//# sourceMappingURL=scope.d.ts.map