Added support for defining macros in Rust within the macro system

Also fixed a lot of bugs
This commit is contained in:
2025-09-30 21:23:16 +02:00
parent 7971a2b4eb
commit b77653f841
52 changed files with 849 additions and 502 deletions

View File

@@ -1,11 +1,14 @@
use std::future::Future;
use std::pin::Pin;
use dyn_clone::DynClone;
use never::Never;
use orchid_base::error::{OrcErrv, OrcRes, mk_errv};
use orchid_base::interner::Interner;
use orchid_base::location::Pos;
use trait_set::trait_set;
use crate::atom::{AtomicFeatures, ForeignAtom, ToAtom, TypAtom};
use crate::atom::{AtomicFeatures, ForeignAtom, TAtom, ToAtom};
use crate::expr::Expr;
use crate::gen_expr::{GExpr, atom, bot};
use crate::system::{SysCtx, downcast_atom};
@@ -41,7 +44,7 @@ impl TryFromExpr for ForeignAtom {
}
}
impl<A: AtomicFeatures> TryFromExpr for TypAtom<A> {
impl<A: AtomicFeatures> TryFromExpr for TAtom<A> {
async fn try_from_expr(expr: Expr) -> OrcRes<Self> {
let f = ForeignAtom::try_from_expr(expr).await?;
match downcast_atom::<A>(f).await {
@@ -59,6 +62,29 @@ pub trait ToExpr {
fn to_expr(self) -> impl Future<Output = GExpr>;
}
pub trait ToExprDyn {
fn to_expr_dyn<'a>(self: Box<Self>) -> Pin<Box<dyn Future<Output = GExpr> + 'a>>
where Self: 'a;
}
impl<T: ToExpr> ToExprDyn for T {
fn to_expr_dyn<'a>(self: Box<Self>) -> Pin<Box<dyn Future<Output = GExpr> + 'a>>
where Self: 'a {
Box::pin(self.to_expr())
}
}
trait_set! {
pub trait ClonableToExprDyn = ToExprDyn + DynClone;
}
impl ToExpr for Box<dyn ToExprDyn> {
async fn to_expr(self) -> GExpr { self.to_expr_dyn().await }
}
impl ToExpr for Box<dyn ClonableToExprDyn> {
async fn to_expr(self) -> GExpr { self.to_expr_dyn().await }
}
impl Clone for Box<dyn ClonableToExprDyn> {
fn clone(&self) -> Self { dyn_clone::clone_box(&**self) }
}
impl ToExpr for GExpr {
async fn to_expr(self) -> GExpr { self }
}