Files
orchid/orchid-std/src/std/reflection/sym_atom.rs
Lawrence Bethlenfalvy 32d6237dc5 task_local context over context objects
- interner impls logically separate from API in orchid-base (default host interner still in base for testing)
- error reporting, logging, and a variety of other features passed down via context in extension, not yet in host to maintain library-ish profile, should consider options
- no global spawn mechanic, the host has a spawn function but extensions only get a stash for enqueuing async work in sync callbacks which is then explicitly, manually, and with strict order popped and awaited
- still deadlocks nondeterministically for some ungodly reason
2026-01-01 14:54:29 +00:00

68 lines
2.0 KiB
Rust

use std::borrow::Cow;
use orchid_api::TStrv;
use orchid_api_derive::{Coding, Hierarchy};
use orchid_api_traits::Request;
use orchid_base::error::mk_errv;
use orchid_base::interner::{es, is};
use orchid_base::name::{NameLike, Sym};
use orchid_extension::atom::{Atomic, Supports, TAtom};
use orchid_extension::atom_owned::{OwnedAtom, OwnedVariant, own};
use orchid_extension::expr::{Expr, ExprHandle};
use orchid_extension::system::dep_req;
use orchid_extension::tree::{GenMember, fun, prefix};
use crate::std::std_system::StdReq;
use crate::std::string::str_atom::IntStrAtom;
use crate::std::string::to_string::ToStringMethod;
use crate::{HomoTpl, StdSystem, api};
#[derive(Clone, Coding)]
pub struct SymAtomData(pub api::TStrv);
#[derive(Clone)]
pub struct SymAtom(pub(crate) Sym);
impl Atomic for SymAtom {
type Data = SymAtomData;
type Variant = OwnedVariant;
}
impl OwnedAtom for SymAtom {
type Refs = ();
async fn val(&self) -> Cow<'_, Self::Data> { Cow::Owned(SymAtomData(self.0.tok().to_api())) }
}
impl Supports<ToStringMethod> for SymAtom {
async fn handle(&self, _: ToStringMethod) -> <ToStringMethod as Request>::Response {
self.0.to_string()
}
}
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(StdReq)]
pub struct CreateSymAtom(pub TStrv);
impl Request for CreateSymAtom {
type Response = api::ExprTicket;
}
pub async fn sym_expr(sym: Sym) -> Expr {
Expr::from_handle(ExprHandle::deserialize(
dep_req::<StdSystem, _>(CreateSymAtom(sym.to_api())).await,
))
}
pub async fn gen_sym_lib() -> Vec<GenMember> {
prefix("std::refl::sym", [
fun(true, "from_str", async move |str: TAtom<IntStrAtom>| {
match Sym::parse(&es(*str).await).await {
Ok(sym) => Ok(SymAtom(sym)),
Err(_) => Err(mk_errv(
is("Cannot parse sym from empty string").await,
"Empty string passed to std::refl::sym::from_str",
[str.pos()],
)),
}
}),
fun(true, "to_tpl", async move |sym: TAtom<SymAtom>| {
HomoTpl(own(&sym).await.0.segs().map(IntStrAtom).collect())
}),
])
}