Three forms
Recoil can run host Rebol code at compile time, and can embed the Rebol interpreter at runtime.
| Form | Evaluation | C code emitted | Links Rebol |
|---|---|---|---|
comptime [body] | parse time, evaluated immediately | literal value baked into the C | no |
compfunc [spec] [body] | parse time, registered as a Rebol function | not emitted | no |
rebol [body] | runtime | a call to __recoil_rebol_eval_* | yes |
comptime
Evaluates a Rebol block during parsing; the normalized result is substituted into the source as a literal. It can appear anywhere an expression is expected.
x: make i32! comptime [1 + 2 + 3] ; 6, decided at parse time
print x ; prints 6
hostname: make c-string! comptime [
call/output "hostname" out: ""
trim/lf out
]
The block has full access to the host Rebol environment (file system, environment variables, …).
Result types
Passed through: integer! (→ i32!/i64! by size), decimal! (→ f64!), string!, char!, file!, none!, words and paths (as identifier references), and a block! holding exactly one expression, which is parsed and normalized. Anything else raises P1301; a multi-expression block raises P1300.
x: make i32! comptime [copy [1 2 3]] ; P1301: unsupported result type
x: make i32! comptime [ ; P1300: block must be one expression
a: 1
a + 1
]
An error raised inside the body surfaces as P1305 (COMPTIME ERROR: boom).
compfunc
Defines a Rebol function that exists only at compile time. It is callable from comptime blocks and from Recoil source; no runtime code is emitted for it — only its result survives into the generated C.
double: compfunc [x] [x * 2] ; define at compile time
y: make i32! double 21 ; called at compile time → 42
print y ; the C contains "= 42;", no call
quad: compfunc [x] [double (double x)] ; compfuncs can call compfuncs
z: make i32! quad 10 ; 40
specis a Rebol function spec (words only, no type constraints);bodyis arbitrary Rebol.- The parser checks argument count against the spec: wrong arity is
P1303. An unknown compfunc isP1302. - An error inside the body surfaces as
P1304(COMPTIME ERROR: in 'failer': boom). - Compfuncs are registered per compilation and cleared between compilations.
rebol (runtime)
Embeds a Rebol block that runs at runtime through the host interpreter. Unlike comptime it emits a C call and requires linking the Rebol runtime. It needs an explicit target type — a typed binding, make or as:
x: make i32! rebol [1 + 1]
y: as f64! rebol [3.14]
z: make string! rebol [{hello}]
if true [rebol ["abc"]] ; T4001: requires explicit target type
p: make c-pointer! rebol [1 + 1] ; T4002: cannot target this type
| Target type | C function called |
|---|---|
logic! | __recoil_rebol_eval_logic |
i8! i16! i32! i64! | __recoil_rebol_eval_i64 (cast) |
u8! u16! u32! u64! | __recoil_rebol_eval_u64 (cast) |
f32! f64! | __recoil_rebol_eval_f64 |
char! | __recoil_rebol_eval_char |
string! | __recoil_rebol_eval_string |
c-string! | __recoil_rebol_eval_c_string |
none! | __recoil_rebol_eval_none (default) |
When rebol is used the compiler adds the embed header, finds a Rebol static or shared library and appends the link flag. If none is found, P1705 (static) or P1706 (shared) is raised. Choose with --rebol-static (default) or --rebol-shared.
Security & tooling
comptime and compfunc run arbitrary Rebol inside the compiler process during parsing — the same privilege model as Rust proc macros or a C build.rs.
--fail-on-comptime-in-untrustederrors if comptime/compfunc runs in an untrusted dependency tier.--security-audit FILEemits structured events for everycomptime,compfuncandrebolsite.--lsp-parse-only(with--transpile) skips execution:0is substituted and warningP1310(comptime) orP1311(compfunc) is emitted, so downstream analysis may be incomplete. It exists for editors and linters that should not run untrusted code.
See CLI & Targets and Packages.
Diagnostic codes
| Code | Severity | Description |
|---|---|---|
P1300 | error | comptime result block must contain a single expression |
P1301 | error | unsupported compile-time result type |
P1302 | error | unknown compfunc |
P1303 | error | wrong compfunc arity |
P1304 | error | compfunc body raised an error |
P1305 | error | comptime block body raised an error |
P1310 | warning | comptime skipped under --lsp-parse-only |
P1311 | warning | compfunc skipped under --lsp-parse-only |
T4001 | error | rebol [...] requires an explicit target type |
T4002 | error | rebol [...] cannot target the given type |
P1705 | error | missing Rebol static library |
P1706 | error | missing Rebol shared library |