forked from Orchid/orchid
Initial extension asynchronization efforts.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use std::future::Future;
|
||||
|
||||
use orchid_base::error::{OrcErr, OrcRes, mk_err};
|
||||
use orchid_base::intern;
|
||||
use orchid_base::interner::Interner;
|
||||
use orchid_base::location::Pos;
|
||||
|
||||
use crate::atom::{AtomicFeatures, ToAtom, TypAtom};
|
||||
use crate::expr::{Expr, atom, bot};
|
||||
use crate::expr::Expr;
|
||||
use crate::gen_expr::{GExpr, atom, bot};
|
||||
use crate::system::downcast_atom;
|
||||
|
||||
pub trait TryFromExpr: Sized {
|
||||
@@ -22,38 +23,39 @@ impl<T: TryFromExpr, U: TryFromExpr> TryFromExpr for (T, U) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn err_not_atom(pos: Pos) -> OrcErr {
|
||||
mk_err(intern!(str: "Expected an atom").await, "This expression is not an atom", [pos.into()])
|
||||
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_type(pos: Pos) -> OrcErr {
|
||||
mk_err(intern!(str: "Type error").await, "The atom is a different type than expected", [
|
||||
pos.into()
|
||||
])
|
||||
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()])
|
||||
}
|
||||
|
||||
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()).await.into()),
|
||||
Err(ex) => Err(err_not_atom(ex.data().await.pos.clone(), &ex.ctx().i).await.into()),
|
||||
Ok(f) => match downcast_atom(f) {
|
||||
Ok(a) => Ok(a),
|
||||
Err(f) => Err(err_type(f.pos).await.into()),
|
||||
Err(f) => Err(err_type(f.pos(), &f.ctx().i).await.into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToExpr {
|
||||
fn to_expr(self) -> Expr;
|
||||
fn to_expr(self) -> GExpr;
|
||||
}
|
||||
|
||||
impl ToExpr for GExpr {
|
||||
fn to_expr(self) -> GExpr { self }
|
||||
}
|
||||
impl ToExpr for Expr {
|
||||
fn to_expr(self) -> Expr { self }
|
||||
fn to_expr(self) -> GExpr { self.gen() }
|
||||
}
|
||||
|
||||
impl<T: ToExpr> ToExpr for OrcRes<T> {
|
||||
fn to_expr(self) -> Expr {
|
||||
fn to_expr(self) -> GExpr {
|
||||
match self {
|
||||
Err(e) => bot(e),
|
||||
Ok(t) => t.to_expr(),
|
||||
@@ -62,5 +64,5 @@ impl<T: ToExpr> ToExpr for OrcRes<T> {
|
||||
}
|
||||
|
||||
impl<A: ToAtom> ToExpr for A {
|
||||
fn to_expr(self) -> Expr { atom(self) }
|
||||
fn to_expr(self) -> GExpr { atom(self) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user