Liking cljdoc? Tell your friends :D

clj-zig.source

Generate the Zig wrapper source from a boundary spec, and resolve external .zig source files named by a descriptor. A spec and the user's body go in, a string of readable Zig comes out; a {:zig/file ...} descriptor resolves a sibling or classpath .zig file.

For a scalar function the wrapper is an export fn (C ABI, so FFM can bind it) whose parameters are the native params and whose body is the user's Zig spliced in verbatim:

export fn clj_zig_app_2e_core_add(x: i64, y: i64) i64 {
    return x + y;
}

zig fmt owns final formatting; the generator emits already-canonical Zig for the structure it controls, and the compile shell runs zig fmt over the whole file to normalize the body.

Generate the Zig wrapper source from a boundary spec, and resolve
external `.zig` source files named by a descriptor. A spec and the
user's body go in, a string of readable Zig comes out; a `{:zig/file
...}` descriptor resolves a sibling or classpath `.zig` file.

For a scalar function the wrapper is an `export fn` (C ABI, so FFM can
bind it) whose parameters are the native params and whose body is the
user's Zig spliced in verbatim:

    export fn clj_zig_app_2e_core_add(x: i64, y: i64) i64 {
        return x + y;
    }

`zig fmt` owns final formatting; the generator emits already-canonical
Zig for the structure it controls, and the compile shell runs `zig
fmt` over the whole file to normalize the body.
raw docstring

candidate-pathsclj

(candidate-paths defining-file rel)

The ordered filesystem paths to try for rel, given the defining Clojure source file (its *file*, or nil / "NO_SOURCE_PATH" at the REPL). An absolute rel is used as-is; a relative rel resolves first against the defining file's directory, then against the current directory. Pure: builds path strings, reads no filesystem.

The ordered filesystem paths to try for `rel`, given the defining
Clojure source file (its `*file*`, or nil / "NO_SOURCE_PATH" at the
REPL). An absolute `rel` is used as-is; a relative `rel` resolves first
against the defining file's directory, then against the current
directory. Pure: builds path strings, reads no filesystem.
sourceraw docstring

declared-namespaceclj

(declared-namespace zig-text)

The namespace a .zig file asserts it belongs to via a leading //! clj-zig: <ns> doc-comment line, or nil when it makes no such assertion. Pure.

The namespace a `.zig` file asserts it belongs to via a leading
`//! clj-zig: <ns>` doc-comment line, or nil when it makes no such
assertion. Pure.
sourceraw docstring

entry-nameclj

(entry-name spec descriptor)

The user fn name the file-mode wrapper calls: :zig/fn when given, else the Clojure fn name with hyphens as underscores, the way Clojure names munge for the JVM (dot-product becomes dot_product). A name still not a legal Zig identifier, such as red? or saxpy!, needs :zig/fn.

The user fn name the file-mode wrapper calls: `:zig/fn` when given, else
the Clojure fn name with hyphens as underscores, the way Clojure names
munge for the JVM (`dot-product` becomes `dot_product`). A name still not a
legal Zig identifier, such as `red?` or `saxpy!`, needs `:zig/fn`.
sourceraw docstring

file-nodesclj

(file-nodes spec entry)

The declaration nodes for the file-mode wrapper of spec calling the user's entry fn. Returns a vector of declaration nodes.

The declaration nodes for the file-mode wrapper of `spec` calling the
user's `entry` fn. Returns a vector of declaration nodes.
sourceraw docstring

generateclj

(generate spec body)
(generate spec body {:keys [mode entry]})

Render the Zig wrapper source for spec as text. In the default inline mode the user's body string is spliced in. In file mode (opts {:mode :file :entry "name"}) the wrapper reconstructs its arguments and calls the user's pub fn.

Render the Zig wrapper source for `spec` as text. In the default inline
mode the user's `body` string is spliced in. In file mode
(`opts {:mode :file :entry "name"}`) the wrapper reconstructs its
arguments and calls the user's `pub fn`.
sourceraw docstring

inline-nodesclj

(inline-nodes spec body)

The declaration nodes for the inline-mode wrapper of spec with body. The user's body string is spliced into the function body. Returns a vector of declaration nodes.

The declaration nodes for the inline-mode wrapper of `spec` with `body`.
The user's body string is spliced into the function body. Returns a
vector of declaration nodes.
sourceraw docstring

namespace-zig-fileclj

(namespace-zig-file defining-file)

The .zig file co-located with a namespace's Clojure source: the defining file's path with its .clj/.cljc extension replaced by .zig. A bodyless defnz sources its body from this file's matching pub fn. Pure; the filesystem and classpath resolution happens in establish-binding-from!. Throws when there is no defining file, as at the REPL, where a bodyless defnz has no co-located file to read.

The `.zig` file co-located with a namespace's Clojure source: the
defining file's path with its `.clj`/`.cljc` extension replaced by
`.zig`. A bodyless `defnz` sources its body from this file's matching
`pub fn`. Pure; the filesystem and classpath resolution happens in
`establish-binding-from!`. Throws when there is no defining file, as at
the REPL, where a bodyless `defnz` has no co-located file to read.
sourceraw docstring

resolve-and-readclj

(resolve-and-read defining-file rel)

Read the text of the Zig source file rel, trying the filesystem candidates first, then the classpath. Returns {:text <content> :path <resolved>}. Throws a :clj-zig/zig-file-not-found diagnostic listing what was tried.

Read the text of the Zig source file `rel`, trying the filesystem
candidates first, then the classpath. Returns `{:text <content> :path
<resolved>}`. Throws a `:clj-zig/zig-file-not-found` diagnostic listing
what was tried.
sourceraw 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