Janet 1.41.1-8b6d56e Documentation
(Other Versions: 1.40.1 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

cjanet

A DSL that compiles to C. Improved version of jpm/cgen that is more amenable to Janet integration, macros, and meta-programming.

The semantics of the language are basically the same as C so a higher level language (or type system) should be built on top of this. This IR emits a very useful subset of valid C 99.

Reference

cjanet/*abstract-type-list* cjanet/*cdef-list* cjanet/*cfun-list* cjanet/*default-ctype* cjanet/*indent* cjanet/*jit-context* cjanet/@ cjanet/abstract-type cjanet/begin-jit cjanet/block cjanet/cdef cjanet/cfunction cjanet/declare cjanet/emit-abstract-type cjanet/emit-block-end cjanet/emit-block-start cjanet/emit-blocks cjanet/emit-cdef cjanet/emit-cfunction cjanet/emit-comment cjanet/emit-declare cjanet/emit-extern cjanet/emit-function cjanet/emit-include cjanet/emit-indent cjanet/emit-module-entry cjanet/emit-preprocess cjanet/emit-typedef cjanet/end-jit cjanet/extern cjanet/function cjanet/include cjanet/mangle cjanet/mangle-name cjanet/mangle-type cjanet/module-entry cjanet/preprocess cjanet/register-binding-type cjanet/type-split cjanet/typedef


cjanet/*abstract-type-list* keyword source
Array of JanetAbstractTypes to register for marshalling in the current compilation unit

cjanet/*cdef-list* keyword source
Array of C Constants defined in the current compilation unit

cjanet/*cfun-list* keyword source
Array of C Functions defined in the current compilation unit

cjanet/*default-ctype* keyword source
The default type used when declaring variables

cjanet/*indent* keyword source
current indent buffer

cjanet/*jit-context* keyword source
A context value for storing the current state of compilation, including buffers, flags, and tool paths.

cjanet/@ macro source
(@ & args)


cjanet/abstract-type macro source
(abstract-type name & fields)

Macro version of emit-abstract-type that allows for top-level unquote

cjanet/begin-jit function source
(begin-jit &keys options)

Begin C Janet JIT context. Optionally pass in options to configure compilation. The `options` argument
will be passed to the `spork/cc` module to compile generated C code. Generated intermediates will be created
in the _build/ directory.

cjanet/block macro source
(block & args)


cjanet/cdef macro source
(cdef name & more)

Define constant which will be registered in the module.
It takes care of the docstring.

cjanet/cfunction macro source
(cfunction name & more)

Define a C Function in cjanet. This also takes care
of recording docstrings and such. Arity checking will be
generated for you (by insertion of a call to janet_arity
or janet_fixarity).

cjanet/declare macro source
(declare & args)


cjanet/emit-abstract-type function source
(emit-abstract-type name & fields)


cjanet/emit-block-end function source
(emit-block-end &opt nl)


cjanet/emit-block-start function source
(emit-block-start)


cjanet/emit-blocks function source
(emit-blocks statements &opt no-indent)

Emit a number of statements in a bracketed block

cjanet/emit-cdef function source
(emit-cdef name & more)

Define constant which will be registered in the module.
It takes care of the docstring.

cjanet/emit-cfunction function source
(emit-cfunction name & more)

Functional form of `cfunction` - takes the same arguments, but parameters must be manually quoted.

cjanet/emit-comment function source
(emit-comment msg)

Emit a multi-line comment string for C

cjanet/emit-declare function source
(emit-declare binding & form)

Emit a declaration of a variable or constant.

cjanet/emit-extern function source
(emit-extern binding)

Emit a declaration of a variable or constant.

cjanet/emit-function function source
(emit-function name & form)

Emit a C function definition.

cjanet/emit-include function source
(emit-include path)


cjanet/emit-indent function source
(emit-indent)


cjanet/emit-module-entry function source
(emit-module-entry name)

Call this at the end of a cjanet module to add a module entry function.

cjanet/emit-preprocess function source
(emit-preprocess & args)

Emit a line of source code for the pre-processor.
For example `(emit-preprocess "include" "<stdio.h>")`.

cjanet/emit-typedef function source
(emit-typedef name definition)

Emit a type declaration (C typedef).

cjanet/end-jit function source
(end-jit &named no-load cache)

End current compilation context, compile all buffered code, and then by default load it into the current process.
The `no-load` argument controls whether or not the compiled code is loaded. If `no-load` is truthy, then
this function will return the path to the compiled shared object and skip loading.
If `cache` is truthy, this function will use a previously compiled shared object or DLL if it exists and the source code matches.

cjanet/extern macro source
(extern & args)


cjanet/function macro source
(function & args)


cjanet/include macro source
(include path)


cjanet/mangle function source
(mangle token)

Convert any sequence of bytes to a valid C identifier in a way that is unlikely to collide. The period character
is left unchanged even though it is not a valid identifier to allow for easy access into structs. Will also remove
any grafted type info. E.g. abc:int -> abc
For generating lvalues and rvalues.

cjanet/mangle-name function source
(mangle-name token)

Same as `mangle` but only emit proper C identifiers (no ., :, or -> allowed).
For C identifiers.

cjanet/mangle-type function source
(mangle-type token)

Same as `mangle` but for valid C

cjanet/module-entry macro source
(module-entry name)

Call this at the end of a cjanet module to add a module entry function.

cjanet/preprocess macro source
(preprocess & args)


cjanet/register-binding-type function source
(register-binding-type alias ctype &opt wrapfn getfn optfn abstract)

Add a C type that can be used a parameter or return type to CFunctions.
`alias` is a short name that can be used as a type alias only in CFunctions, and can be
nil if no alias is desired. Any of `wrapfn`, `getfn`, and `optfn` can be nil.

* `ctype` is a CJanet type expression, such as `(* double)` or `(const MyCustonType)`.
* `wrapfn` is a function or C macro name that is used to convert values of `ctype` to a `Janet` value,
 such as `janet_wrap_pointer` or `wrap_my_custom_type`. This will be used for returning values from functions.
* `getfn` is the name of a function of two argumnets to extract this value from a parameter list, such as `janet_getnumber`.
 This function should have the signature `Janet getfn(const Janet *argv, int32_t n);`
* `optfn` is the name of a function similar to `getfn` but will be used in the case where the parameter is optional.
 This function should have the signature `Janet optfn(const Janet *argv, int32_t argc, int32_t n, <anytype> dflt);`
 Notably, the "default" value `dflt` does not need to be any particular type.

cjanet/type-split function source
(type-split x &opt dflt-type)

Extract name and type from a variable. Allow typing variables as both (name type) or name:type as a shorthand. If no type is found, default to dflt-type. dflt-type itself defaults to (dyn *default-ctype* 'CJANET_DEFAULT_TYPE')

cjanet/typedef macro source
(typedef & args)