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

@@ -16,6 +16,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt, clippy
- name: Build
run: cargo build --verbose
- name: Run tests

View File

@@ -1,2 +1,2 @@
[toolchain]
channel = "stable"
channel = "nightly"

View File

@@ -32,8 +32,8 @@ 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)]
@@ -41,7 +41,9 @@ use crate::Primitive;
/// 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| {
@@ -50,7 +52,10 @@ use crate::Primitive;
/// });
///
/// #[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),
}
}

View File

@@ -70,10 +70,12 @@ fn substitute(paths: &PathSet, value: Clause, body: ExprInst) -> ExprInst {
x: substitute(right, value.clone(), x.clone()),
}),
(Clause::LambdaArg, None) => Ok(value.clone()),
(_, None) =>
panic!("Substitution path ends in something other than LambdaArg"),
(_, Some(_)) =>
panic!("Substitution path leads into something other than Apply"),
(_, None) => {
panic!("Substitution path ends in something other than LambdaArg")
},
(_, Some(_)) => {
panic!("Substitution path leads into something other than Apply")
},
}
})
.unwrap()

View File

@@ -23,8 +23,9 @@ impl Display for RuntimeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Extern(e) => write!(f, "Error in external function: {e}"),
Self::NonFunctionApplication(loc) =>
write!(f, "Primitive applied as function at {loc:?}"),
Self::NonFunctionApplication(loc) => {
write!(f, "Primitive applied as function at {loc:?}")
},
}
}
}

View File

@@ -65,8 +65,9 @@ pub fn collect_exported_ops(
let preparsed = &loaded[&fpath].preparsed;
let module = preparsed.0.walk(subpath_v, false).map_err(|walk_err| {
match walk_err.kind {
WalkErrorKind::Private =>
unreachable!("visibility is not being checked here"),
WalkErrorKind::Private => {
unreachable!("visibility is not being checked here")
},
WalkErrorKind::Missing => ModuleNotFound {
file: i.extern_vec(fpath),
subpath: subpath_v

View File

@@ -23,8 +23,9 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::EmptyS =>
write!(f, "`()` as a clause is meaningless in lambda calculus"),
Error::EmptyS => {
write!(f, "`()` as a clause is meaningless in lambda calculus")
},
Error::BadGroup(_) => write!(
f,
"Only `(...)` may be converted to typed lambdas. `[...]` and \

View File

@@ -18,15 +18,17 @@ pub enum RuleError {
impl InternedDisplay for RuleError {
fn fmt_i(&self, f: &mut fmt::Formatter<'_>, i: &Interner) -> fmt::Result {
match *self {
Self::Missing(key) =>
write!(f, "Key {:?} not in match pattern", i.r(key)),
Self::Missing(key) => {
write!(f, "Key {:?} not in match pattern", i.r(key))
},
Self::TypeMismatch(key) => write!(
f,
"Key {:?} used inconsistently with and without ellipsis",
i.r(key)
),
Self::Multiple(key) =>
write!(f, "Key {:?} appears multiple times in match pattern", i.r(key)),
Self::Multiple(key) => {
write!(f, "Key {:?} appears multiple times in match pattern", i.r(key))
},
Self::VecNeighbors(left, right) => write!(
f,
"Keys {:?} and {:?} are two vectorials right next to each other",

View File

@@ -11,5 +11,6 @@ mod str;
pub use cpsio::{handle as handleIO, IO};
pub use mk_stl::mk_stl;
pub use self::bool::Boolean;
pub use self::num::Numeric;