x-lang

← Index

x/tool/compile

Native code compiler: JIT assembler (default) with C compiler fallback.

Default compile uses JIT assembler. compile-c falls back to C compiler. compile-asm is the pure JIT path.

A module of its own: every name here is reached with (import x/tool/compile NAME); compile-with-writers, compile-emitters and compile-add-emitter! are re-exported from x/tool/compile/pipeline and x/tool/compile/emit.

compile-hosted?

Whether this engine ships the C headers the cc lane compiles against; the tower’s JIT probe reads it to choose between compiling and keeping the interpreted twin.

Returns: BOOL — #t when engine/include and engine/ext/x-expr/include exist

Pipeline stages

compile-to-c

Generate C source code from an (fn …) expression.

Parameters:

Returns: STRING — Generated C source code

Examples:

(import x/tool/compile compile-to-c) (Str8 starts? "#include" (compile-to-c '(fn (_ x) (+ x 1)))) => #t

compile-write

Write a string to a file. Returns the path.

Parameters:

Returns: STRING — The path written to

compile-cc

Invoke the C compiler on a source file to produce a shared library.

Parameters:

compile-load

Load a compiled shared library and return fn_0 as a callable primitive.

Parameters:

Returns: PRIMITIVE — Native function

compile-cc-flags

Compiler flags for the current platform.

Returns: LIST — Platform-specific cc flags

compile-ext

Shared library file extension for the current platform.

Returns: STRING — .bundle or .so

Compilation

compile-c

Compile an (fn …) expression to a native primitive via C compiler. Caches by expression hash.

Parameters:

Returns: PRIMITIVE — Compiled native function

compile-asm

compile

Compile an (fn …) expression to native code. Pure expressions use JIT assembler; fvar expressions use C compiler with persistent caching.

Parameters:

Returns: PRIMITIVE — Compiled native function