Skip to main content

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). The opt-in `expr-tree` feature exposes the
32//! canonical expression-tree core, calculation, runtime, view, and server
33//! crates without adding a facade-specific builder or policy layer. This
34//! crate also ships the core runtime installer plus the authoring helpers
35//! (`functions`, `classes`, `macros`, `shapes`, and `runtime`, available with
36//! the `shape` feature). The default feature set is `core`, `shape`,
37//! `codec-lisp`, and `numbers-f64`; the canonical, current feature map is this
38//! crate's `Cargo.toml`.
39//!
40//! ## Kernel boundary
41//!
42//! The central discipline is keeping the kernel small. The kernel may define
43//! identity and transport types (`Symbol`, `Expr`, `Value`, `Origin`, `Ref`,
44//! `Datum`, errors, stable ids), coordination types (`Cx`, `Registry`, `Lib`,
45//! `Linker`, `ExportRecord`, capabilities, claim/fact and handle stores, Card
46//! records, operation specs, event/effect ledgers, control policy, rank
47//! metadata), the object/callable/class/shape/factory/eval-policy/
48//! macro-expander behavior contracts, shape match and binding result types, and
49//! the ABI frame and manifest transport shapes. The kernel must not define
50//! concrete Lisp/JSON/Algol parsing, concrete number domains or arithmetic,
51//! concrete help/test/browse implementations, wasm guest behavior above the ABI
52//! transport, or remote transport and agent-product policy. New metadata is
53//! modeled as open `ExportRecord`-style data rather than new closed kernel
54//! enums. Concrete behavior is added as a lib through `Lib`, `Linker`, and
55//! `ExportRecord`.
56//!
57//! ## Load-bearing concepts
58//!
59//! - **`Shape`** is one shared engine for parsing, checking, binding, dispatch,
60//!   macro syntax, codec grammar, lambda locals, and overload selection. It is
61//!   a first-class kernel protocol (object-accessible via `as_shape`, callable
62//!   as a matcher); concrete shape behavior lives in `sim-shape` and other libs.
63//! - **Codecs are first-class runtime objects**, split into independent
64//!   decoders and encoders; encoders know their output position. General-purpose
65//!   expression codecs are total over the shared `Expr` graph and round-trip
66//!   every expression semantically; domain codecs round-trip only their domain
67//!   and fail closed outside it.
68//! - **`realize` and `EvalFabric`** are the location-transparent distributed
69//!   evaluation surface. Server and agent code targets these, never a
70//!   transport-specific API. Evaluation strategy itself is an injectable
71//!   `EvalPolicy` (eager, lazy, need, hybrid, no-op).
72//! - **Capability gating** makes power explicit: read-eval, native dynamic
73//!   loading, and host effects (file, network, clock, random, process) are
74//!   capabilities a host grants. **Read-construct** is the narrower
75//!   capability-gated path that backs Lisp `#(...)` literals; it is distinct
76//!   from broad **read-eval**, which evaluates during decode and is disabled by
77//!   default for untrusted input.
78//! - **Number domains, lists, and tables are pluggable libs**, not kernel
79//!   behavior; codecs delegate numeric literals to the active domains by parse
80//!   priority.
81//! - **Wasm** is a first-class runtime target and the portable plugin ABI.
82//!
83//! ## Embedding
84//!
85//! `runtime::install_core_runtime` (with the `shape` feature) is the entry
86//! point for embedding SIM.
87//! Build a `Cx` with an eval policy and a factory, install the core runtime,
88//! then install codecs and behavior libs through their `install_*` helpers or
89//! directly through `Lib` and `Linker`:
90//!
91//! ```ignore
92//! use std::sync::Arc;
93//! use sim::kernel::{Cx, DefaultFactory, EagerPolicy};
94//! use sim::runtime::install_core_runtime;
95//!
96//! let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
97//! install_core_runtime(&mut cx);
98//! // install codecs and libs, then cx.eval_expr(...).
99//! ```
100//!
101//! `install_core_runtime` loads the core runtime through the lib registry and
102//! installs the default number domain(s) for the enabled `numbers-*` features.
103#![deny(unsafe_code)]
104#![deny(missing_docs)]
105#![allow(deprecated)]
106extern crate self as sim;
107
108#[rustfmt::skip]
109#[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"))]
110pub use femm_exports::*;
111#[rustfmt::skip] #[allow(unused_imports)] pub use numbers_exports::*;
112#[rustfmt::skip] #[allow(unused_imports)] pub use standard_exports::*;
113#[rustfmt::skip]
114#[cfg(any(feature = "server-net-http", feature = "agent-net", feature = "glasses", 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"))]
115const _: bool = true;
116#[allow(unused_imports)]
117pub use roadmap11_exports::*;
118#[rustfmt::skip]
119#[cfg(any(feature = "compute-auto", feature = "compute-cli", feature = "compute-cuda", feature = "compute-femm", feature = "compute-model", feature = "compute-rocm", feature = "compute-wgpu"))]
120pub use compute_exports::*;
121#[rustfmt::skip]
122#[cfg(any(feature = "interference-core", feature = "interference-solve", feature = "interference-runtime", feature = "interference-compute", feature = "view-interference"))]
123pub use interference_exports::*;
124#[cfg(feature = "expr-tree")]
125pub use expr_tree_exports::*;
126#[cfg(feature = "agent")]
127pub use sim_lib_agent::{self as lib_agent, install_agent_lib};
128/// Native class authoring helpers: a `Class` implementation plus the lib
129/// wrapper that registers a host-defined class, its constructor, and members.
130#[cfg(all(feature = "core", feature = "shape"))]
131pub mod classes;
132#[rustfmt::skip]
133#[cfg(all(test, feature = "shape", feature = "codec-lisp", feature = "codec-json", feature = "codec-binary", feature = "codec-binary-base64", feature = "codec-algol", feature = "codec-bridge", feature = "bridge"))]
134mod codec_matrix_tests;
135/// Stable hashing of lib manifests, shapes, and codecs for compatibility
136/// checks across versions of the constellation.
137#[cfg(feature = "core")]
138pub mod compat;
139mod compute_exports;
140#[cfg(feature = "expr-tree")]
141mod expr_tree_exports;
142mod femm_exports;
143/// Function authoring helpers built on the shared `Shape` engine: overload
144/// cases, native function objects, and member-table construction.
145#[cfg(all(feature = "core", feature = "shape"))]
146pub mod functions;
147mod interference_exports;
148/// Lib loaders for the supported source formats (host, Lisp source, binary
149/// pack, native dynamic library, and wasm) plus the standard loader registry.
150#[cfg(feature = "core")]
151pub mod loaders;
152/// Macro authoring and expansion: the `LispMacro` contract, macro objects, the
153/// registry-backed expander, and shape constructors for macro syntax.
154#[cfg(all(feature = "core", feature = "shape"))]
155pub mod macros;
156mod music_algorithm_exports;
157/// End-to-end music rendering stack that lowers a score to MIDI and renders it
158/// to PCM audio through the sound libs.
159#[cfg(feature = "sound-music")]
160pub mod music_stack;
161mod numbers_exports;
162#[allow(unused_imports)]
163pub use music_algorithm_exports::*;
164mod roadmap11_exports;
165/// Core runtime installer and the embedding entry point that wires classes,
166/// shapes, functions, and the default number domains into a `Cx`.
167#[cfg(all(feature = "core", feature = "shape"))]
168pub mod runtime;
169#[cfg(feature = "serial-music")]
170pub mod serial_music;
171/// Shape authoring helpers: documented and value-backed shape wrappers plus
172/// shape registration and checking utilities.
173#[cfg(all(feature = "core", feature = "shape"))]
174pub mod shapes;
175mod standard_exports;
176#[cfg(feature = "proc-macros")]
177pub use sim_macros::*;
178// The macros' native_export output emits `::sim::codec_binary::{decode_frame,
179// encode_frame}`, so the feature that enables the macros must also expose that
180// module. `proc-macros` pulls `codec-binary`; this contract asserts it, so an
181// edit that drops it fails to compile instead of shipping macros that cannot expand.
182#[cfg(all(feature = "proc-macros", not(feature = "codec-binary")))]
183compile_error!("feature `proc-macros` requires `codec-binary` (macros emit `::sim::codec_binary`)");
184#[cfg(feature = "wasm")]
185pub use sim_wasm_abi as wasm_abi;
186#[cfg(test)]
187mod feature_contract_tests;
188#[cfg(all(test, feature = "music-stack"))]
189mod music_stack_tests;
190#[cfg(all(test, feature = "skill"))]
191mod skill_tests;