Skip to main content

sim_lib_lang_clojure/
profile.rs

1use sim_kernel::{Cx, Ref, Result, Symbol};
2use sim_lib_standard_core::{
3    FidelityBadge, LanguageProfile, OrganUse, ProfileRegistry, install_language_profile,
4};
5
6use crate::{
7    clojure_conformance_test_symbol, clojure_control_fidelity_symbol, clojure_core_profile_symbol,
8    clojure_edn_reader_symbol, clojure_lowering_symbol, clojure_namespace_fidelity_symbol,
9    clojure_sequence_fidelity_symbol,
10};
11
12/// Describes the Clojure-core language profile as standard-distribution data.
13///
14/// Binds the EDN reader, lowering, eval policy, numeric tower, and the sequence,
15/// namespace, and control organs, with a per-organ [`FidelityBadge`] against the
16/// conformance test.
17pub fn clojure_core_profile() -> LanguageProfile {
18    let profile = clojure_core_profile_symbol();
19    let test = clojure_conformance_test_symbol();
20    LanguageProfile::new(profile.clone())
21        .with_reader(clojure_edn_reader_symbol())
22        .with_lowering(clojure_lowering_symbol())
23        .with_eval_policy(Symbol::qualified("eval", "clojure-core"))
24        .with_organ(OrganUse::new(sim_lib_sequence::sequence_organ_symbol()))
25        .with_organ(OrganUse::new(sim_lib_namespace::namespace_organ_symbol()))
26        .with_organ(OrganUse::new(sim_lib_control::control_organ_symbol()))
27        .with_numeric_tower(Symbol::qualified("numbers", "clojure-core"))
28        .with_conformance_test(test.clone())
29        .with_fidelity_badge(FidelityBadge::new(
30            Ref::Symbol(profile.clone()),
31            clojure_sequence_fidelity_symbol(),
32            1,
33            Ref::Symbol(test.clone()),
34        ))
35        .with_fidelity_badge(FidelityBadge::new(
36            Ref::Symbol(profile.clone()),
37            clojure_namespace_fidelity_symbol(),
38            1,
39            Ref::Symbol(test.clone()),
40        ))
41        .with_fidelity_badge(FidelityBadge::new(
42            Ref::Symbol(profile),
43            clojure_control_fidelity_symbol(),
44            1,
45            Ref::Symbol(test),
46        ))
47}
48
49/// Installs the Clojure-core profile into a [`ProfileRegistry`], publishing organ claims.
50///
51/// Registers [`clojure_core_profile`] and runs the sequence, namespace, and
52/// control organ claim publishers as a side effect.
53pub fn install_clojure_core_profile(
54    cx: &mut Cx,
55    registry: &mut ProfileRegistry,
56) -> Result<LanguageProfile> {
57    install_language_profile(
58        cx,
59        registry,
60        clojure_core_profile(),
61        &[
62            sim_lib_sequence::publish_sequence_organ_claims_for_lib,
63            sim_lib_namespace::publish_namespace_organ_claims_for_lib,
64            sim_lib_control::publish_control_organ_claims_for_lib,
65        ],
66    )
67}