Skip to main content

sim_lib_lang_lua/
profile.rs

1use sim_kernel::{Cx, Result, Symbol};
2use sim_lib_standard_core::{
3    LanguageProfile, OrganUse, ProfileRegistry, fidelity_badge, install_language_profile,
4};
5
6use crate::{
7    lua_conformance_test_symbol, lua_control_fidelity_symbol, lua_full_runtime_fidelity_symbol,
8    lua_lowering_symbol, lua_mutation_fidelity_symbol, lua_profile_symbol, lua_reader_symbol,
9};
10
11/// Builds the [`LanguageProfile`] describing the Lua core surface profile.
12///
13/// Reuses the shared algol reader, wires Lua lowering and eval policy, draws on
14/// the control and mutation organs, requires the standard mutate capability,
15/// marks full-VM debug hooks as unsupported, and publishes honest fidelity
16/// badges (coroutines and table mutation supported, full runtime limited).
17pub fn lua_core_profile() -> LanguageProfile {
18    let profile = lua_profile_symbol();
19    let test = lua_conformance_test_symbol();
20    LanguageProfile::new(profile.clone())
21        .with_reader(lua_reader_symbol())
22        .with_lowering(lua_lowering_symbol())
23        .with_eval_policy(Symbol::qualified("eval", "lua-core"))
24        .with_organ(OrganUse::new(sim_lib_control::control_organ_symbol()))
25        .with_organ(OrganUse::new(sim_lib_mutation::mutation_organ_symbol()))
26        .requiring(sim_lib_mutation::standard_mutate_capability())
27        .with_unsupported_form(Symbol::qualified("lua", "full-vm-debug-hooks"))
28        .with_conformance_test(test.clone())
29        .with_fidelity_badge(fidelity_badge(
30            &profile,
31            lua_control_fidelity_symbol(),
32            1,
33            &test,
34        ))
35        .with_fidelity_badge(fidelity_badge(
36            &profile,
37            lua_mutation_fidelity_symbol(),
38            1,
39            &test,
40        ))
41        .with_fidelity_badge(fidelity_badge(
42            &profile,
43            lua_full_runtime_fidelity_symbol(),
44            0,
45            &test,
46        ))
47}
48
49/// Installs the Lua core profile and its organ claims into a registry.
50///
51/// First-reach entry point: registers [`lua_core_profile`] through the standard
52/// profile installer, publishing the control- and mutation-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_lua::install_lua_core_profile;
62///
63/// let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
64/// let mut registry = ProfileRegistry::new();
65/// let profile = install_lua_core_profile(&mut cx, &mut registry).unwrap();
66/// assert_eq!(profile.reader, Symbol::qualified("codec", "algol"));
67/// ```
68pub fn install_lua_core_profile(
69    cx: &mut Cx,
70    registry: &mut ProfileRegistry,
71) -> Result<LanguageProfile> {
72    install_language_profile(
73        cx,
74        registry,
75        lua_core_profile(),
76        &[
77            sim_lib_control::publish_control_organ_claims_for_lib,
78            sim_lib_mutation::publish_mutation_organ_claims_for_lib,
79        ],
80    )
81}