Liking cljdoc? Tell your friends :D

threeagent.tsl.compiler

Rewrites Clojure forms into code that builds a TSL node graph.

Pure form -> form functions with no dependency on the ClojureScript analyzer, so the same compiler backs both the shadow-cljs macros in threeagent.tsl and the SCI macros in threeagent.tsl.sci.

The emitted code only calls plain functions in threeagent.tsl (no ^js interop), which keeps it valid under advanced compilation and in SCI.

Symbol resolution inside shader code:

  • lexical locals (from &env and bindings inside the form) always win
  • operators and special forms (+, <, if, set!, dotimes, ...) are rewritten to TSL-aware runtime calls
  • names exported by three/tsl, in their JS spelling (positionLocal) or kebab-case (position-local), become TSL references
  • everything else passes through untouched, as does (clj ...)
Rewrites Clojure forms into code that builds a TSL node graph.

Pure form -> form functions with no dependency on the ClojureScript
analyzer, so the same compiler backs both the shadow-cljs macros in
`threeagent.tsl` and the SCI macros in `threeagent.tsl.sci`.

The emitted code only calls plain functions in `threeagent.tsl` (no `^js`
interop), which keeps it valid under advanced compilation and in SCI.

Symbol resolution inside shader code:
- lexical locals (from `&env` and bindings inside the form) always win
- operators and special forms (`+`, `<`, `if`, `set!`, `dotimes`, ...) are
  rewritten to TSL-aware runtime calls
- names exported by three/tsl, in their JS spelling (`positionLocal`) or
  kebab-case (`position-local`), become TSL references
- everything else passes through untouched, as does `(clj ...)`
raw docstring

compile-computeclj/s

(compile-compute [opts & body] locals form)

(compute {:count n :workgroup-size [64]} & body)

(compute {:count n :workgroup-size [64]} & body)
raw docstring

compile-formclj/s

(compile-form form locals)

Compile one form of shader code. locals is a set of symbols bound in the surrounding scope; they shadow TSL names.

Compile one form of shader code. `locals` is a set of symbols bound in the
surrounding scope; they shadow TSL names.
raw docstring

compile-shaderclj/s

(compile-shader body locals)

Compile the body of a shader form. Bodies that use statements are wrapped in a TSL Fn so If/Loop/assign have a stack to land on.

Compile the body of a `shader` form. Bodies that use statements are wrapped
in a TSL Fn so If/Loop/assign have a stack to land on.
raw docstring

compile-shader-fnclj/s

(compile-shader-fn fname [params & more] locals form)

(shader-fn name? [params] return-type? & body) -> code creating a TSL Fn wrapped in a Clojure function.

(shader-fn name? [params] return-type? & body) -> code creating a TSL Fn
wrapped in a Clojure function.
raw docstring

contains-statement?clj/s

(contains-statement? form)

True when form uses a construct that needs a TSL Fn stack.

True when `form` uses a construct that needs a TSL Fn stack.
raw docstring

env-localsclj/s

(env-locals env)

Local symbols from a macro &env: ClojureScript analyzer envs keep them under :locals; SCI and Clojure pass a map keyed by the locals.

Local symbols from a macro `&env`: ClojureScript analyzer envs keep them
under :locals; SCI and Clojure pass a map keyed by the locals.
raw docstring

expand-computeclj/s

(expand-compute args env form)

expand-defcomputeclj/s

(expand-defcompute [cname & args] env form)

expand-defshaderclj/s

(expand-defshader [fname & fdecl])

expand-defshader-fnclj/s

(expand-defshader-fn [fname & args] env form)

expand-shaderclj/s

(expand-shader body env)

expand-shader-fnclj/s

(expand-shader-fn args env form)

expand-threadingclj/s

(expand-threading [op x & steps :as form])

kebabclj/s

(kebab js-name)

positionLocal -> position-local, TWO_PI -> two-pi, mx_noise_float -> mx-noise-float

positionLocal -> position-local, TWO_PI -> two-pi, mx_noise_float -> mx-noise-float
raw docstring

parse-paramsclj/s

(parse-params params form)

[a :float b :vec3] -> {:syms [a b] :types ["float" "vec3"]} [a b] -> {:syms [a b] :types nil}

[a :float b :vec3] -> {:syms [a b] :types ["float" "vec3"]}
[a b]             -> {:syms [a b] :types nil}
raw docstring

pattern-symsclj/s

(pattern-syms pattern)

Every symbol bound by a destructuring pattern.

Every symbol bound by a destructuring pattern.
raw docstring

tsl-namesclj/s

symbol -> three/tsl export name

symbol -> three/tsl export name
raw docstring

wgsl-nameclj/s

(wgsl-name sym)

A WGSL-safe identifier for a Clojure symbol.

A WGSL-safe identifier for a Clojure symbol.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close