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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Install latest nightly
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
components: rustfmt, clippy
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --verbose
|
run: cargo build --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "stable"
|
channel = "nightly"
|
||||||
@@ -32,25 +32,30 @@ use crate::Primitive;
|
|||||||
///
|
///
|
||||||
/// _definition of the `add` function in the STL_
|
/// _definition of the `add` function in the STL_
|
||||||
/// ```
|
/// ```
|
||||||
/// use orchidlang::stl::Numeric;
|
|
||||||
/// use orchidlang::interpreted::ExprInst;
|
/// use orchidlang::interpreted::ExprInst;
|
||||||
|
/// use orchidlang::stl::Numeric;
|
||||||
/// use orchidlang::{atomic_impl, atomic_redirect, externfn_impl};
|
/// use orchidlang::{atomic_impl, atomic_redirect, externfn_impl};
|
||||||
///
|
///
|
||||||
/// #[derive(Clone)]
|
/// #[derive(Clone)]
|
||||||
/// pub struct Add2;
|
/// pub struct Add2;
|
||||||
/// externfn_impl!(Add2, |_: &Self, x: ExprInst| Ok(Add1 { x }));
|
/// externfn_impl!(Add2, |_: &Self, x: ExprInst| Ok(Add1 { x }));
|
||||||
///
|
///
|
||||||
/// #[derive(Debug, Clone)]
|
/// #[derive(Debug, Clone)]
|
||||||
/// pub struct Add1 { x: ExprInst }
|
/// pub struct Add1 {
|
||||||
|
/// x: ExprInst,
|
||||||
|
/// }
|
||||||
/// atomic_redirect!(Add1, x);
|
/// atomic_redirect!(Add1, x);
|
||||||
/// atomic_impl!(Add1);
|
/// atomic_impl!(Add1);
|
||||||
/// externfn_impl!(Add1, |this: &Self, x: ExprInst| {
|
/// externfn_impl!(Add1, |this: &Self, x: ExprInst| {
|
||||||
/// let a: Numeric = this.x.clone().try_into()?;
|
/// let a: Numeric = this.x.clone().try_into()?;
|
||||||
/// Ok(Add0 { a, x })
|
/// Ok(Add0 { a, x })
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// #[derive(Debug, Clone)]
|
/// #[derive(Debug, Clone)]
|
||||||
/// pub struct Add0 { a: Numeric, x: ExprInst }
|
/// pub struct Add0 {
|
||||||
|
/// a: Numeric,
|
||||||
|
/// x: ExprInst,
|
||||||
|
/// }
|
||||||
/// atomic_redirect!(Add0, x);
|
/// atomic_redirect!(Add0, x);
|
||||||
/// atomic_impl!(Add0, |Self { a, x }: &Self, _| {
|
/// atomic_impl!(Add0, |Self { a, x }: &Self, _| {
|
||||||
/// let b: Numeric = x.clone().try_into()?;
|
/// let b: Numeric = x.clone().try_into()?;
|
||||||
@@ -74,10 +79,8 @@ macro_rules! atomic_impl {
|
|||||||
ctx: $crate::interpreter::Context,
|
ctx: $crate::interpreter::Context,
|
||||||
) -> $crate::foreign::AtomicResult {
|
) -> $crate::foreign::AtomicResult {
|
||||||
// extract the expression
|
// extract the expression
|
||||||
let expr = <Self as AsRef<
|
let expr =
|
||||||
$crate::interpreted::ExprInst,
|
<Self as AsRef<$crate::interpreted::ExprInst>>::as_ref(self).clone();
|
||||||
>>::as_ref(self)
|
|
||||||
.clone();
|
|
||||||
// run the expression
|
// run the expression
|
||||||
let ret = $crate::interpreter::run(expr, ctx.clone())?;
|
let ret = $crate::interpreter::run(expr, ctx.clone())?;
|
||||||
let $crate::interpreter::Return { gas, state, inert } = ret;
|
let $crate::interpreter::Return { gas, state, inert } = ret;
|
||||||
|
|||||||
@@ -23,13 +23,9 @@ macro_rules! atomic_redirect {
|
|||||||
&self.$field
|
&self.$field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<(&Self, $crate::interpreted::ExprInst)>
|
impl From<(&Self, $crate::interpreted::ExprInst)> for $typ {
|
||||||
for $typ
|
|
||||||
{
|
|
||||||
#[allow(clippy::needless_update)]
|
#[allow(clippy::needless_update)]
|
||||||
fn from(
|
fn from((old, $field): (&Self, $crate::interpreted::ExprInst)) -> Self {
|
||||||
(old, $field): (&Self, $crate::interpreted::ExprInst),
|
|
||||||
) -> Self {
|
|
||||||
Self { $field, ..old.clone() }
|
Self { $field, ..old.clone() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,9 @@ macro_rules! externfn_impl {
|
|||||||
let closure = $next_atomic;
|
let closure = $next_atomic;
|
||||||
match closure(self, arg) {
|
match closure(self, arg) {
|
||||||
// ? casts the result but we want to strictly forward it
|
// ? casts the result but we want to strictly forward it
|
||||||
Ok(r) => Ok($crate::interpreted::Clause::P(
|
Ok(r) => Ok($crate::interpreted::Clause::P($crate::Primitive::Atom(
|
||||||
$crate::Primitive::Atom(
|
$crate::foreign::Atom::new(r),
|
||||||
$crate::foreign::Atom::new(r),
|
))),
|
||||||
),
|
|
||||||
)),
|
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,10 +70,12 @@ fn substitute(paths: &PathSet, value: Clause, body: ExprInst) -> ExprInst {
|
|||||||
x: substitute(right, value.clone(), x.clone()),
|
x: substitute(right, value.clone(), x.clone()),
|
||||||
}),
|
}),
|
||||||
(Clause::LambdaArg, None) => Ok(value.clone()),
|
(Clause::LambdaArg, None) => Ok(value.clone()),
|
||||||
(_, None) =>
|
(_, None) => {
|
||||||
panic!("Substitution path ends in something other than LambdaArg"),
|
panic!("Substitution path ends in something other than LambdaArg")
|
||||||
(_, Some(_)) =>
|
},
|
||||||
panic!("Substitution path leads into something other than Apply"),
|
(_, Some(_)) => {
|
||||||
|
panic!("Substitution path leads into something other than Apply")
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ impl Display for RuntimeError {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Extern(e) => write!(f, "Error in external function: {e}"),
|
Self::Extern(e) => write!(f, "Error in external function: {e}"),
|
||||||
Self::NonFunctionApplication(loc) =>
|
Self::NonFunctionApplication(loc) => {
|
||||||
write!(f, "Primitive applied as function at {loc:?}"),
|
write!(f, "Primitive applied as function at {loc:?}")
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,9 @@ pub fn collect_exported_ops(
|
|||||||
let preparsed = &loaded[&fpath].preparsed;
|
let preparsed = &loaded[&fpath].preparsed;
|
||||||
let module = preparsed.0.walk(subpath_v, false).map_err(|walk_err| {
|
let module = preparsed.0.walk(subpath_v, false).map_err(|walk_err| {
|
||||||
match walk_err.kind {
|
match walk_err.kind {
|
||||||
WalkErrorKind::Private =>
|
WalkErrorKind::Private => {
|
||||||
unreachable!("visibility is not being checked here"),
|
unreachable!("visibility is not being checked here")
|
||||||
|
},
|
||||||
WalkErrorKind::Missing => ModuleNotFound {
|
WalkErrorKind::Missing => ModuleNotFound {
|
||||||
file: i.extern_vec(fpath),
|
file: i.extern_vec(fpath),
|
||||||
subpath: subpath_v
|
subpath: subpath_v
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ pub enum Error {
|
|||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Error::EmptyS =>
|
Error::EmptyS => {
|
||||||
write!(f, "`()` as a clause is meaningless in lambda calculus"),
|
write!(f, "`()` as a clause is meaningless in lambda calculus")
|
||||||
|
},
|
||||||
Error::BadGroup(_) => write!(
|
Error::BadGroup(_) => write!(
|
||||||
f,
|
f,
|
||||||
"Only `(...)` may be converted to typed lambdas. `[...]` and \
|
"Only `(...)` may be converted to typed lambdas. `[...]` and \
|
||||||
|
|||||||
@@ -18,15 +18,17 @@ pub enum RuleError {
|
|||||||
impl InternedDisplay for RuleError {
|
impl InternedDisplay for RuleError {
|
||||||
fn fmt_i(&self, f: &mut fmt::Formatter<'_>, i: &Interner) -> fmt::Result {
|
fn fmt_i(&self, f: &mut fmt::Formatter<'_>, i: &Interner) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Self::Missing(key) =>
|
Self::Missing(key) => {
|
||||||
write!(f, "Key {:?} not in match pattern", i.r(key)),
|
write!(f, "Key {:?} not in match pattern", i.r(key))
|
||||||
|
},
|
||||||
Self::TypeMismatch(key) => write!(
|
Self::TypeMismatch(key) => write!(
|
||||||
f,
|
f,
|
||||||
"Key {:?} used inconsistently with and without ellipsis",
|
"Key {:?} used inconsistently with and without ellipsis",
|
||||||
i.r(key)
|
i.r(key)
|
||||||
),
|
),
|
||||||
Self::Multiple(key) =>
|
Self::Multiple(key) => {
|
||||||
write!(f, "Key {:?} appears multiple times in match pattern", i.r(key)),
|
write!(f, "Key {:?} appears multiple times in match pattern", i.r(key))
|
||||||
|
},
|
||||||
Self::VecNeighbors(left, right) => write!(
|
Self::VecNeighbors(left, right) => write!(
|
||||||
f,
|
f,
|
||||||
"Keys {:?} and {:?} are two vectorials right next to each other",
|
"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 cpsio::{handle as handleIO, IO};
|
||||||
pub use mk_stl::mk_stl;
|
pub use mk_stl::mk_stl;
|
||||||
|
|
||||||
pub use self::bool::Boolean;
|
pub use self::bool::Boolean;
|
||||||
pub use self::num::Numeric;
|
pub use self::num::Numeric;
|
||||||
|
|||||||
Reference in New Issue
Block a user