forked from Orchid/orchid
Separated orchid-host and orchid-extension
This is an architectural change that allows me to implment specifics first and generalize along observed symmetries in orchid-base
This commit is contained in:
@@ -5,8 +5,6 @@ use orchid_api::expr::{Clause, Expr};
|
||||
use orchid_api::location::Location;
|
||||
|
||||
use super::traits::{GenClause, Generable};
|
||||
use crate::expr::RtExpr;
|
||||
use crate::host::AtomHand;
|
||||
use crate::intern::{deintern, intern};
|
||||
|
||||
fn safely_reinterpret<In: 'static, Out: 'static>(x: In) -> Result<Out, In> {
|
||||
@@ -24,7 +22,7 @@ impl GenClause for Expr {
|
||||
fn generate<T: super::traits::Generable>(&self, ctx: T::Ctx<'_>, pop: &impl Fn() -> T) -> T {
|
||||
match &self.clause {
|
||||
Clause::Arg(arg) => T::arg(ctx, deintern(*arg).as_str()),
|
||||
Clause::Atom(atom) => T::atom(ctx, AtomHand::from_api(atom.clone())),
|
||||
Clause::Atom(atom) => T::atom(ctx, atom.clone()),
|
||||
Clause::Call(f, x) => T::apply(ctx, |c| f.generate(c, pop), |c| x.generate(c, pop)),
|
||||
Clause::Lambda(arg, b) => T::lambda(ctx, deintern(*arg).as_str(), |ctx| b.generate(ctx, pop)),
|
||||
Clause::Seq(n1, n2) => T::seq(ctx, |c| n1.generate(c, pop), |c| n2.generate(c, pop)),
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
//! Various elemental components to build expression trees that all implement
|
||||
//! [GenClause].
|
||||
|
||||
use orchid_api::atom::Atom;
|
||||
|
||||
use super::traits::{GenClause, Generable};
|
||||
use crate::host::AtomHand;
|
||||
|
||||
/// A trivial atom
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SysAtom(pub AtomHand);
|
||||
pub struct SysAtom(pub Atom);
|
||||
impl GenClause for SysAtom {
|
||||
fn generate<T: Generable>(&self, ctx: T::Ctx<'_>, _: &impl Fn() -> T) -> T {
|
||||
T::atom(ctx, self.0.clone())
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::cell::RefCell;
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
|
||||
use crate::host::AtomHand;
|
||||
use orchid_api::atom::Atom;
|
||||
|
||||
/// Representations of the Orchid expression tree that can describe basic
|
||||
/// language elements.
|
||||
@@ -13,7 +13,7 @@ pub trait Generable: Sized + 'static {
|
||||
/// Context information defined by parents. Generators just forward this.
|
||||
type Ctx<'a>: Sized;
|
||||
/// Wrap external data.
|
||||
fn atom(ctx: Self::Ctx<'_>, a: AtomHand) -> Self;
|
||||
fn atom(ctx: Self::Ctx<'_>, a: Atom) -> Self;
|
||||
/// Generate a reference to a constant
|
||||
fn constant<'a>(ctx: Self::Ctx<'_>, name: impl IntoIterator<Item = &'a str>) -> Self;
|
||||
/// Generate a function call given the function and its argument
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
use std::fmt;
|
||||
|
||||
use dyn_clone::{clone_box, DynClone};
|
||||
use orchid_api::atom::Atom;
|
||||
use orchid_api::expr::Expr;
|
||||
use trait_set::trait_set;
|
||||
|
||||
use super::tpl;
|
||||
use super::traits::{Gen, GenClause};
|
||||
use crate::combine::Combine;
|
||||
use crate::host::AtomHand;
|
||||
use crate::tree::{ModEntry, ModMember, TreeConflict};
|
||||
|
||||
trait_set! {
|
||||
@@ -64,14 +64,14 @@ pub fn ent<K: AsRef<str>>(
|
||||
|
||||
/// Describe an [Atomic]
|
||||
#[must_use]
|
||||
pub fn atom_leaf(atom: AtomHand) -> ConstTree { leaf(tpl::SysAtom(atom)) }
|
||||
pub fn atom_leaf(atom: Atom) -> ConstTree { leaf(tpl::SysAtom(atom)) }
|
||||
|
||||
/// Describe an [Atomic] which appears as an entry in a [ConstTree::tree]
|
||||
///
|
||||
/// The unarray is used to trick rustfmt into breaking the atom into a block
|
||||
/// without breaking this call into a block
|
||||
#[must_use]
|
||||
pub fn atom_ent<K: AsRef<str>>(key: K, [atom]: [AtomHand; 1]) -> (K, ConstTree) {
|
||||
pub fn atom_ent<K: AsRef<str>>(key: K, [atom]: [Atom; 1]) -> (K, ConstTree) {
|
||||
(key, atom_leaf(atom))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user