Added untested comm impl

This commit is contained in:
2025-12-11 16:25:46 +01:00
parent 4e4dc381ea
commit d211f3127d
14 changed files with 613 additions and 61 deletions

View File

@@ -3,7 +3,7 @@ use std::future::Future;
use std::mem;
use std::num::NonZero;
use std::pin::Pin;
use std::rc::Rc;
use std::rc::{Rc, Weak};
use futures::channel::mpsc::{Receiver, Sender, channel};
use futures::future::{LocalBoxFuture, join_all};
@@ -21,7 +21,7 @@ use orchid_base::interner::{Interner, Tok};
use orchid_base::logging::Logger;
use orchid_base::name::Sym;
use orchid_base::parse::{Comment, Snippet};
use orchid_base::reqnot::{ReqNot, RequestHandle, Requester};
use orchid_base::reqnot::{ReqNot, ReqReader, Requester};
use orchid_base::tree::{TokenVariant, ttv_from_api};
use substack::Substack;
use trait_set::trait_set;
@@ -37,7 +37,29 @@ use crate::system::atom_by_idx;
use crate::system_ctor::{CtedObj, DynSystemCtor};
use crate::tree::{LazyMemberFactory, TreeIntoApiCtxImpl};
pub type ExtReq<'a> = RequestHandle<'a, api::ExtMsgSet>;
task_local::task_local! {
static CLIENT: Rc<dyn Client>;
}
fn get_client() -> Rc<dyn Client> {
CLIENT.with(|c| c.expect("Client not set, not running inside a duplex reqnot channel!").clone())
}
/// Sent the client used for global [request] and [notify] functions within the
/// runtime of this future
pub async fn with_client<F: Future>(c: Rc<dyn Client>, fut: F) -> F::Output {
CLIENT.scope(c, fut).await
}
/// Send a request through the global client's [ClientExt::request]
pub async fn request<T: Request + UnderRoot<Root: Encode>>(t: T) -> T::Response {
get_client().request(t).await
}
/// Send a notification through the global client's [ClientExt::notify]
pub async fn notify<T: UnderRoot<Root: Encode> + 'static>(t: T) { get_client().notify(t).await }
pub type ExtReq<'a> = ReqReader<'a, api::ExtMsgSet>;
pub type ExtReqNot = ReqNot<api::ExtMsgSet>;
pub struct ExtensionData {
@@ -177,8 +199,7 @@ pub fn extension_init(
})
.await,
api::HostExtReq::Ping(ping @ api::Ping) => hand.handle(&ping, &()).await,
api::HostExtReq::Sweep(sweep @ api::Sweep) =>
hand.handle(&sweep, &interner.sweep_replica().await).await,
api::HostExtReq::Sweep(api::Sweep) => todo!(),
api::HostExtReq::SysReq(api::SysReq::NewSystem(new_sys)) => {
let (sys_id, _) = (decls.iter().enumerate().find(|(_, s)| s.id == new_sys.system))
.expect("NewSystem call received for invalid system");

View File

@@ -0,0 +1,73 @@
use std::borrow::Borrow;
use std::cell::RefCell;
use std::fmt::Debug;
use std::hash::Hash;
use std::rc::{Rc, Weak};
use hashbrown::HashMap;
use orchid_api_traits::Coding;
use orchid_base::interner::{IStr, IStrHandle, IStrv, IStrvHandle};
use crate::api;
trait Branch: 'static {
type Token: Clone + Copy + Debug + Hash + PartialEq + Eq + PartialOrd + Ord + Coding + 'static;
type Data: 'static + Borrow<Self::Borrow>;
type Borrow: ToOwned<Owned = Self::Data> + ?Sized;
type Handle: AsRef<Self::Borrow>;
type Interned: Clone;
fn mk_interned(t: Self::Token, h: Rc<Self::Handle>) -> Self::Interned;
}
struct StrBranch;
impl Branch for StrBranch {
type Data = String;
type Token = api::TStr;
type Borrow = str;
type Handle = Handle<Self>;
type Interned = IStr;
fn mk_interned(t: Self::Token, h: Rc<Self::Handle>) -> Self::Interned { IStr(t, h) }
}
struct StrvBranch;
impl Branch for StrvBranch {
type Data = Vec<IStr>;
type Token = api::TStrv;
type Borrow = [IStr];
type Handle = Handle<Self>;
type Interned = IStrv;
fn mk_interned(t: Self::Token, h: Rc<Self::Handle>) -> Self::Interned { IStrv(t, h) }
}
struct Data<B: Branch> {
token: B::Token,
data: Rc<B::Data>,
}
struct Handle<B: Branch> {
data: Rc<Data<B>>,
parent: Weak<RefCell<IntData<B>>>,
}
impl IStrHandle for Handle<StrBranch> {}
impl AsRef<str> for Handle<StrBranch> {
fn as_ref(&self) -> &str { self.data.data.as_ref().as_ref() }
}
impl IStrvHandle for Handle<StrvBranch> {}
impl AsRef<[IStr]> for Handle<StrvBranch> {
fn as_ref(&self) -> &[IStr] { self.data.data.as_ref().as_ref() }
}
struct Rec<B: Branch> {
handle: Weak<B::Handle>,
data: Rc<Data<B>>,
}
struct IntData<B: Branch> {
by_tok: HashMap<B::Token, Rec<B>>,
by_data: HashMap<Rc<B::Data>, Rec<B>>,
}
impl<B: Branch> IntData<B> {
async fn i(&mut self, q: &B::Borrow) -> B::Interned { todo!() }
async fn e(&mut self, q: &B::Token) -> B::Interned { todo!() }
}
struct Int<B: Branch>(Rc<RefCell<IntData<B>>>);

View File

@@ -12,6 +12,7 @@ pub mod gen_expr;
pub mod lexer;
// pub mod msg;
pub mod context;
pub mod interner;
pub mod other_system;
pub mod parser;
pub mod reflection;