Fixing some showstoppers

- inertness now tracked separately from gas
- atomic_impl now correctly rolls over when the argument is inert
- syntax fixes
- tree shaking
This commit is contained in:
2023-05-08 20:27:52 +01:00
parent a604e40bad
commit 6a381c5b57
28 changed files with 112 additions and 445 deletions

View File

@@ -56,14 +56,14 @@ macro_rules! atomic_impl {
AsRef<$crate::foreign::RcExpr>
>::as_ref(self).clone();
// run the expression
let ret = $crate::interpreter::run(expr, ctx)?;
let $crate::interpreter::Return{ gas, state } = ret;
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));
// branch off or wrap up
let next_clause = if gas.map(|g| g > 0).unwrap_or(true) {
let clause = if inert {
match ($next_phase)(&next_self) {
Ok(r) => r,
Err(e) => return Err(
@@ -72,7 +72,7 @@ macro_rules! atomic_impl {
}
} else { next_self.to_atom_cls() };
// package and return
Ok((next_clause, gas))
Ok($crate::foreign::AtomicReturn{ clause, gas, inert: false })
}
}
};

View File

@@ -18,7 +18,11 @@ macro_rules! atomic_inert {
fn run(&self, ctx: $crate::interpreter::Context)
-> $crate::foreign::AtomicResult
{
Ok((self.clone().to_atom_cls(), ctx.gas))
Ok($crate::foreign::AtomicReturn{
clause: self.clone().to_atom_cls(),
gas: ctx.gas,
inert: true
})
}
}
};

View File

@@ -23,17 +23,16 @@ macro_rules! externfn_impl {
fn name(&self) -> &str {stringify!($typ)}
fn apply(&self,
arg: $crate::foreign::RcExpr,
ctx: $crate::interpreter::Context
_ctx: $crate::interpreter::Context
) -> $crate::foreign::XfnResult {
match ($next_atomic)(self, arg) { // ? casts the result but we want to strictly forward it
Ok(r) => Ok((
Ok(r) => Ok(
$crate::representations::interpreted::Clause::P(
$crate::representations::Primitive::Atom(
$crate::foreign::Atom::new(r)
)
),
ctx.gas.map(|g| g - 1)
)),
)
),
Err(e) => Err(e)
}
}