Skip to main content

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
6/// Symbol identifying the binding organ in the claim store.
7///
8/// Used as the claim subject when publishing the organ's contributed
9/// operations into a [`Cx`].
10pub fn binding_organ_symbol() -> Symbol {
11    Symbol::qualified("organ", "binding")
12}
13
14/// Operation key for the `let` form (parallel lexical binding).
15pub fn binding_let_op_key() -> OpKey {
16    binding_op_key("let")
17}
18
19/// Operation key for the `let*` form (sequential lexical binding).
20pub fn binding_let_star_op_key() -> OpKey {
21    binding_op_key("let-star")
22}
23
24/// Operation key for the `letrec` form (mutually recursive lexical binding).
25pub fn binding_letrec_op_key() -> OpKey {
26    binding_op_key("letrec")
27}
28
29/// Operation key for the `dynamic-let` form (dynamic-extent binding).
30pub fn binding_dynamic_let_op_key() -> OpKey {
31    binding_op_key("dynamic-let")
32}
33
34/// Operation key for the `parameterize` form (dynamic parameter rebinding).
35pub fn binding_parameterize_op_key() -> OpKey {
36    binding_op_key("parameterize")
37}
38
39/// Operation key for the `profile-modes` form (per-profile binding/hygiene modes).
40pub fn binding_profile_modes_op_key() -> OpKey {
41    binding_op_key("profile-modes")
42}
43
44/// All operation keys contributed by the binding organ, in claim order.
45pub fn binding_op_keys() -> Vec<OpKey> {
46    [
47        binding_let_op_key(),
48        binding_let_star_op_key(),
49        binding_letrec_op_key(),
50        binding_dynamic_let_op_key(),
51        binding_parameterize_op_key(),
52        binding_profile_modes_op_key(),
53    ]
54    .into()
55}
56
57/// Publishes the binding organ's claims and operation keys into a [`Cx`].
58///
59/// The kernel defines the claim/organ contract; this crate supplies the
60/// binding organ's operation set. After publishing, the organ and its ops
61/// are discoverable through the standard Card projection.
62///
63/// # Examples
64///
65/// ```
66/// use std::sync::Arc;
67/// use sim_kernel::{Cx, DefaultFactory, NoopEvalPolicy};
68/// use sim_lib_binding::publish_binding_organ_claims;
69///
70/// let mut cx = Cx::new(Arc::new(NoopEvalPolicy), Arc::new(DefaultFactory));
71/// publish_binding_organ_claims(&mut cx).unwrap();
72/// ```
73pub fn publish_binding_organ_claims(cx: &mut Cx) -> Result<()> {
74    publish_organ_claims(cx, binding_organ_symbol(), binding_op_keys())
75}
76
77/// Publishes binding organ claims as part of a loaded lib receipt.
78pub fn publish_binding_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
79    publish_organ_claims_for_lib(cx, lib_id, binding_organ_symbol(), binding_op_keys())
80}
81
82fn binding_op_key(name: &str) -> OpKey {
83    OpKey::new(Symbol::new("binding"), Symbol::new(name), 1)
84}