Liking cljdoc? Tell your friends :D

clj-zig.spec

Build the canonical boundary spec for a defnz function, and project it into clojure.spec.alpha predicates. The build is pure: an identity-plus-signature map goes in, a validated spec comes out, or a diagnostic is thrown. spec-for-type and spec-for-param derive the predicate forms; register! writes them to the registry.

The spec is the native boundary contract that source generation, FFM binding, and cache hashing all consume:

{:ns app.core
 :name add
 :symbol "clj_zig_app_2e_core_add"
 :params [{:binding x :type {:kind :scalar :name :i64}}
          {:binding y :type {:kind :scalar :name :i64}}]
 :ret {:kind :scalar :name :i64}
 :signature [x :i64 y :i64 :ret :i64]}

:params is the flat list of native parameters in call order. Clojure-side destructuring is expanded here: each destructured local becomes one native param tagged with :destructured-from, so the core macro can lower a map argument to scalars before the call.

Build the canonical boundary spec for a `defnz` function, and project
it into `clojure.spec.alpha` predicates. The build is pure: an
identity-plus-signature map goes in, a validated spec comes out, or a
diagnostic is thrown. `spec-for-type` and `spec-for-param` derive the
predicate forms; `register!` writes them to the registry.

The spec is the native boundary contract that source generation, FFM
binding, and cache hashing all consume:

    {:ns app.core
     :name add
     :symbol "clj_zig_app_2e_core_add"
     :params [{:binding x :type {:kind :scalar :name :i64}}
              {:binding y :type {:kind :scalar :name :i64}}]
     :ret {:kind :scalar :name :i64}
     :signature [x :i64 y :i64 :ret :i64]}

`:params` is the flat list of native parameters in call order.
Clojure-side destructuring is expanded here: each destructured
local becomes one native param tagged with `:destructured-from`, so the
core macro can lower a map argument to scalars before the call.
raw docstring

build-specclj

(build-spec {:keys [ns name signature types] :or {types {}}})

Build the boundary spec from {:ns :name :signature}, resolving any named-type references against an optional :types map. Throws a diagnostic (ex-info) when the contract is invalid.

Build the boundary spec from `{:ns :name :signature}`, resolving any
named-type references against an optional `:types` map. Throws a
diagnostic (`ex-info`) when the contract is invalid.
sourceraw docstring

register!clj

(register! the-var)

Register clojure.spec.alpha predicates for the defnz Var's arguments and return. Reads the boundary spec from the Var's :clj-zig/info metadata. Idempotent: re-registering replaces the specs.

Register `clojure.spec.alpha` predicates for the `defnz` Var's
arguments and return. Reads the boundary spec from the Var's
`:clj-zig/info` metadata. Idempotent: re-registering replaces the
specs.
sourceraw docstring

spec-for-paramclj

(spec-for-param param)

The argument-side spec for a boundary param. A slice argument is driven by the caller, who passes a Java primitive array; so the spec is permissive (array? or coll?). A scalar is exact.

The argument-side spec for a boundary param. A slice argument is
driven by the caller, who passes a Java primitive array; so the spec
is permissive (`array?` or `coll?`). A scalar is exact.
sourceraw docstring

spec-for-typeclj

(spec-for-type t)

A clojure.spec predicate form for a normalized boundary type. Scalars map to their JVM predicate; enums map to the member keyword set; named structs map to map?; slices and collections map to coll-of; strings to string?; bytes to bytes?; optional wraps in nilable; handle to some?; void to nil?.

A clojure.spec predicate form for a normalized boundary type.
Scalars map to their JVM predicate; enums map to the member keyword
set; named structs map to `map?`; slices and collections map to
`coll-of`; strings to `string?`; bytes to `bytes?`; optional wraps in
`nilable`; handle to `some?`; void to `nil?`.
sourceraw docstring

symbol-nameclj

(symbol-name var-ns var-name)

The stable, collision-free C symbol for a Var: clj_zig_<ns>_<name>.

The stable, collision-free C symbol for a Var: `clj_zig_<ns>_<name>`.
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