Skip to main content

bock_core/
lib.rs

1// Value has interior mutability (Rc<RefCell<IteratorKind>>) but iterator
2// values are never used as map/set keys (ordering panics at runtime).
3#![allow(clippy::mutable_key_type)]
4//! Bock core — core standard library primitives, collections, monadic types, iterators, and built-in operations.
5//!
6//! This crate populates the interpreter's [`BuiltinRegistry`] with the full
7//! method suites for primitive types (Int, Float, Bool, String, Char),
8//! collection types (List, Map, Set), monadic types (Optional, Result),
9//! iterator protocol (lazy combinators: map, filter, take, skip, enumerate, zip, chain, collect),
10//! and their core trait implementations (Comparable, Equatable, Hashable, Displayable).
11
12pub mod adaptive;
13pub mod collections;
14pub mod iterator;
15pub mod option_result;
16pub mod primitives;
17pub mod string_builder;
18pub mod time;
19pub mod traits;
20
21// ── Stub modules for unimplemented core modules ─────────────────────────────
22// These exist so that downstream code can reference the module paths without
23// error, even though they have no functionality yet.
24pub mod concurrency;
25pub mod effect;
26pub mod error;
27pub mod math;
28pub mod memory;
29pub mod test;
30
31#[cfg(test)]
32mod callback_tests;
33
34pub use traits::{ConversionDirection, TraitDispatch};
35
36use bock_interp::BuiltinRegistry;
37
38/// Register all primitive, collection, and monadic type methods and trait
39/// implementations into the given [`BuiltinRegistry`].
40///
41/// Call this during interpreter initialization to make all built-in methods
42/// available.
43pub fn register_core(registry: &mut BuiltinRegistry) {
44    // Primitives
45    primitives::int::register(registry);
46    primitives::float::register(registry);
47    primitives::bool::register(registry);
48    primitives::string::register(registry);
49    primitives::char::register(registry);
50    primitives::duration::register(registry);
51    primitives::instant::register(registry);
52
53    // Collections
54    collections::list::register(registry);
55    collections::map::register(registry);
56    collections::set::register(registry);
57
58    // Option & Result
59    option_result::optional::register(registry);
60    option_result::result::register(registry);
61
62    // Iterator protocol
63    iterator::register(registry);
64
65    // StringBuilder
66    string_builder::register(registry);
67
68    // Time (Duration/Instant already registered above as primitives; sleep is prelude)
69    time::register(registry);
70
71    // Concurrency primitives: Channel, spawn
72    concurrency::register(registry);
73}