Skip to main content

logicaffeine_system/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3
4// === Always Available (Core IO) ===
5pub mod io;
6pub mod failure;
7pub mod temporal;
8
9// The observation channel for compiled (AOT-Rust) programs compiled in the
10// OBSERVED profile: Note/Warn/
11// Record/During emit here. No-op when no sink is installed; the release (elided)
12// profile emits none of these calls, so it pays nothing.
13pub mod obs;
14
15// The sealed test world (`largo test`): a thread-local that intercepts the IO natives with simulated
16// resources — virtual clock, in-memory FS, empty env, seeded RNG. One TL
17// check per IO call; zero cost on compute paths.
18pub mod testworld;
19
20// The thin-relay wire protocol — shared by the native relay server (under
21// `networking`) and the browser relay client (wasm). Target-agnostic (serde
22// only), so it compiles into both the native binary and the wasm bundle without
23// dragging in libp2p.
24pub mod relay_proto;
25
26// Address normalization (libp2p multiaddr → ws:// URL) so the interpreter accepts
27// the same peer-address surface as the compiled path. Pure string logic, no
28// libp2p, no target gating — identical on native and wasm.
29pub mod addr;
30
31// The native WebSocket relay server + client. A LIGHT capability behind its own
32// `relay` feature (tokio-tungstenite, NO libp2p) so the interpreter can network
33// over the relay without the mesh stack. `networking` implies `relay`.
34#[cfg(all(not(target_arch = "wasm32"), feature = "relay"))]
35pub mod relay;
36
37// Browser relay client — a `web-sys` WebSocket speaking `relay_proto`, the
38// browser's door into a native node's relay. wasm-only; no libp2p.
39#[cfg(target_arch = "wasm32")]
40pub mod relay_browser;
41
42// The cross-target `Net` handle the interpreter holds — native RelayClient or
43// browser WebSocket behind one API. Available wherever a relay client is.
44#[cfg(any(
45    all(not(target_arch = "wasm32"), feature = "relay"),
46    target_arch = "wasm32"
47))]
48pub mod net;
49
50// Native HTTP/1.1 server — what a LOGOS program's `Serve` statement runs on. A
51// LIGHT capability behind its own `http` feature (raw tokio + a hand-rolled wire
52// core, NO hyper) so a LOGOS backend can serve a website with no extra protocol
53// dependency. The HTTP core sits behind an internal transport boundary so hyper
54// can drop in later without touching the LOGOS handler bridge.
55#[cfg(all(not(target_arch = "wasm32"), feature = "http"))]
56pub mod http;
57
58// A page document's CSRF meta — pure text, composed and read on every target.
59pub mod csrf;
60
61// Core runtime seams. `time` and `random` are the ONE seam every tier's
62// `now`/`randomInt`/`randomFloat` natives route through, so they compile on every
63// target: on wasm, `time` reads `js_sys::Date` and `random` reseeds from getrandom's
64// `js` backend (both still sealed-world aware). `env` and `text` remain native-only.
65#[cfg(not(target_arch = "wasm32"))]
66pub mod env;
67pub mod stack;
68pub mod random;
69#[cfg(not(target_arch = "wasm32"))]
70pub mod tcp;
71#[cfg(not(target_arch = "wasm32"))]
72pub mod text;
73pub mod time;
74
75// === Feature-Gated Modules ===
76
77// Persistence feature: file operations, storage, VFS
78#[cfg(feature = "persistence")]
79pub mod file;
80#[cfg(feature = "persistence")]
81pub mod fs;
82#[cfg(feature = "persistence")]
83pub mod storage;
84
85// Networking feature: P2P networking
86#[cfg(feature = "networking")]
87pub mod network;
88
89// Concurrency feature: parallel computation
90#[cfg(feature = "concurrency")]
91pub mod concurrency;
92#[cfg(feature = "concurrency")]
93pub mod memory;
94#[cfg(feature = "concurrency")]
95pub mod replay;
96
97// Distributed<T> requires both networking AND persistence
98#[cfg(all(feature = "networking", feature = "persistence"))]
99pub mod distributed;
100
101// CRDT sync wrapper requires networking (uses tokio + libp2p)
102#[cfg(feature = "networking")]
103pub mod crdt;
104
105// Runtime support for the Word8/16/32/64 ring types in compiled LOGOS (constructors,
106// rotations, Showable). Operators live on the newtypes themselves in logicaffeine_base.
107pub mod word_rt;
108
109// ML-KEM (Kyber) NTT runtime kernel (scalar + AVX2 i16×16) reached via the `mlkemNtt` stdlib fn.
110pub mod ntt;
111
112// Keccak-f[1600] + SHA-3 / SHAKE — the symmetric/hash layer (reached via sha3_256/shake128/… ).
113pub mod keccak;
114
115// ChaCha20-Poly1305 AEAD (RFC 8439) — the symmetric seal for the post-quantum channel.
116pub mod aead;
117
118// ML-KEM-768 (FIPS-203) keygen/encaps/decaps composed from the NTT + Keccak kernels — the
119// post-quantum key exchange for the channel handshake.
120pub mod mlkem;
121
122// ML-DSA-65 (FIPS-204) signature kernels — the post-quantum signature complement to ML-KEM.
123pub mod mldsa;
124
125// The argument contract of the standard library's native kernels: bytes, lengths, ranges.
126mod kernel_args;
127
128// Re-export tokio for async main support (native only)
129#[cfg(not(target_arch = "wasm32"))]
130pub use tokio;
131/// The async TLS wrapper, re-exported so the interpreter/VM socket registry uses the SAME
132/// rustls version and the same client config this crate builds for the synchronous path.
133///
134/// Native-only, like every other consumer of it: `tcp` is `cfg(not(wasm32))` and this re-export
135/// was not, so a wasm32 build referred to a crate it no longer depends on.
136#[cfg(not(target_arch = "wasm32"))]
137pub use tokio_rustls;
138
139// Re-export commonly used items
140pub use io::{eprintln, print, println, read_line, show, Showable};
141pub use keccak::{sha3_256, sha3_512, shake128, shake256};
142pub use ntt::{
143    mlkem_base_mul, mlkem_byte_decode, mlkem_byte_encode, mlkem_cbd2, mlkem_cbd3, mlkem_compress,
144    mlkem_decompress, mlkem_inv_ntt, mlkem_ntt, mlkem_sample_a, mlkem_sample_ntt, mlkem_to_mont,
145};
146pub use temporal::{LogosDate, LogosMoment, LogosSpan, LogosTime};
147pub use word_rt::{
148    and_not4, byte_add16, hsum_lanes4, int_of_word16, int_of_word32, int_of_word64, int_of_word8,
149    interleave_hi16, interleave_lo16, lanes16_word16, lanes16_word8, lanes4_of, lanes4_word32,
150    lanes4_word64, lanes8_word32, maddubs16, montmul32, mul32x32to64, mulhi16, packus16, rotl,
151    rotr, seq_of_lanes16, seq_of_lanes16w8, seq_of_lanes4, seq_of_lanes4w32, seq_of_lanes8,
152    sha1msg1, sha1msg2, sha1nexte, sha1rnds4, shr_bytes16, shuffle16, splat16_word16,
153    splat16_word8, splat4_word64, splat8_word32, word16, word32, word32_shr, word64, word64_and,
154    word64_shl, word64_shr, word8, word_and, word_not, word_or, Lanes16Word16, Lanes16Word8,
155    Lanes4Word32, Lanes4Word64, Lanes8Word32, Word16, Word32, Word64, Word8, WordRotate,
156};
157
158/// Panic with a custom message (used by generated LOGOS code)
159pub fn panic_with(reason: &str) -> ! {
160    panic!("{}", reason);
161}
162
163/// Formatting utilities
164pub mod fmt {
165    pub fn format<T: std::fmt::Display>(x: T) -> String {
166        format!("{}", x)
167    }
168}