Skip to main content

sim_lib_pattern/
claims.rs

1//! Organ claims for the pattern surface.
2//!
3//! These helpers name the pattern organ and its operation keys, then publish
4//! them as kernel claims so the organ and its operations are discoverable
5//! through the standard Card surface.
6
7use sim_kernel::{
8    Cx, LibId, OpKey, Result, Symbol,
9    standard::{publish_organ_claims, publish_organ_claims_for_lib},
10};
11
12/// Returns the organ symbol that identifies the pattern surface.
13pub fn pattern_organ_symbol() -> Symbol {
14    Symbol::qualified("organ", "pattern")
15}
16
17/// Returns the operation key for declaring an ADT.
18pub fn pattern_adt_op_key() -> OpKey {
19    pattern_op_key("adt")
20}
21
22/// Returns the operation key for constructing a tagged value.
23pub fn pattern_tag_op_key() -> OpKey {
24    pattern_op_key("tag")
25}
26
27/// Returns the operation key for matching a value against pattern arms.
28pub fn pattern_match_op_key() -> OpKey {
29    pattern_op_key("match")
30}
31
32/// Returns the operation key for destructuring a value or expression.
33pub fn pattern_destructure_op_key() -> OpKey {
34    pattern_op_key("destructure")
35}
36
37/// Returns the operation key for exhaustiveness checking.
38pub fn pattern_exhaustive_op_key() -> OpKey {
39    pattern_op_key("exhaustive")
40}
41
42/// Returns every operation key the pattern organ publishes.
43pub fn pattern_op_keys() -> Vec<OpKey> {
44    [
45        pattern_adt_op_key(),
46        pattern_tag_op_key(),
47        pattern_match_op_key(),
48        pattern_destructure_op_key(),
49        pattern_exhaustive_op_key(),
50    ]
51    .into()
52}
53
54/// Publishes the pattern organ and its operation keys as kernel claims.
55pub fn publish_pattern_organ_claims(cx: &mut Cx) -> Result<()> {
56    publish_organ_claims(cx, pattern_organ_symbol(), pattern_op_keys())
57}
58
59/// Publishes pattern organ claims as part of a loaded lib receipt.
60pub fn publish_pattern_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
61    publish_organ_claims_for_lib(cx, lib_id, pattern_organ_symbol(), pattern_op_keys())
62}
63
64fn pattern_op_key(name: &str) -> OpKey {
65    OpKey::new(Symbol::new("pattern"), Symbol::new(name), 1)
66}