#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NativeFnId(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NativeTypeId(pub u32);
pub trait NativeProvider: Send + Sync {
fn modules(&self) -> Vec<NativeModule>;
fn expand(&self, path: &[String]) -> NativeModule;
fn register_enum_builtins(&self, _enum_def: super::DefId) -> Vec<NativeFnDecl> {
Vec::new()
}
}
impl<T: NativeProvider + ?Sized> NativeProvider for std::sync::Arc<T> {
fn modules(&self) -> Vec<NativeModule> {
(**self).modules()
}
fn expand(&self, path: &[String]) -> NativeModule {
(**self).expand(path)
}
fn register_enum_builtins(&self, enum_def: super::DefId) -> Vec<NativeFnDecl> {
(**self).register_enum_builtins(enum_def)
}
}
impl NativeProvider for Vec<NativeModule> {
fn modules(&self) -> Vec<NativeModule> {
self.clone()
}
fn expand(&self, path: &[String]) -> NativeModule {
panic!("`{}` was not declared lazy", path.join("::"))
}
}
#[derive(Debug, Clone, Default)]
pub struct NativeModule {
pub name: String,
pub lazy: bool,
pub functions: Vec<NativeFnDecl>,
pub types: Vec<NativeTypeDecl>,
pub modules: Vec<NativeModule>,
}
#[derive(Debug, Clone)]
pub struct NativeFnDecl {
pub name: String,
pub id: NativeFnId,
pub param_names: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct NativeTypeDecl {
pub name: String,
pub id: NativeTypeId,
pub functions: Vec<NativeFnDecl>,
pub variants: Vec<NativeVariantDecl>,
}
#[derive(Debug, Clone)]
pub struct NativeVariantDecl {
pub name: String,
pub kind: NativeVariantKind,
pub repr_value: Option<i64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NativeVariantKind {
Unit,
Tuple,
Named,
}