sim/lib.rs
1//! # sim-nest -- the SIM umbrella crate (imported as `sim`)
2//!
3//! Published on crates.io as **`sim-nest`** (the bare name `sim` is taken), but the
4//! library import identifier is `sim`. Add it as `sim-nest = "0.1"` (or, to make the
5//! rename explicit, `sim = { package = "sim-nest", version = "0.1" }`) and write
6//! `use sim::...` throughout; the `#[sim::sim_lib]` / `#[sim::sim_fn]` proc-macros
7//! resolve against it unchanged. Note: `use sim_nest::...` will NOT resolve -- the
8//! crate's library name is `sim`, so import `sim`, not `sim_nest`.
9//!
10//! SIM is an expandable Rust runtime built around a small protocol kernel plus
11//! a large set of loadable libraries. The kernel defines contracts; libraries
12//! provide behavior. The data flow is:
13//!
14//! ```text
15//! tokens -> checked forms -> objects -> checked calls -> objects -> encoded forms
16//! ```
17//!
18//! SIM is a Rust runtime with multiple codec surfaces. Lisp is one codec, not
19//! the system identity. Everything above the kernel is a lib: syntax, codecs,
20//! classes, functions, number domains, checkers, evaluators, wasm adapters,
21//! loaders, and even the standard language surface. The standard distribution
22//! is just a set of libs loaded by default.
23//!
24//! ## Umbrella role
25//!
26//! This crate (`sim`) is the umbrella and entry point of the SIM constellation.
27//! The implementation crates live in sibling repositories; this crate
28//! aggregates them through optional dependencies and a feature map, re-exports
29//! them under stable module aliases (`sim::kernel`, `sim::shape`,
30//! `sim::codec`, the `sim::codec_*`, `sim::lib_*`, `sim::table_*`, and
31//! `sim::list_*` families), and ships the core runtime installer plus the
32//! authoring helpers (`functions`, `classes`, `macros`, `shapes`, and
33//! `runtime`, available with the `shape` feature). The default feature set is
34//! `core`, `codec-lisp`, and
35//! `numbers-f64`; the canonical, current feature map is this crate's
36//! `Cargo.toml`.
37//!
38//! ## Kernel boundary
39//!
40//! The central discipline is keeping the kernel small. The kernel may define
41//! identity and transport types (`Symbol`, `Expr`, `Value`, `Origin`, `Ref`,
42//! `Datum`, errors, stable ids), coordination types (`Cx`, `Registry`, `Lib`,
43//! `Linker`, `ExportRecord`, capabilities, claim/fact and handle stores, Card
44//! records, operation specs, event/effect ledgers, control policy, rank
45//! metadata), the object/callable/class/shape/factory/eval-policy/
46//! macro-expander behavior contracts, shape match and binding result types, and
47//! the ABI frame and manifest transport shapes. The kernel must not define
48//! concrete Lisp/JSON/Algol parsing, concrete number domains or arithmetic,
49//! concrete help/test/browse implementations, wasm guest behavior above the ABI
50//! transport, or remote transport and agent-product policy. New metadata is
51//! modeled as open `ExportRecord`-style data rather than new closed kernel
52//! enums. Concrete behavior is added as a lib through `Lib`, `Linker`, and
53//! `ExportRecord`.
54//!
55//! ## Load-bearing concepts
56//!
57//! - **`Shape`** is one shared engine for parsing, checking, binding, dispatch,
58//! macro syntax, codec grammar, lambda locals, and overload selection. It is
59//! a first-class kernel protocol (object-accessible via `as_shape`, callable
60//! as a matcher); concrete shape behavior lives in `sim-shape` and other libs.
61//! - **Codecs are first-class runtime objects**, split into independent
62//! decoders and encoders; encoders know their output position. General-purpose
63//! expression codecs are total over the shared `Expr` graph and round-trip
64//! every expression semantically; domain codecs round-trip only their domain
65//! and fail closed outside it.
66//! - **`realize` and `EvalFabric`** are the location-transparent distributed
67//! evaluation surface. Server and agent code targets these, never a
68//! transport-specific API. Evaluation strategy itself is an injectable
69//! `EvalPolicy` (eager, lazy, need, hybrid, no-op).
70//! - **Capability gating** makes power explicit: read-eval, native dynamic
71//! loading, and host effects (file, network, clock, random, process) are
72//! capabilities a host grants. **Read-construct** is the narrower
73//! capability-gated path that backs Lisp `#(...)` literals; it is distinct
74//! from broad **read-eval**, which evaluates during decode and is disabled by
75//! default for untrusted input.
76//! - **Number domains, lists, and tables are pluggable libs**, not kernel
77//! behavior; codecs delegate numeric literals to the active domains by parse
78//! priority.
79//! - **Wasm** is a first-class runtime target and the portable plugin ABI.
80//!
81//! ## Embedding
82//!
83//! `runtime::install_core_runtime` (with the `shape` feature) is the entry
84//! point for embedding SIM.
85//! Build a `Cx` with an eval policy and a factory, install the core runtime,
86//! then install codecs and behavior libs through their `install_*` helpers or
87//! directly through `Lib` and `Linker`:
88//!
89//! ```ignore
90//! use std::sync::Arc;
91//! use sim::kernel::{Cx, DefaultFactory, EagerPolicy};
92//! use sim::runtime::install_core_runtime;
93//!
94//! let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
95//! install_core_runtime(&mut cx);
96//! // install codecs and libs, then cx.eval_expr(...).
97//! ```
98//!
99//! `install_core_runtime` loads the core runtime through the lib registry and
100//! installs the default number domain(s) for the enabled `numbers-*` features.
101#![deny(unsafe_code)]
102#![deny(missing_docs)]
103#![allow(deprecated)]
104extern crate self as sim;
105
106#[rustfmt::skip]
107#[cfg(any(feature = "femm-assembly", feature = "femm-codec", feature = "femm-core", feature = "femm-fixtures", feature = "femm-field", feature = "femm-flow", feature = "femm-function", feature = "femm-geometry", feature = "femm-material", feature = "femm-mesh", feature = "femm-ode", feature = "femm-physics", feature = "femm-post", feature = "femm-prelude", feature = "femm-sensitiv", feature = "femm-solve", feature = "femm-space", feature = "femm-tape"))]
108pub use femm_exports::*;
109#[rustfmt::skip] #[allow(unused_imports)] pub use numbers_exports::*;
110#[rustfmt::skip] #[allow(unused_imports)] pub use standard_exports::*;
111#[rustfmt::skip]
112#[cfg(any(feature = "server-net-http", feature = "agent-net", feature = "openai-server-http", feature = "standard", feature = "rank-codec-fallback", feature = "rank-expr", feature = "rank-learn", feature = "rank-music", feature = "rank-scatter", feature = "stream-bridge", feature = "stream-host"))]
113const _: bool = true;
114#[allow(unused_imports)]
115pub use roadmap11_exports::*;
116#[cfg(feature = "agent")]
117pub use sim_lib_agent::{self as lib_agent, install_agent_lib};
118/// Native class authoring helpers: a `Class` implementation plus the lib
119/// wrapper that registers a host-defined class, its constructor, and members.
120#[cfg(all(feature = "core", feature = "shape"))]
121pub mod classes;
122#[rustfmt::skip]
123#[cfg(all(test, feature = "shape", feature = "codec-lisp", feature = "codec-json", feature = "codec-binary", feature = "codec-binary-base64", feature = "codec-algol"))]
124mod codec_matrix_tests;
125/// Stable hashing of lib manifests, shapes, and codecs for compatibility
126/// checks across versions of the constellation.
127#[cfg(feature = "core")]
128pub mod compat;
129mod femm_exports;
130/// Function authoring helpers built on the shared `Shape` engine: overload
131/// cases, native function objects, and member-table construction.
132#[cfg(all(feature = "core", feature = "shape"))]
133pub mod functions;
134/// Lib loaders for the supported source formats (host, Lisp source, binary
135/// pack, native dynamic library, and wasm) plus the standard loader registry.
136#[cfg(feature = "core")]
137pub mod loaders;
138/// Macro authoring and expansion: the `LispMacro` contract, macro objects, the
139/// registry-backed expander, and shape constructors for macro syntax.
140#[cfg(all(feature = "core", feature = "shape"))]
141pub mod macros;
142/// End-to-end music rendering stack that lowers a score to MIDI and renders it
143/// to PCM audio through the sound libs.
144#[cfg(feature = "sound-music")]
145pub mod music_stack;
146mod numbers_exports;
147mod roadmap11_exports;
148/// Core runtime installer and the embedding entry point that wires classes,
149/// shapes, functions, and the default number domains into a `Cx`.
150#[cfg(all(feature = "core", feature = "shape"))]
151pub mod runtime;
152/// Shape authoring helpers: documented and value-backed shape wrappers plus
153/// shape registration and checking utilities.
154#[cfg(all(feature = "core", feature = "shape"))]
155pub mod shapes;
156mod standard_exports;
157#[cfg(feature = "proc-macros")]
158pub use sim_macros::*;
159// The macros' native_export output emits `::sim::codec_binary::{decode_frame,
160// encode_frame}`, so the feature that enables the macros must also expose that
161// module. `proc-macros` pulls `codec-binary`; this contract asserts it, so a future
162// edit that drops it fails to compile instead of shipping macros that cannot expand.
163#[cfg(all(feature = "proc-macros", not(feature = "codec-binary")))]
164compile_error!("feature `proc-macros` requires `codec-binary` (macros emit `::sim::codec_binary`)");
165#[cfg(feature = "wasm")]
166pub use sim_wasm_abi as wasm_abi;
167#[cfg(test)]
168mod feature_contract_tests;
169#[cfg(all(test, feature = "music-stack"))]
170mod music_stack_tests;
171#[cfg(all(test, feature = "skill"))]
172mod skill_tests;