forked from Orchid/orchid
More adjustments
This commit is contained in:
5
.github/workflows/rust.yml
vendored
5
.github/workflows/rust.yml
vendored
@@ -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
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "stable"
|
||||
channel = "nightly"
|
||||
@@ -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;
|
||||
|
||||
@@ -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() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:?}")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
pub use self::num::Numeric;
|
||||
|
||||
Reference in New Issue
Block a user