forked from Orchid/orchid
Macro system done in theory
too afraid to begin debugging, resting for a moment
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use std::future::Future;
|
||||
|
||||
use never::Never;
|
||||
use orchid_base::error::{OrcErr, OrcRes, mk_err};
|
||||
use orchid_base::error::{OrcErrv, OrcRes, mk_errv};
|
||||
use orchid_base::interner::Interner;
|
||||
use orchid_base::location::Pos;
|
||||
|
||||
use crate::atom::{AtomicFeatures, ToAtom, TypAtom};
|
||||
use crate::atom::{AtomicFeatures, ForeignAtom, ToAtom, TypAtom};
|
||||
use crate::expr::Expr;
|
||||
use crate::gen_expr::{GExpr, atom, bot};
|
||||
use crate::system::{SysCtx, downcast_atom};
|
||||
@@ -24,22 +24,29 @@ impl<T: TryFromExpr, U: TryFromExpr> TryFromExpr for (T, U) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn err_not_atom(pos: Pos, i: &Interner) -> OrcErr {
|
||||
mk_err(i.i("Expected an atom").await, "This expression is not an atom", [pos.into()])
|
||||
async fn err_not_atom(pos: Pos, i: &Interner) -> OrcErrv {
|
||||
mk_errv(i.i("Expected an atom").await, "This expression is not an atom", [pos])
|
||||
}
|
||||
|
||||
async fn err_type(pos: Pos, i: &Interner) -> OrcErr {
|
||||
mk_err(i.i("Type error").await, "The atom is a different type than expected", [pos.into()])
|
||||
async fn err_type(pos: Pos, i: &Interner) -> OrcErrv {
|
||||
mk_errv(i.i("Type error").await, "The atom is a different type than expected", [pos])
|
||||
}
|
||||
|
||||
impl TryFromExpr for ForeignAtom {
|
||||
async fn try_from_expr(expr: Expr) -> OrcRes<Self> {
|
||||
match expr.atom().await {
|
||||
Err(ex) => Err(err_not_atom(ex.data().await.pos.clone(), ex.ctx().i()).await),
|
||||
Ok(f) => Ok(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AtomicFeatures> TryFromExpr for TypAtom<A> {
|
||||
async fn try_from_expr(expr: Expr) -> OrcRes<Self> {
|
||||
match expr.atom().await {
|
||||
Err(ex) => Err(err_not_atom(ex.data().await.pos.clone(), ex.ctx().i()).await.into()),
|
||||
Ok(f) => match downcast_atom::<A>(f).await {
|
||||
Ok(a) => Ok(a),
|
||||
Err(f) => Err(err_type(f.pos(), f.ctx().i()).await.into()),
|
||||
},
|
||||
let f = ForeignAtom::try_from_expr(expr).await?;
|
||||
match downcast_atom::<A>(f).await {
|
||||
Ok(a) => Ok(a),
|
||||
Err(f) => Err(err_type(f.pos(), f.ctx().i()).await),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,29 +56,29 @@ impl TryFromExpr for SysCtx {
|
||||
}
|
||||
|
||||
pub trait ToExpr {
|
||||
fn to_expr(self) -> GExpr;
|
||||
fn to_expr(self) -> impl Future<Output = GExpr>;
|
||||
}
|
||||
|
||||
impl ToExpr for GExpr {
|
||||
fn to_expr(self) -> GExpr { self }
|
||||
async fn to_expr(self) -> GExpr { self }
|
||||
}
|
||||
impl ToExpr for Expr {
|
||||
fn to_expr(self) -> GExpr { self.slot() }
|
||||
async fn to_expr(self) -> GExpr { self.slot() }
|
||||
}
|
||||
|
||||
impl<T: ToExpr> ToExpr for OrcRes<T> {
|
||||
fn to_expr(self) -> GExpr {
|
||||
async fn to_expr(self) -> GExpr {
|
||||
match self {
|
||||
Err(e) => bot(e),
|
||||
Ok(t) => t.to_expr(),
|
||||
Ok(t) => t.to_expr().await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: ToAtom> ToExpr for A {
|
||||
fn to_expr(self) -> GExpr { atom(self) }
|
||||
async fn to_expr(self) -> GExpr { atom(self) }
|
||||
}
|
||||
|
||||
impl ToExpr for Never {
|
||||
fn to_expr(self) -> GExpr { match self {} }
|
||||
async fn to_expr(self) -> GExpr { match self {} }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user