forked from Orchid/orchid
exec working up to halt
clean shutdown doesn't for some reason
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
//! #TODO: redefine this in terms of [crate::coroutine_exec::exec]. Try
|
||||
//! differentiating between eager and lazy arguments. [ExprFunc] can remain with
|
||||
//! tweaks but other techniques probably must go.
|
||||
//!
|
||||
//! Notice also that Func must still be resumable
|
||||
use std::any::TypeId;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
@@ -48,11 +43,14 @@ struct FunRecord {
|
||||
fun: Rc<dyn FunCB>,
|
||||
}
|
||||
|
||||
async fn process_args<I, O, F: ExprFunc<I, O>>(f: F) -> FunRecord {
|
||||
async fn process_args<I, O, F: ExprFunc<I, O>>(
|
||||
debug: impl AsRef<str> + Clone + 'static,
|
||||
f: F,
|
||||
) -> FunRecord {
|
||||
let argtyps = F::argtyps();
|
||||
let fun = Rc::new(move |v: Vec<Expr>| {
|
||||
clone!(f, v mut);
|
||||
exec(async move |mut hand| {
|
||||
exec(debug.clone(), async move |mut hand| {
|
||||
let mut norm_args = Vec::with_capacity(v.len());
|
||||
for (expr, typ) in v.into_iter().zip(argtyps) {
|
||||
if *typ != TypeId::of::<Expr>() {
|
||||
@@ -85,7 +83,7 @@ impl Fun {
|
||||
let record = if let Some(record) = fung.get(&path) {
|
||||
record.clone()
|
||||
} else {
|
||||
let record = process_args(f).await;
|
||||
let record = process_args(path.to_string(), f).await;
|
||||
fung.insert(path.clone(), record.clone());
|
||||
record
|
||||
};
|
||||
@@ -101,7 +99,6 @@ impl OwnedAtom for Fun {
|
||||
type Refs = Vec<Expr>;
|
||||
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(()) }
|
||||
async fn call_ref(&self, arg: Expr) -> GExpr {
|
||||
std::io::Write::flush(&mut std::io::stderr()).unwrap();
|
||||
let new_args = self.args.iter().cloned().chain([arg]).collect_vec();
|
||||
if new_args.len() == self.record.argtyps.len() {
|
||||
(self.record.fun)(new_args).await.to_expr().await
|
||||
@@ -137,8 +134,11 @@ pub struct Lambda {
|
||||
record: FunRecord,
|
||||
}
|
||||
impl Lambda {
|
||||
pub async fn new<I, O, F: ExprFunc<I, O>>(f: F) -> Self {
|
||||
Self { args: vec![], record: process_args(f).await }
|
||||
pub async fn new<I, O, F: ExprFunc<I, O>>(
|
||||
debug: impl AsRef<str> + Clone + 'static,
|
||||
f: F,
|
||||
) -> Self {
|
||||
Self { args: vec![], record: process_args(debug, f).await }
|
||||
}
|
||||
}
|
||||
impl Atomic for Lambda {
|
||||
|
||||
Reference in New Issue
Block a user