Skip to main content

sim_kernel/
lib.rs

1//! sim-kernel is the small protocol kernel of the SIM Rust runtime.
2//!
3//! The kernel defines contracts; libraries supply behavior. This crate holds
4//! the protocol and contract types -- forms, values, stores, registry and
5//! callable surfaces, the [`shape`] protocol, evaluation policy, and the ABI
6//! transport -- while concrete behavior (parsers, number domains, the standard
7//! distribution, and server/agent/browse implementations) lives in separate
8//! library crates loaded against these contracts. SIM is a Rust runtime, not a
9//! Lisp runtime; Lisp is one codec surface among several.
10//!
11//! The one deliberate exception is the pair of built-in *reference backends*:
12//! [`list::VecList`] (a [`list::ListValue`]) and [`table::AssocTable`] (a
13//! [`table::Table`]). These are the kernel's bootstrap list and table
14//! implementations -- minimal, correct, and self-annotated `sim-non-citizen` --
15//! so the runtime can stand up collections before any library loads. They are
16//! reference implementations, not the only backends: alternatives load as libs
17//! against the [`list::ListBackend`]/[`table::TableBackend`] contracts. (Future
18//! cleanup: move even these into a default-loaded distribution lib so the kernel
19//! ships pure contracts; tracked against the constellation reorg.)
20//!
21//! The kernel data flow is:
22//!
23//! ```text
24//! tokens -> checked forms -> objects -> checked calls -> objects -> encoded forms
25//! ```
26//!
27//! # Module map
28//!
29//! Core forms and values: [`value`], [`expr`], [`term`], [`encode`],
30//! [`error`], [`id`], [`ref_id`].
31//!
32//! Data substrate: [`datum`], [`datum_store`], [`fact_store`], [`claim`],
33//! [`card`], [`catalog`], [`handle_store`], [`hint`], [`ref_resolver`].
34//!
35//! Registry and behavior contracts: [`library`], [`op`], [`capability`],
36//! [`mod@env`], [`standard`], [`factory`].
37//!
38//! Callable, object, control, ledgers: [`callable`], [`class`], [`object`],
39//! [`control`], [`event`], [`event_ledger`], [`effect`], [`effect_ledger`],
40//! [`rank`].
41//!
42//! Shape protocol: [`shape`], [`shape_report`], [`pratt`].
43//!
44//! Evaluation: [`eval`], [`realize`].
45//!
46//! ABI, stream transport, collections: [`native_abi`], [`stream`],
47//! [`stream_surface`], [`list`], [`seq`], [`table`], [`number_domain`].
48#![forbid(unsafe_code)]
49#![deny(missing_docs)]
50pub mod callable;
51pub mod capability;
52pub mod card;
53pub mod catalog;
54pub mod claim;
55pub mod class;
56pub mod control;
57pub mod datum;
58pub mod datum_store;
59pub mod effect;
60pub mod effect_ledger;
61pub mod encode;
62pub mod env;
63pub mod error;
64pub mod eval;
65pub mod event;
66pub mod event_ledger;
67#[cfg(test)]
68mod event_tests;
69pub mod expr;
70pub mod fact_store;
71#[cfg(test)]
72mod fact_store_tests;
73pub mod factory;
74pub mod handle_store;
75pub mod hint;
76#[cfg(test)]
77mod hint_tests;
78pub mod id;
79pub mod library;
80pub mod list;
81pub mod native_abi;
82pub mod number_domain;
83pub mod object;
84pub mod op;
85#[cfg(test)]
86mod op_adapter_tests;
87mod op_adapters;
88#[cfg(test)]
89mod op_tests;
90pub mod pratt;
91pub mod rank;
92pub mod realize;
93#[cfg(test)]
94mod realize_tests;
95pub mod ref_id;
96pub mod ref_resolver;
97pub mod seq;
98#[cfg(test)]
99mod seq_tests;
100pub mod shape;
101pub mod shape_report;
102pub mod standard;
103pub mod stream;
104pub mod stream_surface;
105pub mod table;
106pub mod term;
107#[cfg(test)]
108mod term_tests;
109pub mod testing;
110pub mod value;
111pub use callable::Callable;
112pub use capability::{
113    CapabilityName, CapabilitySet, ReadPolicy, TrustLevel, browse_internal_capability,
114    browse_read_capability, browse_run_tests_capability, config_list_impl_capability,
115    config_table_impl_capability, eval_fabric_capability, eval_remote_capability,
116    fact_private_capability, list_force_unbounded_capability, logic_consult_file_capability,
117    logic_db_write_capability, logic_tool_call_capability, macro_expand_capability,
118    macro_expand_compile_capability, macro_expand_eval_capability, macro_expand_read_capability,
119    native_dynamic_load_capability, read_construct_capability, read_eval_capability,
120    registry_catalog_read_capability, table_remote_capability,
121};
122pub use claim::{Claim, ClaimKind, ClaimPattern, Visibility};
123pub use class::{Class, class_is_subclass_of};
124pub use datum::{
125    DATUM_CONTENT_ALGORITHM_NAME, DATUM_CONTENT_ALGORITHM_NAMESPACE, Datum, datum_content_algorithm,
126};
127pub use datum_store::{BTreeDatumStore, DatumStore};
128pub use effect::{Effect, effect_abort_op_key, effect_resume_op_key, effect_test_run_kind};
129pub use encode::{
130    CanonicalPolicy, ConstructorSurface, EncodeOptions, EncodePosition, ObjectEncode,
131    ObjectEncoding, ReadConstructEncodePolicy, ReadConstructor, ReadEvalEncodePolicy, WriteCx,
132};
133pub use env::{Capabilities, Cx, Diagnostics, Env};
134pub use error::{Diagnostic, Error, Result, Severity};
135pub use eval::{
136    Consistency, Demand, EagerPolicy, EvalFabric, EvalFabricRef, EvalMode, EvalPolicy,
137    EvalPolicyRef, EvalReply, EvalRequest, HybridPolicy, LazyPolicy, LazyThunkObject,
138    MacroExpander, MacroExpanderRef, NeedPolicy, NoopEvalPolicy, Phase, PreparedArgs,
139    StrictByShapePolicy, StrictNames, Thunk, ThunkObject, eval_expr_default, force_default,
140};
141pub use event::{Event, EventKind, EventSource, Tick, validate_ticks};
142pub use event_ledger::EventLedger;
143pub use expr::{
144    CanonicalKey, Expr, LocatedExpr, LocatedExprTree, NumberLiteral, Origin, QuoteMode, SourceId,
145    SourceRegistry, Span, Trivia,
146};
147pub use fact_store::{BTreeFactStore, FactStore};
148pub use factory::{DefaultFactory, Factory};
149pub use handle_store::{BTreeHandleStore, HandleStore};
150pub use hint::HintMetadata;
151#[rustfmt::skip]
152pub use id::{CORE_BOOL_CLASS_ID, CORE_BYTES_CLASS_ID, CORE_CARD_CLASS_ID, CORE_CLASS_CLASS_ID, CORE_CODEC_CLASS_ID, CORE_EVAL_REPLY_CLASS_ID, CORE_EVAL_REQUEST_CLASS_ID, CORE_EXPR_CLASS_ID, CORE_FUNCTION_CLASS_ID, CORE_HELP_CLASS_ID, CORE_LIST_CLASS_ID, CORE_LOCAL_EVAL_FABRIC_CLASS_ID, CORE_MACRO_CLASS_ID, CORE_NIL_CLASS_ID, CORE_NUMBER_CLASS_ID, CORE_NUMBER_DOMAIN_CLASS_ID, CORE_SEQUENCE_CLASS_ID, CORE_SHAPE_CLASS_ID, CORE_SHAPE_MATCH_CLASS_ID, CORE_STRING_CLASS_ID, CORE_SYMBOL_CLASS_ID, CORE_TABLE_CLASS_ID, CORE_TEST_CLASS_ID, CORE_THUNK_CLASS_ID, CaseId, ClassId, CodecId, FunctionId, LibId, MacroId, NumberDomainId, RuntimeId, ShapeId, SiteId, Symbol, ValueId};
153pub use library::{
154    AbiVersion, CatalogSource, Dependency, Export, ExportKind, ExportRecord, ExportState, Lib,
155    LibBootDependency, LibBootReceipt, LibLoader, LibManifest, LibSource, LibSourceSpec, LibTarget,
156    Linker, LoadCx, LoadedLib, LoaderRegistry, Registry, RegistryBootState, Test, TestReport,
157    Version,
158};
159pub use list::{
160    DEFAULT_FORCE_BOUND, LengthResult, ListBackend, ListRegistry, ListValue, VecList,
161    force_list_bound, force_list_to_vec, spine_len_cmp,
162};
163pub use native_abi::{
164    NATIVE_DYLIB_ENTRYPOINT_V1, NATIVE_LIB_ABI_V1_MAJOR, NATIVE_LIB_ABI_V1_MINOR,
165    NativeAbiBorrowedBytes, NativeAbiCall, NativeAbiCallResponse, NativeAbiDestroyBytes,
166    NativeAbiDestroyError, NativeAbiDestroyInstance, NativeAbiError, NativeAbiInstantiate,
167    NativeAbiManifest, NativeAbiOwnedBytes, NativeLibAbiHeaderV1, NativeLibAbiV1,
168    native_abi_owned_bytes,
169};
170pub use number_domain::{
171    NumberBinaryOp, NumberDomain, NumberReductionOp, NumberUnaryOp, NumberValue, NumberValueRef,
172    PromotionRule, PromotionSearchLimits, ValueNumberBinaryOp, ValueNumberReductionOp,
173    ValueNumberUnaryOp, ValuePromotionRule,
174};
175pub use object::{
176    Args, ClaimSink, ClassRef, Object, ObjectCompat, ObjectHeader, RawArgs, ReadConstructorRef,
177    ShapeRef, TableRef, default_object_header, is_default_object_header,
178};
179#[rustfmt::skip]
180pub use op::{Op, OpSpec, ResolvedOp, Step, check_shape_if_available, core_any_ref, core_call_op_key, core_class_symbol_op_key, core_dir_is_dir_op_key, core_expr_snapshot_op_key, core_force_op_key, core_list_items_op_key, core_number_domain_symbol_op_key, core_number_value_op_key, core_object_encoding_op_key, core_read_construct_op_key, core_realize_start_op_key, core_seq_close_op_key, core_seq_next_op_key, core_shape_check_term_op_key, core_shape_check_value_op_key, core_shape_describe_op_key, core_table_entries_op_key, invoke_op, resolve_op};
181pub use pratt::{
182    Fixity, PrattOperator, PrattResult, PrattTable, PrattTableObject, Token as PrattToken,
183    parse_symbol as parse_pratt_symbol, pratt_table_value,
184};
185pub use realize::{
186    BufferedEventSource, ObserveMode, RealizeRequest, drain_events_to_reply, realize_events,
187    realize_final,
188};
189pub use ref_id::{ContentId, Coordinate, HandleId, Ref};
190pub use ref_resolver::{
191    RefResolver, ResolvedRef, TemporaryRefResolver, value_from_datum, value_from_ref,
192};
193#[rustfmt::skip]
194pub use seq::{EventSourceSequence, ListSequence, Sequence, SequenceItem, seq_close, seq_close_value, seq_is_done, seq_next, seq_next_value, seq_peek, sequence_item_from_event, sequence_item_value};
195pub use shape::{
196    ExprKind, MatchScore, Shape, ShapeBindings, ShapeCallTarget, ShapeDoc, ShapeMatch,
197    ShapeMatchObject, call_shape, shape_is_subshape_of, shape_match_value,
198};
199pub use stream::Stream;
200pub use table::{AssocTable, Dir, Table, TableBackend, TableRegistry};
201pub use term::{OpKey, Term};
202pub use value::{RuntimeObject, Value};