1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! zsh wiring for inline Rust FFI (`rust { ... }` blocks).
//!
//! fusevm does the heavy lifting: [`fusevm::RustSugar`] rewrites the block at
//! the source level and [`fusevm::ffi`] compiles/loads/marshals it. This module
//! only supplies the zsh-flavored [`fusevm::RustSugar`] config and the desugar
//! entry the parser calls before lexing. The emitted `__rust_compile` command
//! and every exported bareword are resolved elsewhere:
//!
//! - `__rust_compile` is a zshrs builtin (`bin_rust_compile`, src/ported/
//! builtin.rs) that calls [`fusevm::ffi::compile_and_register`].
//! - An exported name runs as a command via the FFI fallback in
//! `ShellExecutor::try_registered_ffi_command` (src/vm_helper.rs), consulted
//! only after builtins/functions/`$PATH`/`command_not_found_handler` all miss
//! — real commands keep priority.
use RustSugar;
/// Emit the zsh command a `rust { ... }` block desugars to: the `__rust_compile`
/// builtin carrying the base64-encoded block body and the block's source line.
/// The body is single-quoted, but the base64 alphabet (`A–Z a–z 0–9 + / =`)
/// contains no zsh-special character, so the quoting is belt-and-suspenders.
/// zsh desugar config: the `rust` keyword, `#` line comments, no block comment,
/// newline as a command boundary. zsh already uses `{ }` for grouping and
/// `;`/newline/`{`/`}` as command separators; the rewrite only fires on the
/// `rust` keyword immediately followed by `{` at a command boundary, so an
/// ordinary `{ ... }` group — or a bare `rust` command word — is never touched.
pub const SUGAR: RustSugar = RustSugar ;
/// Rewrite every `rust { ... }` block at a command boundary into a
/// `__rust_compile '<base64>' <line>` command, before lexing. No-op (single
/// substring scan) when the source has no `rust` token.
/// The `__rust_compile '<base64>' [line]` builtin handler — the target of the
/// desugar above (registered in the `BUILTINS` table, src/ported/builtin.rs).
/// It compiles the base64-encoded `rust { ... }` block body into a cached cdylib
/// and registers its exported `extern "C"` functions so each becomes callable
/// as a zshrs command (resolved in `ShellExecutor::try_registered_ffi_command`,
/// src/vm_helper.rs). `argv[0]` is the base64 body; `argv[1]` (the block's
/// source line) is carried for diagnostics but not yet consumed. Returns 0 on
/// success, or 1 with a `zshrs: <err>` diagnostic on failure.
///
/// Lives here rather than under `src/ported/` because it is a zshrs-native
/// builtin with no zsh C counterpart — the port-fidelity guard (build.rs)
/// requires every fn under `src/ported/` to map to an upstream C function.