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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//! Keleusma is a Total Functional Stream Processor that compiles
//! to bytecode and runs on a stack-based virtual machine. The crate
//! targets `no_std + alloc` environments and is designed for embedded
//! scripting where definitive worst-case execution time and worst-case
//! memory usage bounds matter.
//!
//! The crate has no built-in standard library. All domain functionality
//! is provided by host-registered native functions through
//! [`vm::Vm::register_fn`], [`vm::Vm::register_native`], and the
//! related entry points. The bundled libraries in [`stddsl`] are
//! examples of the registration pattern, not a closed set.
//!
//! # Quick start
//!
//! ```ignore
//! // Requires the `compile` cargo feature (default on).
//! use keleusma::compiler::compile;
//! use keleusma::lexer::tokenize;
//! use keleusma::parser::parse;
//! use keleusma::vm::{DEFAULT_ARENA_CAPACITY, Vm, VmState};
//! use keleusma::{Arena, Value};
//!
//! let source = r#"
//! fn double(x: Word) -> Word { x * 2 }
//! fn main(n: Word) -> Word { n |> double() }
//! "#;
//!
//! let tokens = tokenize(source).expect("lex");
//! let program = parse(&tokens).expect("parse");
//! let module = compile(&program).expect("compile");
//! let arena = Arena::with_capacity(DEFAULT_ARENA_CAPACITY);
//! let mut vm = Vm::new(module, &arena).expect("verify");
//!
//! match vm.call(&[Value::Int(21)]).unwrap() {
//! VmState::Finished(value) => println!("{:?}", value),
//! _ => unreachable!(),
//! }
//! // prints: Int(42)
//! ```
//!
//! # Cargo features
//!
//! The crate exposes orthogonal feature gates so hosts can strip
//! pipeline stages they do not need.
//!
//! - `compile` (default on): lexer, parser, type checker,
//! monomorphizer, compiler. Drop when the host ships precompiled
//! bytecode.
//! - `verify` (default on): structural verifier and WCET/WCMU
//! resource-bounds pass. With this off, [`vm::Vm::new`] behaves
//! like [`vm::Vm::new_unchecked`].
//! - `floats` (default on): the `Float` surface type, `Value::Float`,
//! `Op::IntToFloat`/`FloatToInt`, and the [`audio_natives`] and
//! [`stddsl::Math`]/[`stddsl::Audio`] bundles. Drop to eliminate the
//! soft-float `compiler_builtins` routines from the runtime image.
//! - `signatures` (default off): Ed25519 module signing and
//! load-time verification.
//! - `shell` (default off): the [`stddsl::Shell`] bundle. Requires
//! `std`.
//! - `sdl3-example` (default off): builds the bundled SDL3 audio
//! piano-roll example. `cmake`-builds SDL3 from source.
//!
//! Seven mutually-exclusive `narrow-word-*`, `narrow-address-*`, and
//! `narrow-float-32` parametric-runtime selectors gate the
//! framing-level upper bound on bytecode widths for hosts that ship
//! only a sub-64-bit `GenericVm` instance.
//!
//! # Further reading
//!
//! The repository's `README.md` and `docs/` knowledge graph describe
//! the language design, execution model, instruction set, wire
//! format, and conservative-verification stance in depth.
extern crate alloc;
/// Address-type abstraction used by the parametric [`vm::GenericVm`]
/// to model the runtime's address width.
/// Runtime values, instructions, the [`Module`] type, and the cost
/// model.
/// Arena-resident dynamic strings ([`KString`]) at the host-VM
/// boundary.
/// Type-driven marshalling between host Rust types and runtime
/// [`Value`]s for native function registration.
/// Opaque host-value support: the [`opaque::HostOpaque`] trait and
/// the [`opaque::host_arc`] constructor that produces
/// `Value::Opaque(Arc<dyn HostOpaque>)`.
/// Bundled utility natives. V0.2.0 ships only `println` here; other
/// utilities are host-registered.
/// The stack-based virtual machine and its coroutine driver.
/// Wire-format encoding and decoding of compiled [`Module`]s.
/// Word-type abstraction used by the parametric [`vm::GenericVm`]
/// to model the runtime's word width.
// Audio natives use floating-point arithmetic throughout (note
// frequency, phase, filter coefficients) and are only useful on
// hosts that enable the `floats` feature. Without floats the
// bundle's native signatures cannot satisfy the `IntoNativeFn`
// trait bounds because `KeleusmaType for f64` is not in scope.
/// Bundled audio-DSP natives (`audio::midi_to_freq`,
/// `audio::db_to_linear`, and similar). Requires the `floats` feature.
/// Parametric floating-point trait used by [`vm::GenericVm`]. The
/// trait and its `f32` and `f64` impls are always compiled so the
/// generic shape carries a `Float` type parameter regardless of the
/// `floats` feature; the floating-point variants of [`Value`] and the
/// floating-point opcodes remain gated by `floats`.
/// Bundled standard-library DSLs ([`stddsl::Math`], [`stddsl::Audio`],
/// [`stddsl::Shell`]) registered through [`vm::Vm::register_library`].
// Compile-pipeline modules. Gated behind the `compile` feature
// (default on). With the feature off, the runtime accepts only
// precompiled bytecode through `Module::from_bytes` and
// `Vm::view_bytes_zero_copy`. Hosts that ship precompiled
// bytecode for the smallest possible runtime binary leave this
// feature off.
/// Abstract syntax tree node definitions.
/// AST to bytecode emission.
/// Closed-signed-interval lattice over `i64` used by the type
/// checker and the refinement-elision pass.
/// Source-text tokenisation (lexer).
/// Compile-time monomorphization of generic functions, structs, and
/// enums.
/// Token-to-AST recursive-descent parser.
/// Target descriptor (word/address/float widths, endianness) used by
/// [`compiler::compile_with_target`] for cross-architecture
/// portability.
/// Token definitions and keyword recognition.
/// Hindley-Milner type checker with generics, traits, and bounds.
/// Visitor and mutable-visitor traits with default walk methods over
/// the AST.
// Verifier modules. Gated behind the `verify` feature (default
// on). With the feature off, `Vm::new` skips structural and
// resource-bound verification and behaves like
// `Vm::new_unchecked` from the caller's perspective. The
// compiler's call to the verifier at the end of
// `compile_with_target` is likewise gated; with the feature off
// the compiler leaves the bytecode header's WCET and WCMU
// fields at 0 (auto).
/// Abstract-interpretation text-size lattice used by the WCMU pass
/// for dynamic-text allocations.
/// Structural verifier plus WCET and WCMU resource-bounds pass.
pub use ;
pub use KString;
pub use Address;
pub use ;
pub use Float;
pub use KeleusmaType;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Word;