forked from Orchid/orchid
Correctly halts
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
use std::fmt;
|
||||
use std::num::NonZeroU64;
|
||||
|
||||
use itertools::Itertools;
|
||||
use orchid_api_derive::{Coding, Hierarchy};
|
||||
use orchid_api_traits::Request;
|
||||
|
||||
use crate::{
|
||||
ExprTicket, Expression, ExtHostReq, FormattingUnit, HostExtNotif, HostExtReq, OrcResult, SysId,
|
||||
TStrv,
|
||||
ExprTicket, Expression, ExtHostReq, FormattingUnit, HostExtReq, OrcResult, SysId, TStrv,
|
||||
};
|
||||
|
||||
pub type AtomData = Vec<u8>;
|
||||
#[derive(Clone, Coding)]
|
||||
pub struct AtomData(pub Vec<u8>);
|
||||
impl fmt::Debug for AtomData {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut byte_strings = self.0.iter().map(|b| format!("{b:02x}"));
|
||||
if self.0.len() < 32 {
|
||||
write!(f, "AtomData({})", byte_strings.join(" "))
|
||||
} else {
|
||||
let data_table =
|
||||
byte_strings.chunks(32).into_iter().map(|mut chunk| chunk.join(" ")).join("\n");
|
||||
write!(f, "AtomData(\n{}\n)", data_table)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Unique ID associated with atoms that have an identity
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
|
||||
@@ -16,7 +30,7 @@ pub struct AtomId(pub NonZeroU64);
|
||||
|
||||
/// An atom owned by an implied system. Usually used in responses from a system.
|
||||
/// This has the same semantics as [Atom] except in that the owner is implied.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct LocalAtom {
|
||||
pub drop: Option<AtomId>,
|
||||
pub data: AtomData,
|
||||
@@ -27,7 +41,7 @@ impl LocalAtom {
|
||||
|
||||
/// An atom representation that can be serialized and sent around. Atoms
|
||||
/// represent the smallest increment of work.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding)]
|
||||
#[derive(Clone, Debug, Coding)]
|
||||
pub struct Atom {
|
||||
/// Instance ID of the system that created the atom
|
||||
pub owner: SysId,
|
||||
@@ -49,7 +63,7 @@ pub struct Atom {
|
||||
}
|
||||
|
||||
/// Attempt to apply an atom as a function to an expression
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct CallRef(pub Atom, pub ExprTicket);
|
||||
impl Request for CallRef {
|
||||
@@ -59,14 +73,14 @@ impl Request for CallRef {
|
||||
/// Attempt to apply an atom as a function, consuming the atom and enabling the
|
||||
/// library to reuse its datastructures rather than duplicating them. This is an
|
||||
/// optimization over [CallRef] followed by [AtomDrop].
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct FinalCall(pub Atom, pub ExprTicket);
|
||||
impl Request for FinalCall {
|
||||
type Response = Expression;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct SerializeAtom(pub Atom);
|
||||
impl Request for SerializeAtom {
|
||||
@@ -81,14 +95,14 @@ impl Request for DeserAtom {
|
||||
}
|
||||
|
||||
/// A request blindly routed to the system that provides an atom.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct Fwded(pub Atom, pub TStrv, pub Vec<u8>);
|
||||
impl Request for Fwded {
|
||||
type Response = Option<Vec<u8>>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(ExtHostReq)]
|
||||
pub struct Fwd(pub Atom, pub TStrv, pub Vec<u8>);
|
||||
impl Request for Fwd {
|
||||
@@ -100,7 +114,7 @@ pub enum NextStep {
|
||||
Continue(Expression),
|
||||
Halt,
|
||||
}
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct Command(pub Atom);
|
||||
impl Request for Command {
|
||||
@@ -111,17 +125,20 @@ impl Request for Command {
|
||||
/// isn't referenced anywhere. This should have no effect if the atom's `drop`
|
||||
/// flag is false.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[extends(HostExtNotif)]
|
||||
#[extends(HostExtReq)]
|
||||
pub struct AtomDrop(pub SysId, pub AtomId);
|
||||
impl Request for AtomDrop {
|
||||
type Response = ();
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(AtomReq, HostExtReq)]
|
||||
pub struct AtomPrint(pub Atom);
|
||||
impl Request for AtomPrint {
|
||||
type Response = FormattingUnit;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(ExtHostReq)]
|
||||
pub struct ExtAtomPrint(pub Atom);
|
||||
impl Request for ExtAtomPrint {
|
||||
@@ -129,7 +146,7 @@ impl Request for ExtAtomPrint {
|
||||
}
|
||||
|
||||
/// Requests that apply to an existing atom instance
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
|
||||
#[derive(Clone, Debug, Coding, Hierarchy)]
|
||||
#[extends(HostExtReq)]
|
||||
#[extendable]
|
||||
pub enum AtomReq {
|
||||
|
||||
Reference in New Issue
Block a user