sim_lib_pattern/
claims.rs1use sim_kernel::{
8 Cx, LibId, OpKey, Result, Symbol,
9 standard::{publish_organ_claims, publish_organ_claims_for_lib},
10};
11
12use crate::match_form::MatchForm;
13
14pub fn pattern_organ_symbol() -> Symbol {
16 Symbol::qualified("organ", "pattern")
17}
18
19pub fn pattern_adt_op_key() -> OpKey {
21 pattern_op_key("adt")
22}
23
24pub fn pattern_tag_op_key() -> OpKey {
26 pattern_op_key("tag")
27}
28
29pub fn pattern_match_op_key() -> OpKey {
31 pattern_op_key("match")
32}
33
34pub fn pattern_destructure_op_key() -> OpKey {
36 pattern_op_key("destructure")
37}
38
39pub fn pattern_exhaustive_op_key() -> OpKey {
41 pattern_op_key("exhaustive")
42}
43
44pub fn pattern_declared_op_keys() -> Vec<OpKey> {
47 [
48 pattern_adt_op_key(),
49 pattern_tag_op_key(),
50 pattern_match_op_key(),
51 pattern_destructure_op_key(),
52 pattern_exhaustive_op_key(),
53 ]
54 .into()
55}
56
57pub fn pattern_live_ops() -> Vec<(OpKey, Symbol)> {
59 vec![(pattern_match_op_key(), MatchForm::symbol())]
60}
61
62pub fn pattern_op_keys() -> Vec<OpKey> {
64 pattern_live_ops()
65 .into_iter()
66 .map(|(op_key, _export_symbol)| op_key)
67 .collect()
68}
69
70pub fn publish_pattern_organ_claims(cx: &mut Cx) -> Result<()> {
72 publish_organ_claims(cx, pattern_organ_symbol(), pattern_op_keys())
73}
74
75pub fn publish_pattern_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
77 publish_organ_claims_for_lib(cx, lib_id, pattern_organ_symbol(), pattern_op_keys())
78}
79
80fn pattern_op_key(name: &str) -> OpKey {
81 OpKey::new(Symbol::new("pattern"), Symbol::new(name), 1)
82}