Skip to main content

vm/builtins/
mod.rs

1// Shared builtin catalog (ids, names, arity, call-index mapping).
2// Runtime execution logic lives under builtins/runtime/.
3
4mod metadata;
5#[cfg(feature = "runtime")]
6pub(crate) mod runtime;
7
8pub use self::metadata::{CallableDef, CallableParam, CallableParamType, CallableSignature};
9use crate::ValueType;
10#[cfg(feature = "runtime")]
11pub(crate) use crate::vm::{HostFunctionRegistry, Value, Vm, VmResult};
12
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub struct LanguageBuiltinSpec {
15    pub name: &'static str,
16    pub docs: &'static str,
17    pub signatures: &'static [CallableSignature],
18}
19
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21pub struct BuiltinNamespaceMemberSpec {
22    pub name: &'static str,
23    pub arity: usize,
24    pub return_type: ValueType,
25    pub docs: &'static str,
26}
27
28impl BuiltinNamespaceMemberSpec {
29    pub const fn new(
30        name: &'static str,
31        arity: usize,
32        return_type: ValueType,
33        docs: &'static str,
34    ) -> Self {
35        Self {
36            name,
37            arity,
38            return_type,
39            docs,
40        }
41    }
42}
43
44#[derive(Clone, Copy, Debug, PartialEq, Eq)]
45pub struct BuiltinNamespaceSpec {
46    pub namespace: &'static str,
47    pub docs: &'static str,
48    pub runtime_supported_on_wasm: bool,
49    pub members: &'static [BuiltinNamespaceMemberSpec],
50}
51
52impl BuiltinNamespaceSpec {
53    pub const fn new(
54        namespace: &'static str,
55        docs: &'static str,
56        runtime_supported_on_wasm: bool,
57        members: &'static [BuiltinNamespaceMemberSpec],
58    ) -> Self {
59        Self {
60            namespace,
61            docs,
62            runtime_supported_on_wasm,
63            members,
64        }
65    }
66}
67
68#[derive(Clone, Copy, Debug)]
69struct BuiltinNamespaceMemberLookup {
70    name: &'static str,
71    builtin: BuiltinFunction,
72}
73
74impl BuiltinNamespaceMemberLookup {
75    const fn new(name: &'static str, builtin: BuiltinFunction) -> Self {
76        Self { name, builtin }
77    }
78}
79
80#[derive(Clone, Copy, Debug)]
81struct BuiltinNamespaceLookup {
82    name: &'static str,
83    members: &'static [BuiltinNamespaceMemberLookup],
84}
85
86impl BuiltinNamespaceLookup {
87    const fn new(name: &'static str, members: &'static [BuiltinNamespaceMemberLookup]) -> Self {
88        Self { name, members }
89    }
90}
91
92include!(concat!(env!("OUT_DIR"), "/builtin_catalog_generated.rs"));