forked from Orchid/orchid
94 lines
3.0 KiB
Rust
94 lines
3.0 KiB
Rust
use std::collections::HashMap;
|
|
use std::num::NonZeroU16;
|
|
|
|
use orchid_api_derive::{Coding, Hierarchy};
|
|
use orchid_api_traits::Request;
|
|
use ordered_float::NotNan;
|
|
|
|
use crate::{CharFilter, EagerVfs, ExtHostReq, HostExtNotif, HostExtReq, MemberKind, TStr};
|
|
|
|
/// ID of a system type
|
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
|
pub struct SysDeclId(pub NonZeroU16);
|
|
|
|
/// ID of a system instance
|
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
|
pub struct SysId(pub NonZeroU16);
|
|
|
|
/// Details about a system provided by this library. This is included in the
|
|
/// extension header, so it cannot rely on the interner.
|
|
#[derive(Debug, Clone, Coding)]
|
|
pub struct SystemDecl {
|
|
/// ID of the system, unique within the library
|
|
pub id: SysDeclId,
|
|
/// This can be depended upon. Exactly one of each kind will be loaded
|
|
pub name: String,
|
|
/// If multiple instances of a system are found, the highest priority will be
|
|
/// used. This can be used for version counting, but also for fallbacks if a
|
|
/// negative number is found.
|
|
///
|
|
/// Systems cannot depend on specific versions and older versions of systems
|
|
/// are never loaded. Compatibility can be determined on a per-system basis
|
|
/// through an algorithm chosen by the provider.
|
|
pub priority: NotNan<f64>,
|
|
/// List of systems needed for this one to work correctly. These will be
|
|
/// looked up, and an error produced if they aren't found.
|
|
pub depends: Vec<String>,
|
|
}
|
|
|
|
/// Host -> extension; instantiate a system according to its [SystemDecl].
|
|
/// Multiple instances of a system may exist in the same address space, so it's
|
|
/// essential that any resource associated with a system finds its system by the
|
|
/// ID in a global map.
|
|
#[derive(Clone, Debug, Coding, Hierarchy)]
|
|
#[extends(SysReq, HostExtReq)]
|
|
pub struct NewSystem {
|
|
/// ID of the system
|
|
pub system: SysDeclId,
|
|
/// ID of the system instance, unique for the host
|
|
pub id: SysId,
|
|
/// Instance IDs for dependencies, in the order that the names appear in the
|
|
/// declaration
|
|
pub depends: Vec<SysId>,
|
|
}
|
|
impl Request for NewSystem {
|
|
type Response = NewSystemResponse;
|
|
}
|
|
|
|
#[derive(Clone, Debug, Coding)]
|
|
pub struct NewSystemResponse {
|
|
/// The set of possible starting characters of tokens the lexer of this system
|
|
/// can process. The lexer will notify this system if it encounters one of
|
|
/// these characters.9
|
|
pub lex_filter: CharFilter,
|
|
pub line_types: Vec<TStr>,
|
|
pub const_root: HashMap<TStr, MemberKind>,
|
|
pub vfs: HashMap<TStr, EagerVfs>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Coding, Hierarchy)]
|
|
#[extends(HostExtNotif)]
|
|
pub struct SystemDrop(pub SysId);
|
|
|
|
#[derive(Clone, Debug, Coding, Hierarchy)]
|
|
#[extends(SysReq, HostExtReq)]
|
|
pub struct SysFwded(pub SysId, pub Vec<u8>);
|
|
impl Request for SysFwded {
|
|
type Response = Vec<u8>;
|
|
}
|
|
|
|
#[derive(Clone, Debug, Coding, Hierarchy)]
|
|
#[extends(ExtHostReq)]
|
|
pub struct SysFwd(pub SysId, pub Vec<u8>);
|
|
impl Request for SysFwd {
|
|
type Response = Vec<u8>;
|
|
}
|
|
|
|
#[derive(Clone, Debug, Coding, Hierarchy)]
|
|
#[extends(HostExtReq)]
|
|
#[extendable]
|
|
pub enum SysReq {
|
|
NewSystem(NewSystem),
|
|
SysFwded(SysFwded),
|
|
}
|