forked from Orchid/orchid
Public API and docs
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
use crate::foreign::Atomic;
|
||||
|
||||
/// A macro that generates the straightforward, syntactically invariant part of
|
||||
/// implementing [Atomic]. Implemented fns are [Atomic::as_any],
|
||||
/// [Atomic::definitely_eq] and [Atomic::hash].
|
||||
/// implementing [Atomic].
|
||||
///
|
||||
/// It depends on [Eq] and [Hash]
|
||||
/// Currently implements
|
||||
/// - [Atomic::as_any]
|
||||
#[macro_export]
|
||||
macro_rules! atomic_defaults {
|
||||
() => {
|
||||
|
||||
@@ -14,10 +14,10 @@ use crate::representations::Primitive;
|
||||
/// A macro that generates implementations of [Atomic] to simplify the
|
||||
/// development of external bindings for Orchid.
|
||||
///
|
||||
/// The macro depends on implementations of [AsRef<Clause>] and [From<(&Self,
|
||||
/// Clause)>] for extracting the clause to be processed and then reconstructing
|
||||
/// the [Atomic]. Naturally, supertraits of [Atomic] are also dependencies.
|
||||
/// These are [Any], [Debug] and [DynClone].
|
||||
/// The macro depends on implementations of [`AsRef<Clause>`] and
|
||||
/// [`From<(&Self, Clause)>`] for extracting the clause to be processed and then
|
||||
/// reconstructing the [Atomic]. Naturally, supertraits of [Atomic] are also
|
||||
/// dependencies. These are [Any], [Debug] and [DynClone].
|
||||
///
|
||||
/// The simplest form just requires the typename to be specified. This
|
||||
/// additionally depends on an implementation of [ExternFn] because after the
|
||||
@@ -37,8 +37,9 @@ use crate::representations::Primitive;
|
||||
/// ```
|
||||
/// // excerpt from the exact implementation of Multiply
|
||||
/// atomic_impl!(Multiply0, |Self(a, cls): &Self| {
|
||||
/// let b: Numeric = cls.clone().try_into().map_err(AssertionError::into_extern)?;
|
||||
/// Ok(*a * b).into())
|
||||
/// let b: Numeric =
|
||||
/// cls.clone().try_into().map_err(AssertionError::into_extern)?;
|
||||
/// Ok(*a * b).into()
|
||||
/// })
|
||||
/// ```
|
||||
#[macro_export]
|
||||
@@ -58,14 +59,18 @@ macro_rules! atomic_impl {
|
||||
ctx: $crate::interpreter::Context,
|
||||
) -> $crate::foreign::AtomicResult {
|
||||
// extract the expression
|
||||
let expr =
|
||||
<Self as AsRef<$crate::foreign::RcExpr>>::as_ref(self).clone();
|
||||
let expr = <Self as AsRef<
|
||||
$crate::representations::interpreted::ExprInst,
|
||||
>>::as_ref(self)
|
||||
.clone();
|
||||
// run the expression
|
||||
let ret = $crate::interpreter::run(expr, ctx.clone())?;
|
||||
let $crate::interpreter::Return { gas, state, inert } = ret;
|
||||
// rebuild the atomic
|
||||
let next_self =
|
||||
<Self as From<(&Self, $crate::foreign::RcExpr)>>::from((self, state));
|
||||
let next_self = <Self as From<(
|
||||
&Self,
|
||||
$crate::representations::interpreted::ExprInst,
|
||||
)>>::from((self, state));
|
||||
// branch off or wrap up
|
||||
let clause = if inert {
|
||||
let closure = $next_phase;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#[allow(unused)]
|
||||
use super::atomic_impl;
|
||||
use crate::atomic_impl;
|
||||
|
||||
/// Implement the traits required by [atomic_impl] to redirect run_* functions
|
||||
/// Implement the traits required by [atomic_impl] to redirect run calls
|
||||
/// to a field with a particular name.
|
||||
#[macro_export]
|
||||
macro_rules! atomic_redirect {
|
||||
@@ -18,14 +18,18 @@ macro_rules! atomic_redirect {
|
||||
}
|
||||
};
|
||||
($typ:ident, $field:ident) => {
|
||||
impl AsRef<$crate::foreign::RcExpr> for $typ {
|
||||
fn as_ref(&self) -> &$crate::foreign::RcExpr {
|
||||
impl AsRef<$crate::representations::interpreted::ExprInst> for $typ {
|
||||
fn as_ref(&self) -> &$crate::representations::interpreted::ExprInst {
|
||||
&self.$field
|
||||
}
|
||||
}
|
||||
impl From<(&Self, $crate::foreign::RcExpr)> for $typ {
|
||||
impl From<(&Self, $crate::representations::interpreted::ExprInst)>
|
||||
for $typ
|
||||
{
|
||||
#[allow(clippy::needless_update)]
|
||||
fn from((old, $field): (&Self, $crate::foreign::RcExpr)) -> Self {
|
||||
fn from(
|
||||
(old, $field): (&Self, $crate::representations::interpreted::ExprInst),
|
||||
) -> Self {
|
||||
Self { $field, ..old.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ macro_rules! externfn_impl {
|
||||
}
|
||||
fn apply(
|
||||
&self,
|
||||
arg: $crate::foreign::RcExpr,
|
||||
arg: $crate::representations::interpreted::ExprInst,
|
||||
_ctx: $crate::interpreter::Context,
|
||||
) -> $crate::foreign::XfnResult {
|
||||
let closure = $next_atomic;
|
||||
|
||||
Reference in New Issue
Block a user