feat(ir): implement resolve functionality (untested)

This commit is contained in:
multisn8 2024-01-19 00:45:01 +01:00
parent d8e08459a0
commit 29269e2fcd
Signed by: multisamplednight
GPG key ID: 6D525AA147CBDAE2
8 changed files with 203 additions and 101 deletions

View file

@ -25,7 +25,7 @@ use crate::Span;
///
/// It does **not** contain what kind of instruction this is.
/// Refer to [`crate::instruction::Kind`] for this instead.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Instruction(pub(super) Span);
impl Instruction {
@ -39,23 +39,37 @@ impl Instruction {
/// On an **instruction**, accepts incoming data.
///
/// An **instruction** cannot run if any of these are not connected.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Input(pub(super) Socket);
impl Input {
#[must_use]
pub fn socket(&self) -> &Socket {
&self.0
}
}
/// On an **instruction**, returns outgoing data to be fed to [`Input`]s.
///
/// In contrast to [`Input`]s, [`Output`]s may be used or unused.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Output(pub(super) Socket);
impl Output {
#[must_use]
pub fn socket(&self) -> &Socket {
&self.0
}
}
/// An unspecified socket on a specific **instruction**,
/// and where it is on that **instruction**.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Socket {
pub belongs_to: Instruction,
pub idx: SocketIdx,
}
/// Where a [`Socket`] is on an **instruction**.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct SocketIdx(pub u16);