forked from Orchid/orchid
October commit
- custom parser support and infra - type-tagging and traits (untested) - match expressions
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
use std::any::Any;
|
||||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
|
||||
use dyn_clone::DynClone;
|
||||
|
||||
use super::ExternError;
|
||||
use super::XfnResult;
|
||||
use crate::ddispatch::request;
|
||||
use crate::error::AssertionError;
|
||||
use crate::interpreted::{ExprInst, TryFromExprInst};
|
||||
use crate::interpreter::{Context, RuntimeError};
|
||||
use crate::representations::interpreted::Clause;
|
||||
use crate::utils::ddispatch::Responder;
|
||||
use crate::{ast, NameLike};
|
||||
|
||||
/// Information returned by [Atomic::run]. This mirrors
|
||||
/// [crate::interpreter::Return] but with a clause instead of an Expr.
|
||||
@@ -77,6 +77,24 @@ where
|
||||
{
|
||||
self.atom_cls().wrap()
|
||||
}
|
||||
|
||||
/// Wrap the atom in a clause to be placed in a [sourcefile::FileEntry].
|
||||
#[must_use]
|
||||
fn ast_cls<N: NameLike>(self) -> ast::Clause<N>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
ast::Clause::Atom(Atom::new(self))
|
||||
}
|
||||
|
||||
/// Wrap the atom in an expression to be placed in a [sourcefile::FileEntry].
|
||||
#[must_use]
|
||||
fn ast_exp<N: NameLike>(self) -> ast::Expr<N>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.ast_cls().into_expr()
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a black box unit of code with its own normalization steps.
|
||||
@@ -129,7 +147,7 @@ impl Debug for Atom {
|
||||
}
|
||||
|
||||
impl TryFromExprInst for Atom {
|
||||
fn from_exi(exi: ExprInst) -> Result<Self, Rc<dyn ExternError>> {
|
||||
fn from_exi(exi: ExprInst) -> XfnResult<Self> {
|
||||
let loc = exi.location();
|
||||
match exi.expr_val().clause {
|
||||
Clause::Atom(a) => Ok(a),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::error::Error;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::hash::Hash;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use dyn_clone::{clone_box, DynClone};
|
||||
|
||||
@@ -9,16 +9,17 @@ use super::XfnResult;
|
||||
use crate::interpreted::ExprInst;
|
||||
use crate::interpreter::Context;
|
||||
use crate::representations::interpreted::Clause;
|
||||
use crate::{ast, NameLike};
|
||||
|
||||
/// Errors produced by external code
|
||||
pub trait ExternError: Display {
|
||||
pub trait ExternError: Display + Send + Sync + DynClone {
|
||||
/// Convert into trait object
|
||||
#[must_use]
|
||||
fn into_extern(self) -> Rc<dyn ExternError>
|
||||
fn into_extern(self) -> Arc<dyn ExternError>
|
||||
where
|
||||
Self: 'static + Sized,
|
||||
{
|
||||
Rc::new(self)
|
||||
Arc::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +52,14 @@ pub trait ExternFn: DynClone + Send {
|
||||
{
|
||||
Clause::ExternFn(ExFn(Box::new(self)))
|
||||
}
|
||||
/// Wrap this function in a clause to be placed in a [FileEntry].
|
||||
#[must_use]
|
||||
fn xfn_ast_cls<N: NameLike>(self) -> ast::Clause<N>
|
||||
where
|
||||
Self: Sized + 'static,
|
||||
{
|
||||
ast::Clause::ExternFn(ExFn(Box::new(self)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for dyn ExternFn {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::atom::StrictEq;
|
||||
use super::{
|
||||
@@ -61,7 +61,7 @@ impl<T, U, F> Param<T, U, F> {
|
||||
/// Wrap a new function in a parametric struct
|
||||
pub fn new(f: F) -> Self
|
||||
where
|
||||
F: FnOnce(T) -> Result<U, Rc<dyn ExternError>>,
|
||||
F: FnOnce(T) -> Result<U, Arc<dyn ExternError>>,
|
||||
{
|
||||
Self { data: f, _t: PhantomData, _u: PhantomData }
|
||||
}
|
||||
@@ -77,7 +77,7 @@ impl<T, U, F: Clone> Clone for Param<T, U, F> {
|
||||
impl<
|
||||
T: 'static + TryFromExprInst,
|
||||
U: 'static + ToClause,
|
||||
F: 'static + Clone + Send + FnOnce(T) -> Result<U, Rc<dyn ExternError>>,
|
||||
F: 'static + Clone + Send + FnOnce(T) -> Result<U, Arc<dyn ExternError>>,
|
||||
> ToClause for Param<T, U, F>
|
||||
{
|
||||
fn to_clause(self) -> Clause { self.xfn_cls() }
|
||||
@@ -109,7 +109,7 @@ impl<T, U, F> Responder for FnMiddleStage<T, U, F> {}
|
||||
impl<
|
||||
T: 'static + TryFromExprInst,
|
||||
U: 'static + ToClause,
|
||||
F: 'static + Clone + FnOnce(T) -> Result<U, Rc<dyn ExternError>> + Send,
|
||||
F: 'static + Clone + FnOnce(T) -> Result<U, Arc<dyn ExternError>> + Send,
|
||||
> Atomic for FnMiddleStage<T, U, F>
|
||||
{
|
||||
fn as_any(self: Box<Self>) -> Box<dyn std::any::Any> { self }
|
||||
@@ -127,7 +127,7 @@ impl<
|
||||
impl<
|
||||
T: 'static + TryFromExprInst,
|
||||
U: 'static + ToClause,
|
||||
F: 'static + Clone + Send + FnOnce(T) -> Result<U, Rc<dyn ExternError>>,
|
||||
F: 'static + Clone + Send + FnOnce(T) -> Result<U, Arc<dyn ExternError>>,
|
||||
> ExternFn for Param<T, U, F>
|
||||
{
|
||||
fn name(&self) -> &str { "anonymous Rust function" }
|
||||
@@ -137,8 +137,9 @@ impl<
|
||||
}
|
||||
|
||||
pub mod constructors {
|
||||
use std::rc::Rc;
|
||||
|
||||
|
||||
use std::sync::Arc;
|
||||
use super::{Param, ToClause};
|
||||
use crate::foreign::{ExternError, ExternFn};
|
||||
use crate::interpreted::TryFromExprInst;
|
||||
@@ -163,7 +164,7 @@ pub mod constructors {
|
||||
TLast: TryFromExprInst + 'static,
|
||||
TReturn: ToClause + Send + 'static,
|
||||
TFunction: FnOnce( $( $t , )* TLast )
|
||||
-> Result<TReturn, Rc<dyn ExternError>> + Clone + Send + 'static
|
||||
-> Result<TReturn, Arc<dyn ExternError>> + Clone + Send + 'static
|
||||
>(function: TFunction) -> impl ExternFn {
|
||||
xfn_variant!(@BODY_LOOP function
|
||||
( $( ( $t [< $t:lower >] ) )* )
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use std::any::Any;
|
||||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
|
||||
use ordered_float::NotNan;
|
||||
|
||||
use super::atom::StrictEq;
|
||||
use super::{AtomicResult, AtomicReturn, ExternError};
|
||||
use super::{AtomicResult, AtomicReturn, XfnResult};
|
||||
use crate::error::AssertionError;
|
||||
#[allow(unused)] // for doc
|
||||
// use crate::define_fn;
|
||||
@@ -62,7 +61,7 @@ impl<T: InertAtomic> Atomic for T {
|
||||
}
|
||||
|
||||
impl<T: InertAtomic> TryFromExprInst for T {
|
||||
fn from_exi(exi: ExprInst) -> Result<Self, Rc<dyn ExternError>> {
|
||||
fn from_exi(exi: ExprInst) -> XfnResult<Self> {
|
||||
let Expr { clause, location } = exi.expr_val();
|
||||
match clause {
|
||||
Clause::Atom(a) => match a.0.as_any().downcast() {
|
||||
|
||||
@@ -8,7 +8,7 @@ mod extern_fn;
|
||||
mod fn_bridge;
|
||||
mod inert;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use atom::{Atom, Atomic, AtomicResult, AtomicReturn, StrictEq};
|
||||
pub use extern_fn::{ExFn, ExternError, ExternFn};
|
||||
@@ -22,4 +22,4 @@ pub use inert::InertAtomic;
|
||||
pub use crate::representations::interpreted::Clause;
|
||||
|
||||
/// Return type of the argument to the [xfn_1ary] family of functions
|
||||
pub type XfnResult<T> = Result<T, Rc<dyn ExternError>>;
|
||||
pub type XfnResult<T> = Result<T, Arc<dyn ExternError>>;
|
||||
|
||||
Reference in New Issue
Block a user