sim_lib_pattern/
runtime.rs1use std::sync::Arc;
8
9use sim_kernel::{
10 AbiVersion, Cx, Export, Lib, LibManifest, LibTarget, Linker, Result, Symbol, Version,
11};
12
13use crate::match_form::MatchForm;
14
15const PATTERN_LIB_ID: &str = "pattern";
16
17pub fn manifest_name() -> Symbol {
19 Symbol::qualified("sim", PATTERN_LIB_ID)
20}
21
22pub struct PatternLib;
24
25impl Lib for PatternLib {
26 fn manifest(&self) -> LibManifest {
27 LibManifest {
28 id: manifest_name(),
29 version: Version(env!("CARGO_PKG_VERSION").to_owned()),
30 abi: AbiVersion { major: 0, minor: 1 },
31 target: LibTarget::HostRegistered,
32 requires: Vec::new(),
33 capabilities: Vec::new(),
34 exports: pattern_exports(),
35 }
36 }
37
38 fn load(&self, cx: &mut sim_kernel::LoadCx, linker: &mut Linker<'_>) -> Result<()> {
39 linker.function_value(
40 MatchForm::symbol(),
41 cx.factory().opaque(Arc::new(MatchForm))?,
42 )?;
43 Ok(())
44 }
45}
46
47pub fn pattern_exports() -> Vec<Export> {
49 vec![Export::Function {
50 symbol: MatchForm::symbol(),
51 function_id: None,
52 }]
53}
54
55pub fn install_pattern_lib(cx: &mut Cx) -> Result<()> {
57 if cx.registry().lib(&manifest_name()).is_some() {
58 return Ok(());
59 }
60 cx.load_lib(&PatternLib)?;
61 Ok(())
62}