orchid-base moved to async

This commit is contained in:
2025-01-15 11:32:37 +01:00
parent f1f49bab8e
commit 3a76513638
16 changed files with 370 additions and 279 deletions

View File

@@ -89,12 +89,13 @@ impl ForeignAtom<'static> {
pub(crate) fn new(handle: Arc<ExprHandle>, atom: api::Atom, pos: Pos) -> Self {
ForeignAtom { _life: PhantomData, atom, ctx: handle.ctx.clone(), expr: Some(handle), pos }
}
pub fn request<M: AtomMethod>(&self, m: M) -> Option<M::Response> {
let rep = self.ctx.reqnot.request(api::Fwd(
pub async fn request<M: AtomMethod>(&self, m: M) -> Option<M::Response> {
let rep = (self.ctx.reqnot.request(api::Fwd(
self.atom.clone(),
Sym::parse(M::NAME).unwrap().tok().to_api(),
Sym::parse(M::NAME).await.unwrap().tok().to_api(),
enc_vec(&m),
))?;
)))
.await?;
Some(M::Response::decode(&mut &rep[..]))
}
}
@@ -116,9 +117,9 @@ impl AtomRepr for ForeignAtom<'_> {
pub struct NotTypAtom(pub Pos, pub Expr, pub Box<dyn AtomDynfo>);
impl NotTypAtom {
pub fn mk_err(&self) -> OrcErr {
pub async fn mk_err(&self) -> OrcErr {
mk_err(
intern!(str: "Not the expected type"),
intern!(str: "Not the expected type").await,
format!("This expression is not a {}", self.2.name()),
[self.0.clone().into()],
)
@@ -147,10 +148,10 @@ pub struct MethodSet<A: AtomCard> {
impl<A: AtomCard> MethodSet<A> {
pub fn new() -> Self { Self { handlers: vec![] } }
pub fn handle<M: AtomMethod>(mut self) -> Self
pub async fn handle<M: AtomMethod>(mut self) -> Self
where A: Supports<M> {
self.handlers.push(AtomReqHandler {
key: Sym::parse(M::NAME).expect("AtomMethod::NAME cannoot be empty"),
key: Sym::parse(M::NAME).await.expect("AtomMethod::NAME cannoot be empty"),
cb: Box::new(move |a: &A, ctx: SysCtx, req: &mut dyn Read, rep: &mut dyn Write| {
Supports::<M>::handle(a, ctx, M::decode(req)).encode(rep);
}),
@@ -197,19 +198,16 @@ impl<A: AtomicFeatures> TypAtom<'static, A> {
}
}
impl<A: AtomicFeatures> TypAtom<'_, A> {
pub fn request<M: AtomMethod>(&self, req: M) -> M::Response
pub async fn request<M: AtomMethod>(&self, req: M) -> M::Response
where A: Supports<M> {
M::Response::decode(
&mut &self
.data
.ctx
.reqnot
.request(api::Fwd(
self.data.atom.clone(),
Sym::parse(M::NAME).unwrap().tok().to_api(),
enc_vec(&req),
))
.unwrap()[..],
&mut &(self.data.ctx.reqnot.request(api::Fwd(
self.data.atom.clone(),
Sym::parse(M::NAME).await.unwrap().tok().to_api(),
enc_vec(&req),
)))
.await
.unwrap()[..],
)
}
}
@@ -255,10 +253,11 @@ impl fmt::Display for AtomFactory {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "AtomFactory") }
}
pub fn err_not_callable() -> OrcErr {
mk_err(intern!(str: "This atom is not callable"), "Attempted to apply value as function", [])
pub async fn err_not_callable() -> OrcErr {
mk_err(intern!(str: "This atom is not callable").await, "Attempted to apply value as function", [
])
}
pub fn err_not_command() -> OrcErr {
mk_err(intern!(str: "This atom is not a command"), "Settled on an inactionable value", [])
pub async fn err_not_command() -> OrcErr {
mk_err(intern!(str: "This atom is not a command").await, "Settled on an inactionable value", [])
}

View File

@@ -20,12 +20,14 @@ impl<T: TryFromExpr, U: TryFromExpr> TryFromExpr for (T, U) {
}
}
fn err_not_atom(pos: Pos) -> OrcErr {
mk_err(intern!(str: "Expected an atom"), "This expression is not an atom", [pos.into()])
async fn err_not_atom(pos: Pos) -> OrcErr {
mk_err(intern!(str: "Expected an atom").await, "This expression is not an atom", [pos.into()])
}
fn err_type(pos: Pos) -> OrcErr {
mk_err(intern!(str: "Type error"), "The atom is a different type than expected", [pos.into()])
async fn err_type(pos: Pos) -> OrcErr {
mk_err(intern!(str: "Type error").await, "The atom is a different type than expected", [
pos.into()
])
}
impl<A: AtomicFeatures> TryFromExpr for TypAtom<'_, A> {

View File

@@ -29,7 +29,7 @@ use crate::system::{SysCtx, atom_by_idx};
use crate::system_ctor::{CtedObj, DynSystemCtor};
use crate::tree::{GenTok, GenTokTree, LazyMemberFactory, TIACtxImpl, do_extra};
pub type ExtReq = RequestHandle<api::ExtMsgSet>;
pub type ExtReq<'a> = RequestHandle<'a, api::ExtMsgSet>;
pub type ExtReqNot = ReqNot<api::ExtMsgSet>;
pub struct ExtensionData {

View File

@@ -10,18 +10,20 @@ use orchid_base::tree::TokHandle;
use crate::api;
use crate::tree::{GenTok, GenTokTree};
pub fn err_cascade() -> OrcErr {
pub async fn err_cascade() -> OrcErr {
mk_err(
intern!(str: "An error cascading from a recursive call"),
"This error should not surface. If you are seeing it, something is wrong",
intern!(str: "An error cascading from a recursive call").await,
"This error is a sentinel for the extension library.\
it should not be emitted by the extension.",
[Pos::None.into()],
)
}
pub fn err_not_applicable() -> OrcErr {
pub async fn err_not_applicable() -> OrcErr {
mk_err(
intern!(str: "Pseudo-error to communicate that the current branch in a dispatch doesn't apply"),
&*err_cascade().message,
intern!(str: "Pseudo-error to communicate that the current branch in a dispatch doesn't apply")
.await,
&*err_cascade().await.message,
[Pos::None.into()],
)
}