More adjustments

This commit is contained in:
2023-05-29 21:34:54 +01:00
parent 12112ff063
commit 5a18f14d3b
11 changed files with 47 additions and 37 deletions

View File

@@ -32,25 +32,30 @@ use crate::Primitive;
///
/// _definition of the `add` function in the STL_
/// ```
/// use orchidlang::stl::Numeric;
/// use orchidlang::interpreted::ExprInst;
/// use orchidlang::stl::Numeric;
/// use orchidlang::{atomic_impl, atomic_redirect, externfn_impl};
///
///
/// #[derive(Clone)]
/// pub struct Add2;
/// externfn_impl!(Add2, |_: &Self, x: ExprInst| Ok(Add1 { x }));
///
///
/// #[derive(Debug, Clone)]
/// pub struct Add1 { x: ExprInst }
/// pub struct Add1 {
/// x: ExprInst,
/// }
/// atomic_redirect!(Add1, x);
/// atomic_impl!(Add1);
/// externfn_impl!(Add1, |this: &Self, x: ExprInst| {
/// let a: Numeric = this.x.clone().try_into()?;
/// Ok(Add0 { a, x })
/// });
///
///
/// #[derive(Debug, Clone)]
/// pub struct Add0 { a: Numeric, x: ExprInst }
/// pub struct Add0 {
/// a: Numeric,
/// x: ExprInst,
/// }
/// atomic_redirect!(Add0, x);
/// atomic_impl!(Add0, |Self { a, x }: &Self, _| {
/// let b: Numeric = x.clone().try_into()?;
@@ -74,10 +79,8 @@ macro_rules! atomic_impl {
ctx: $crate::interpreter::Context,
) -> $crate::foreign::AtomicResult {
// extract the expression
let expr = <Self as AsRef<
$crate::interpreted::ExprInst,
>>::as_ref(self)
.clone();
let expr =
<Self as AsRef<$crate::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;

View File

@@ -23,13 +23,9 @@ macro_rules! atomic_redirect {
&self.$field
}
}
impl From<(&Self, $crate::interpreted::ExprInst)>
for $typ
{
impl From<(&Self, $crate::interpreted::ExprInst)> for $typ {
#[allow(clippy::needless_update)]
fn from(
(old, $field): (&Self, $crate::interpreted::ExprInst),
) -> Self {
fn from((old, $field): (&Self, $crate::interpreted::ExprInst)) -> Self {
Self { $field, ..old.clone() }
}
}

View File

@@ -34,11 +34,9 @@ macro_rules! externfn_impl {
let closure = $next_atomic;
match closure(self, arg) {
// ? casts the result but we want to strictly forward it
Ok(r) => Ok($crate::interpreted::Clause::P(
$crate::Primitive::Atom(
$crate::foreign::Atom::new(r),
),
)),
Ok(r) => Ok($crate::interpreted::Clause::P($crate::Primitive::Atom(
$crate::foreign::Atom::new(r),
))),
Err(e) => Err(e),
}
}