exec working up to halt
clean shutdown doesn't for some reason
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use std::num::NonZero;
|
||||
use std::rc::Rc;
|
||||
|
||||
use async_fn_stream::stream;
|
||||
use dyn_clone::{DynClone, clone_box};
|
||||
@@ -18,9 +17,9 @@ use trait_set::trait_set;
|
||||
use crate::api;
|
||||
use crate::conv::ToExpr;
|
||||
use crate::entrypoint::MemberRecord;
|
||||
use crate::expr::{Expr, ExprHandle};
|
||||
use crate::expr::{BorrowedExprStore, Expr, ExprHandle};
|
||||
use crate::func_atom::{ExprFunc, Fun};
|
||||
use crate::gen_expr::{GExpr, arg, call, lambda, seq, sym_ref};
|
||||
use crate::gen_expr::{GExpr, sym_ref};
|
||||
use crate::system::SysCtx;
|
||||
|
||||
pub type GenTokTree = TokTree<Expr, GExpr>;
|
||||
@@ -43,26 +42,18 @@ impl TokenVariant<api::Expression> for GExpr {
|
||||
}
|
||||
|
||||
impl TokenVariant<api::ExprTicket> for Expr {
|
||||
type FromApiCtx<'a> = SysCtx;
|
||||
type FromApiCtx<'a> = (SysCtx, &'a BorrowedExprStore);
|
||||
async fn from_api(
|
||||
api: &api::ExprTicket,
|
||||
ctx: &mut Self::FromApiCtx<'_>,
|
||||
(ctx, exprs): &mut Self::FromApiCtx<'_>,
|
||||
_: SrcRange,
|
||||
_: &Interner,
|
||||
) -> Self {
|
||||
// SAFETY: receiving trees from sublexers implies ownership transfer
|
||||
Expr::from_handle(Rc::new(unsafe { ExprHandle::from_args(ctx.clone(), *api) }))
|
||||
// SAFETY: receiving trees from sublexers implies borrowing
|
||||
Expr::from_handle(ExprHandle::borrowed(ctx.clone(), *api, exprs))
|
||||
}
|
||||
type ToApiCtx<'a> = ();
|
||||
async fn into_api(self, (): &mut Self::ToApiCtx<'_>) -> api::ExprTicket {
|
||||
let hand = self.handle();
|
||||
std::mem::drop(self);
|
||||
let h = match Rc::try_unwrap(hand) {
|
||||
Ok(h) => h,
|
||||
Err(h) => h.as_ref().clone().await,
|
||||
};
|
||||
h.into_tk()
|
||||
}
|
||||
async fn into_api(self, (): &mut Self::ToApiCtx<'_>) -> api::ExprTicket { self.handle().tk }
|
||||
}
|
||||
|
||||
pub async fn x_tok(x: impl ToExpr) -> GenTok { GenTok::NewExpr(x.to_expr().await) }
|
||||
@@ -96,19 +87,9 @@ pub fn root_mod(name: &str, mems: impl IntoIterator<Item = Vec<GenMember>>) -> (
|
||||
(name.to_string(), kind)
|
||||
}
|
||||
pub fn fun<I, O>(public: bool, name: &str, xf: impl ExprFunc<I, O>) -> Vec<GenMember> {
|
||||
let fac =
|
||||
LazyMemberFactory::new(move |sym, ctx| async {
|
||||
return MemKind::Const(build_lambdas(Fun::new(sym, ctx, xf).await, 0).await);
|
||||
async fn build_lambdas(fun: Fun, i: u64) -> GExpr {
|
||||
if i < fun.arity().into() {
|
||||
return lambda(i, [build_lambdas(fun, i + 1).boxed_local().await]);
|
||||
}
|
||||
let arity = fun.arity();
|
||||
seq((0..arity).map(|i| arg(i as u64)).chain([call(
|
||||
[fun.to_expr().await].into_iter().chain((0..arity).map(|i| arg(i as u64))),
|
||||
)]))
|
||||
}
|
||||
});
|
||||
let fac = LazyMemberFactory::new(async move |sym, ctx| {
|
||||
MemKind::Const(Fun::new(sym, ctx, xf).await.to_expr().await)
|
||||
});
|
||||
vec![GenMember { name: name.to_string(), kind: MemKind::Lazy(fac), public, comments: vec![] }]
|
||||
}
|
||||
pub fn prefix(path: &str, items: impl IntoIterator<Item = Vec<GenMember>>) -> Vec<GenMember> {
|
||||
|
||||
Reference in New Issue
Block a user