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
Array of JanetAbstractTypes to register for marshalling in the current compilation unit
A context value for storing the current state of compilation, including buffers, flags, and tool paths.
(abstract-type name & fields) Macro version of emit-abstract-type that allows for top-level unquote
(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.
(cdef name & more) Define constant which will be registered in the module. It takes care of the docstring.
(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).
(emit-blocks statements &opt no-indent) Emit a number of statements in a bracketed block
(emit-cdef name & more) Define constant which will be registered in the module. It takes care of the docstring.
(emit-cfunction name & more) Functional form of `cfunction` - takes the same arguments, but parameters must be manually quoted.
(emit-declare binding & form) Emit a declaration of a variable or constant.
(emit-extern binding) Emit a declaration of a variable or constant.
(emit-module-entry name) Call this at the end of a cjanet module to add a module entry function.
(emit-preprocess & args) Emit a line of source code for the pre-processor. For example `(emit-preprocess "include" "<stdio.h>")`.
(emit-typedef name definition) Emit a type declaration (C typedef).
(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.
(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.
(mangle-name token) Same as `mangle` but only emit proper C identifiers (no ., :, or -> allowed). For C identifiers.
(module-entry name) Call this at the end of a cjanet module to add a module entry function.
(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.
(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')