sim_lib_binding/claims.rs
1use sim_kernel::{
2 Cx, LibId, OpKey, Result, Symbol,
3 standard::{publish_organ_claims, publish_organ_claims_for_lib},
4};
5
6use crate::let_form::LetForm;
7
8/// Symbol identifying the binding organ in the claim store.
9///
10/// Used as the claim subject when publishing the organ's contributed
11/// operations into a [`Cx`].
12pub fn binding_organ_symbol() -> Symbol {
13 Symbol::qualified("organ", "binding")
14}
15
16/// Operation key for the `let` form (parallel lexical binding).
17pub fn binding_let_op_key() -> OpKey {
18 binding_op_key("let")
19}
20
21/// Operation key for the `let*` form (sequential lexical binding).
22pub fn binding_let_star_op_key() -> OpKey {
23 binding_op_key("let-star")
24}
25
26/// Operation key for the `letrec` form (mutually recursive lexical binding).
27pub fn binding_letrec_op_key() -> OpKey {
28 binding_op_key("letrec")
29}
30
31/// Operation key for the `dynamic-let` form (dynamic-extent binding).
32pub fn binding_dynamic_let_op_key() -> OpKey {
33 binding_op_key("dynamic-let")
34}
35
36/// Operation key for the `parameterize` form (dynamic parameter rebinding).
37pub fn binding_parameterize_op_key() -> OpKey {
38 binding_op_key("parameterize")
39}
40
41/// Operation key for the `profile-modes` form (per-profile binding/hygiene modes).
42pub fn binding_profile_modes_op_key() -> OpKey {
43 binding_op_key("profile-modes")
44}
45
46/// All binding-surface operations this crate models, whether or not they are
47/// currently exported as live runtime callables.
48pub fn binding_declared_op_keys() -> Vec<OpKey> {
49 [
50 binding_let_op_key(),
51 binding_let_star_op_key(),
52 binding_letrec_op_key(),
53 binding_dynamic_let_op_key(),
54 binding_parameterize_op_key(),
55 binding_profile_modes_op_key(),
56 ]
57 .into()
58}
59
60/// Live binding claim-to-export mappings backed by the loaded runtime surface.
61pub fn binding_live_ops() -> Vec<(OpKey, Symbol)> {
62 vec![(binding_let_op_key(), LetForm::symbol())]
63}
64
65/// Operation keys the binding organ currently publishes as live claims.
66pub fn binding_op_keys() -> Vec<OpKey> {
67 binding_live_ops()
68 .into_iter()
69 .map(|(op_key, _export_symbol)| op_key)
70 .collect()
71}
72
73/// Publishes the binding organ's claims and operation keys into a [`Cx`].
74///
75/// The kernel defines the claim/organ contract; this crate supplies the
76/// binding organ's operation set. After publishing, the organ and its ops
77/// are discoverable through the standard Card projection.
78///
79/// # Examples
80///
81/// ```
82/// use std::sync::Arc;
83/// use sim_kernel::{Cx, DefaultFactory, NoopEvalPolicy};
84/// use sim_lib_binding::publish_binding_organ_claims;
85///
86/// let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
87/// publish_binding_organ_claims(&mut cx).unwrap();
88/// ```
89pub fn publish_binding_organ_claims(cx: &mut Cx) -> Result<()> {
90 publish_organ_claims(cx, binding_organ_symbol(), binding_op_keys())
91}
92
93/// Publishes binding organ claims as part of a loaded lib receipt.
94pub fn publish_binding_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
95 publish_organ_claims_for_lib(cx, lib_id, binding_organ_symbol(), binding_op_keys())
96}
97
98fn binding_op_key(name: &str) -> OpKey {
99 OpKey::new(Symbol::new("binding"), Symbol::new(name), 1)
100}