lex_hello worked for a second just now
this is just a backup however
This commit is contained in:
@@ -148,7 +148,7 @@ pub trait AtomMethod: Request {
|
||||
const NAME: &str;
|
||||
}
|
||||
pub trait Supports<M: AtomMethod>: AtomCard {
|
||||
fn handle(&self, ctx: SysCtx, req: M) -> LocalBoxFuture<'_, <M as Request>::Response>;
|
||||
fn handle(&self, ctx: SysCtx, req: M) -> impl Future<Output = <M as Request>::Response>;
|
||||
}
|
||||
|
||||
trait_set! {
|
||||
|
||||
@@ -144,8 +144,8 @@ impl<T: OwnedAtom> AtomDynfo for OwnedAtomDynfo<T> {
|
||||
pub trait DeserializeCtx: Sized {
|
||||
fn read<T: Decode>(&mut self) -> impl Future<Output = T>;
|
||||
fn is_empty(&self) -> bool;
|
||||
fn assert_empty(self) { assert!(self.is_empty(), "Bytes found after decoding") }
|
||||
fn decode<T: Decode>(mut self) -> impl Future<Output = T> {
|
||||
fn assert_empty(&self) { assert!(self.is_empty(), "Bytes found after decoding") }
|
||||
fn decode<T: Decode>(&mut self) -> impl Future<Output = T> {
|
||||
async {
|
||||
let t = self.read().await;
|
||||
self.assert_empty();
|
||||
|
||||
@@ -18,7 +18,7 @@ use hashbrown::HashMap;
|
||||
use itertools::Itertools;
|
||||
use orchid_api::ApplyMacro;
|
||||
use orchid_api_traits::{Decode, Encode, enc_vec};
|
||||
use orchid_base::builtin::ExtPort;
|
||||
use orchid_base::builtin::{ExtPort, Spawner};
|
||||
use orchid_base::char_filter::{char_filter_match, char_filter_union, mk_char_filter};
|
||||
use orchid_base::clone;
|
||||
use orchid_base::interner::{Interner, Tok};
|
||||
@@ -127,7 +127,7 @@ impl ExtPort for ExtensionOwner {
|
||||
}
|
||||
}
|
||||
|
||||
async fn extension_main_logic(data: ExtensionData, spawner: Rc<dyn LocalSpawn>) {
|
||||
pub async fn extension_main_logic(data: ExtensionData, spawner: Spawner) {
|
||||
let api::HostHeader { log_strategy } =
|
||||
api::HostHeader::decode(Pin::new(&mut async_std::io::stdin())).await;
|
||||
let mut buf = Vec::new();
|
||||
@@ -142,7 +142,7 @@ async fn extension_main_logic(data: ExtensionData, spawner: Rc<dyn LocalSpawn>)
|
||||
std::io::stdout().write_all(&buf).unwrap();
|
||||
std::io::stdout().flush().unwrap();
|
||||
let exiting = Arc::new(AtomicBool::new(false));
|
||||
let logger = Arc::new(Logger::new(log_strategy));
|
||||
let logger = Logger::new(log_strategy);
|
||||
let interner_cell = Rc::new(RefCell::new(None::<Rc<Interner>>));
|
||||
let interner_weak = Rc::downgrade(&interner_cell);
|
||||
let obj_store = ObjStore::default();
|
||||
@@ -159,10 +159,8 @@ async fn extension_main_logic(data: ExtensionData, spawner: Rc<dyn LocalSpawn>)
|
||||
}.boxed_local())
|
||||
});
|
||||
let rn = ReqNot::<api::ExtMsgSet>::new(
|
||||
clone!(logger; move |a, _| clone!(logger; async move {
|
||||
logger.log_buf("Upsending", a);
|
||||
send_parent_msg(a).await.unwrap()
|
||||
}.boxed_local())),
|
||||
logger.clone(),
|
||||
move |a, _| async move { send_parent_msg(a).await.unwrap() }.boxed_local(),
|
||||
clone!(systems, exiting, mk_ctx, obj_store; move |n, reqnot| {
|
||||
clone!(systems, exiting, mk_ctx, obj_store; async move {
|
||||
match n {
|
||||
@@ -209,7 +207,7 @@ async fn extension_main_logic(data: ExtensionData, spawner: Rc<dyn LocalSpawn>)
|
||||
.then(|(k, v)| {
|
||||
let (req, lazy_mems, rules) = (&hand, &lazy_mems, &rules);
|
||||
clone!(i, ctx; async move {
|
||||
let name = i.i::<String>(&k).await.to_api();
|
||||
let name = i.i(&k).await.to_api();
|
||||
let value = v.into_api(&mut TIACtxImpl {
|
||||
lazy_members: &mut *lazy_mems.lock().await,
|
||||
rules: &mut *rules.lock().await,
|
||||
@@ -434,6 +432,6 @@ async fn extension_main_logic(data: ExtensionData, spawner: Rc<dyn LocalSpawn>)
|
||||
*interner_cell.borrow_mut() = Some(Rc::new(Interner::new_replica(rn.clone().map())));
|
||||
while !exiting.load(Ordering::Relaxed) {
|
||||
let rcvd = recv_parent_msg().await.unwrap();
|
||||
rn.receive(&rcvd).await
|
||||
spawner(Box::pin(clone!(rn; async move { rn.receive(&rcvd).await })))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::rc::Rc;
|
||||
|
||||
use async_once_cell::OnceCell;
|
||||
use derive_destructure::destructure;
|
||||
use futures::task::LocalSpawnExt;
|
||||
use orchid_base::error::OrcErrv;
|
||||
use orchid_base::location::Pos;
|
||||
use orchid_base::reqnot::Requester;
|
||||
@@ -34,10 +33,8 @@ impl fmt::Debug for ExprHandle {
|
||||
impl Drop for ExprHandle {
|
||||
fn drop(&mut self) {
|
||||
let notif = api::Release(self.ctx.id, self.tk);
|
||||
let SysCtx { reqnot, spawner, logger, .. } = self.ctx.clone();
|
||||
if let Err(e) = spawner.spawn_local(async move { reqnot.notify(notif).await }) {
|
||||
writeln!(logger, "Failed to schedule notification about resource release: {e}");
|
||||
}
|
||||
let SysCtx { reqnot, spawner, .. } = self.ctx.clone();
|
||||
spawner(Box::pin(async move { reqnot.notify(notif).await }))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ impl OwnedAtom for Fun {
|
||||
self.path.to_api().encode(write).await;
|
||||
self.args.clone()
|
||||
}
|
||||
async fn deserialize(ctx: impl DeserializeCtx, args: Self::Refs) -> Self {
|
||||
async fn deserialize(mut ctx: impl DeserializeCtx, args: Self::Refs) -> Self {
|
||||
let sys = ctx.sys();
|
||||
let path = Sym::from_api(ctx.decode().await, &sys.i).await;
|
||||
let (arity, fun) = FUNS.with(|f| f.clone()).lock().await.get(&path).unwrap().clone();
|
||||
@@ -128,6 +128,8 @@ impl OwnedAtom for Lambda {
|
||||
}
|
||||
|
||||
mod expr_func_derives {
|
||||
use std::future::Future;
|
||||
|
||||
use orchid_base::error::OrcRes;
|
||||
|
||||
use super::ExprFunc;
|
||||
@@ -140,14 +142,14 @@ mod expr_func_derives {
|
||||
paste::paste!{
|
||||
impl<
|
||||
$($t: TryFromExpr, )*
|
||||
Out: ToExpr,
|
||||
Func: Fn($($t,)*) -> Out + Clone + Send + Sync + 'static
|
||||
> ExprFunc<($($t,)*), Out> for Func {
|
||||
Fut: Future<Output: ToExpr>,
|
||||
Func: Fn($($t,)*) -> Fut + Clone + Send + Sync + 'static
|
||||
> ExprFunc<($($t,)*), Fut::Output> for Func {
|
||||
const ARITY: u8 = $arity;
|
||||
async fn apply(&self, v: Vec<Expr>) -> OrcRes<GExpr> {
|
||||
assert_eq!(v.len(), Self::ARITY.into(), "Arity mismatch");
|
||||
let [$([< $t:lower >],)*] = v.try_into().unwrap_or_else(|_| panic!("Checked above"));
|
||||
Ok(self($($t::try_from_expr([< $t:lower >]).await?,)*).to_expr())
|
||||
Ok(self($($t::try_from_expr([< $t:lower >]).await?,)*).await.to_expr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::future::Future;
|
||||
|
||||
use futures::FutureExt;
|
||||
use orchid_base::error::{OrcErr, OrcErrv};
|
||||
use orchid_base::location::Pos;
|
||||
@@ -98,9 +100,9 @@ pub fn bot(ev: impl IntoIterator<Item = OrcErr>) -> GExpr {
|
||||
inherit(GExprKind::Bottom(OrcErrv::new(ev).unwrap()))
|
||||
}
|
||||
|
||||
pub fn with<I: TryFromExpr, O: ToExpr>(
|
||||
pub fn with<I: TryFromExpr, Fut: Future<Output: ToExpr>>(
|
||||
expr: GExpr,
|
||||
cont: impl Fn(I) -> O + Clone + Send + Sync + 'static,
|
||||
cont: impl Fn(I) -> Fut + Clone + Send + Sync + 'static,
|
||||
) -> GExpr {
|
||||
call([lambda(0, [seq([arg(0), call([Lambda::new(cont).to_expr(), arg(0)])])]), expr])
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
use std::pin::pin;
|
||||
|
||||
use async_std::io;
|
||||
use async_once_cell::OnceCell;
|
||||
use async_std::io::{self, Stdout};
|
||||
use async_std::sync::Mutex;
|
||||
use orchid_base::msg::{recv_msg, send_msg};
|
||||
|
||||
static STDOUT: OnceCell<Mutex<Stdout>> = OnceCell::new();
|
||||
|
||||
pub async fn send_parent_msg(msg: &[u8]) -> io::Result<()> {
|
||||
send_msg(pin!(io::stdout()), msg).await
|
||||
let stdout_lk = STDOUT.get_or_init(async { Mutex::new(io::stdout()) }).await;
|
||||
let mut stdout_g = stdout_lk.lock().await;
|
||||
send_msg(pin!(&mut *stdout_g), msg).await
|
||||
}
|
||||
pub async fn recv_parent_msg() -> io::Result<Vec<u8>> { recv_msg(pin!(io::stdin())).await }
|
||||
|
||||
@@ -4,13 +4,12 @@ use std::future::Future;
|
||||
use std::num::NonZero;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::future::LocalBoxFuture;
|
||||
use futures::task::LocalSpawn;
|
||||
use hashbrown::HashMap;
|
||||
use orchid_api_traits::{Coding, Decode};
|
||||
use orchid_base::boxed_iter::BoxedIter;
|
||||
use orchid_base::builtin::Spawner;
|
||||
use orchid_base::interner::Interner;
|
||||
use orchid_base::logging::Logger;
|
||||
use orchid_base::reqnot::{Receipt, ReqNot};
|
||||
@@ -133,10 +132,10 @@ where A: AtomicFeatures {
|
||||
#[derive(Clone)]
|
||||
pub struct SysCtx {
|
||||
pub reqnot: ReqNot<api::ExtMsgSet>,
|
||||
pub spawner: Rc<dyn LocalSpawn>,
|
||||
pub spawner: Spawner,
|
||||
pub id: api::SysId,
|
||||
pub cted: CtedObj,
|
||||
pub logger: Arc<Logger>,
|
||||
pub logger: Logger,
|
||||
pub obj_store: ObjStore,
|
||||
pub i: Rc<Interner>,
|
||||
}
|
||||
|
||||
@@ -71,16 +71,16 @@ impl GenItem {
|
||||
pub fn cnst(public: bool, name: &str, value: impl ToExpr) -> Vec<GenItem> {
|
||||
with_export(GenMember { name: name.to_string(), kind: MemKind::Const(value.to_expr()) }, public)
|
||||
}
|
||||
pub async fn module(
|
||||
pub fn module(
|
||||
public: bool,
|
||||
name: &str,
|
||||
imports: impl IntoIterator<Item = Sym>,
|
||||
items: impl IntoIterator<Item = Vec<GenItem>>,
|
||||
) -> Vec<GenItem> {
|
||||
let (name, kind) = root_mod(name, imports, items).await;
|
||||
let (name, kind) = root_mod(name, imports, items);
|
||||
with_export(GenMember { name, kind }, public)
|
||||
}
|
||||
pub async fn root_mod(
|
||||
pub fn root_mod(
|
||||
name: &str,
|
||||
imports: impl IntoIterator<Item = Sym>,
|
||||
items: impl IntoIterator<Item = Vec<GenItem>>,
|
||||
@@ -91,7 +91,7 @@ pub async fn root_mod(
|
||||
};
|
||||
(name.to_string(), kind)
|
||||
}
|
||||
pub async fn fun<I, O>(exported: bool, name: &str, xf: impl ExprFunc<I, O>) -> Vec<GenItem> {
|
||||
pub fn fun<I, O>(exported: bool, name: &str, xf: impl ExprFunc<I, O>) -> Vec<GenItem> {
|
||||
let fac =
|
||||
LazyMemberFactory::new(move |sym| async { MemKind::Const(Fun::new(sym, xf).await.to_expr()) });
|
||||
with_export(GenMember { name: name.to_string(), kind: MemKind::Lazy(fac) }, exported)
|
||||
|
||||
Reference in New Issue
Block a user