Skip to main content

sim_lib_lang_ruby/
profile.rs

1use sim_kernel::{Cx, Result, Symbol};
2use sim_lib_standard_core::{
3    LanguageProfile, OrganUse, ProfileBackingLib, ProfileRegistry, fidelity_badge,
4    install_language_profile,
5};
6
7use crate::{
8    ruby_blocks_fidelity_symbol, ruby_conformance_test_symbol, ruby_control_fidelity_symbol,
9    ruby_dispatch_fidelity_symbol, ruby_lowering_symbol, ruby_profile_symbol, ruby_reader_symbol,
10};
11
12/// Builds the [`LanguageProfile`] describing the Ruby DSL surface profile.
13///
14/// Reuses the shared algol reader, wires Ruby lowering and eval policy, draws on
15/// the control and dispatch organs, marks the full object model as unsupported,
16/// and publishes honest fidelity badges (control and dispatch supported, full
17/// blocks limited).
18pub fn ruby_dsl_profile() -> LanguageProfile {
19    let profile = ruby_profile_symbol();
20    let test = ruby_conformance_test_symbol();
21    LanguageProfile::new(profile.clone())
22        .with_reader(ruby_reader_symbol())
23        .with_lowering(ruby_lowering_symbol())
24        .with_eval_policy(Symbol::qualified("eval", "ruby-dsl"))
25        .with_organ(OrganUse::new(sim_lib_control::control_organ_symbol()))
26        .with_organ(OrganUse::new(sim_lib_dispatch::dispatch_organ_symbol()))
27        .with_unsupported_form(Symbol::qualified("ruby", "full-object-model"))
28        .with_conformance_test(test.clone())
29        .with_fidelity_badge(fidelity_badge(
30            &profile,
31            ruby_control_fidelity_symbol(),
32            1,
33            &test,
34        ))
35        .with_fidelity_badge(fidelity_badge(
36            &profile,
37            ruby_dispatch_fidelity_symbol(),
38            1,
39            &test,
40        ))
41        .with_fidelity_badge(fidelity_badge(
42            &profile,
43            ruby_blocks_fidelity_symbol(),
44            0,
45            &test,
46        ))
47}
48
49/// Installs the Ruby DSL profile and its organ claims into a registry.
50///
51/// First-reach entry point: registers [`ruby_dsl_profile`] through the standard
52/// profile installer, publishing the control- and dispatch-organ claims so the
53/// surface becomes loadable.
54///
55/// # Examples
56///
57/// ```
58/// use std::sync::Arc;
59/// use sim_kernel::{Cx, DefaultFactory, NoopEvalPolicy, Symbol};
60/// use sim_lib_standard_core::ProfileRegistry;
61/// use sim_lib_lang_ruby::install_ruby_dsl_profile;
62///
63/// let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
64/// let mut registry = ProfileRegistry::new();
65/// let profile = install_ruby_dsl_profile(&mut cx, &mut registry).unwrap();
66/// assert_eq!(profile.reader, Symbol::qualified("codec", "algol"));
67/// ```
68pub fn install_ruby_dsl_profile(
69    cx: &mut Cx,
70    registry: &mut ProfileRegistry,
71) -> Result<LanguageProfile> {
72    install_language_profile(
73        cx,
74        registry,
75        ruby_dsl_profile(),
76        &[
77            ProfileBackingLib::loadable(
78                sim_lib_control::control_organ_symbol(),
79                sim_lib_control::manifest_name(),
80                sim_lib_control::install_control_lib,
81                None,
82            ),
83            ProfileBackingLib::unresolved(
84                sim_lib_dispatch::dispatch_organ_symbol(),
85                Symbol::qualified("sim", "dispatch"),
86            ),
87        ],
88        &[],
89    )
90}