#![no_std]
#![forbid(unsafe_code)]
#![warn(missing_docs)]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
pub mod box_iter;
pub mod compile;
pub mod data;
mod exn;
mod filter;
mod fold;
mod funs;
mod into_iter;
pub mod load;
pub mod native;
pub mod ops;
pub mod path;
mod rc_lazy_list;
mod rc_list;
mod stack;
pub mod val;
pub use data::DataT;
pub use exn::{Error, Exn};
pub use filter::{Ctx, Cv, Native, PathsPtr, RunPtr, UpdatePtr, Vars};
pub use val::{unwrap_valr, ValR, ValT, ValX, ValXs};
use rc_list::List as RcList;
use stack::Stack;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Bind<V = (), F = V> {
Var(V),
Fun(F),
}
impl<V, F> Bind<V, F> {
pub(crate) fn as_ref(&self) -> Bind<&V, &F> {
match self {
Self::Var(x) => Bind::Var(x),
Self::Fun(x) => Bind::Fun(x),
}
}
}
impl<T> Bind<T, T> {
pub(crate) fn map<U>(self, f: impl FnOnce(T) -> U) -> Bind<U, U> {
match self {
Self::Var(x) => Bind::Var(f(x)),
Self::Fun(x) => Bind::Fun(f(x)),
}
}
}
pub type Compiler<S, D> = compile::Compiler<S, Native<D>>;
pub type Filter<D> = compile::Filter<Native<D>>;
pub type Lut<D> = compile::Lut<Native<D>>;
impl<V: ValT + 'static> Filter<data::JustLut<V>> {
pub fn yields(&self, x: V, ys: impl Iterator<Item = ValR<V>>) {
let ctx = Ctx::<data::JustLut<V>>::new(&self.lut, Vars::new([]));
let out = self.id.run((ctx, x)).map(unwrap_valr);
assert!(out.eq(ys));
}
}
pub fn defs() -> impl Iterator<Item = load::parse::Def<&'static str>> {
load::parse(include_str!("defs.jq"), |p| p.defs())
.unwrap()
.into_iter()
}
pub fn funs<D: DataT>() -> impl Iterator<Item = native::Filter<Native<D>>>
where
for<'a> D::V<'a>: ValT,
{
let run = funs::run().into_vec().into_iter().map(native::run);
let paths = funs::paths().into_vec().into_iter().map(native::paths);
run.chain(paths)
}