Removed macro facets
Macros, placeholders, etc. will all be handled by std eventually so they shouldn't appear in the protocol or the host
This commit is contained in:
@@ -63,7 +63,7 @@ impl<A: Atomic + AtomicFeaturesImpl<A::Variant> + ?Sized> AtomicFeatures for A {
|
||||
}
|
||||
|
||||
pub fn get_info<A: AtomCard>(
|
||||
sys: &(impl DynSystemCard + ?Sized)
|
||||
sys: &(impl DynSystemCard + ?Sized),
|
||||
) -> (api::AtomId, &'static dyn AtomDynfo) {
|
||||
atom_info_for(sys, TypeId::of::<A>()).unwrap_or_else(|| {
|
||||
panic!("Atom {} not associated with system {}", type_name::<A>(), sys.name())
|
||||
@@ -195,10 +195,10 @@ pub trait ReqPck<T: AtomCard + ?Sized>: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct RequestPack<'a, T: AtomCard + ?Sized, W: Write + ?Sized>{
|
||||
pub(crate) struct RequestPack<'a, T: AtomCard + ?Sized, W: Write + ?Sized> {
|
||||
pub req: T::Req,
|
||||
pub write: &'a mut W,
|
||||
pub sys: SysCtx
|
||||
pub sys: SysCtx,
|
||||
}
|
||||
|
||||
impl<'a, T: AtomCard + ?Sized, W: Write + ?Sized> ReqPck<T> for RequestPack<'a, T, W> {
|
||||
|
||||
@@ -64,7 +64,11 @@ impl<T: OwnedAtom> AtomDynfo for OwnedAtomDynfo<T> {
|
||||
fn drop(&self, AtomCtx(_, id, ctx): AtomCtx) {
|
||||
with_atom(id.unwrap(), |a| a.remove().dyn_free(ctx))
|
||||
}
|
||||
fn serialize(&self, AtomCtx(_, id, ctx): AtomCtx<'_>, write: &mut dyn Write) -> Vec<api::ExprTicket> {
|
||||
fn serialize(
|
||||
&self,
|
||||
AtomCtx(_, id, ctx): AtomCtx<'_>,
|
||||
write: &mut dyn Write,
|
||||
) -> Vec<api::ExprTicket> {
|
||||
let id = id.unwrap();
|
||||
id.encode(write);
|
||||
with_atom(id, |a| a.dyn_serialize(ctx, write)).into_iter().map(|t| t.into_tk()).collect_vec()
|
||||
@@ -182,7 +186,8 @@ impl<T: OwnedAtom> DynOwnedAtom for T {
|
||||
self.same(ctx, other_self)
|
||||
}
|
||||
fn dyn_handle_req(&self, sys: SysCtx, req: &mut dyn Read, write: &mut dyn Write) {
|
||||
let pack = RequestPack::<T, dyn Write>{ req: <Self as AtomCard>::Req::decode(req), write, sys };
|
||||
let pack =
|
||||
RequestPack::<T, dyn Write> { req: <Self as AtomCard>::Req::decode(req), write, sys };
|
||||
self.handle_req(pack)
|
||||
}
|
||||
fn dyn_command(self: Box<Self>, ctx: SysCtx) -> OrcRes<Option<GenExpr>> { self.command(ctx) }
|
||||
|
||||
@@ -49,7 +49,7 @@ impl<T: ThinAtom> AtomDynfo for ThinAtomDynfo<T> {
|
||||
req: &mut dyn std::io::Read,
|
||||
write: &mut dyn Write,
|
||||
) {
|
||||
let pack = RequestPack::<T, dyn Write>{ req: Decode::decode(req), write, sys };
|
||||
let pack = RequestPack::<T, dyn Write> { req: Decode::decode(req), write, sys };
|
||||
T::decode(&mut &buf[..]).handle_req(pack)
|
||||
}
|
||||
fn same(&self, AtomCtx(buf, _, ctx): AtomCtx, a2: &api::Atom) -> bool {
|
||||
@@ -58,7 +58,7 @@ impl<T: ThinAtom> AtomDynfo for ThinAtomDynfo<T> {
|
||||
fn command(&self, AtomCtx(buf, _, ctx): AtomCtx<'_>) -> OrcRes<Option<GenExpr>> {
|
||||
T::decode(&mut &buf[..]).command(ctx)
|
||||
}
|
||||
fn serialize(&self, AtomCtx(buf, _, _): AtomCtx<'_>, write: &mut dyn Write) -> Vec<ExprTicket> {
|
||||
fn serialize(&self, AtomCtx(buf, ..): AtomCtx<'_>, write: &mut dyn Write) -> Vec<ExprTicket> {
|
||||
T::decode(&mut &buf[..]).encode(write);
|
||||
Vec::new()
|
||||
}
|
||||
@@ -72,7 +72,9 @@ impl<T: ThinAtom> AtomDynfo for ThinAtomDynfo<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ThinAtom: AtomCard<Data = Self> + Atomic<Variant = ThinVariant> + Coding + Send + Sync + 'static {
|
||||
pub trait ThinAtom:
|
||||
AtomCard<Data = Self> + Atomic<Variant = ThinVariant> + Coding + Send + Sync + 'static
|
||||
{
|
||||
#[allow(unused_variables)]
|
||||
fn call(&self, arg: ExprHandle) -> GenExpr { bot(err_not_callable()) }
|
||||
#[allow(unused_variables)]
|
||||
|
||||
@@ -127,7 +127,7 @@ fn extension_main_logic(data: ExtensionData) {
|
||||
};
|
||||
let mut tia_ctx = TIACtxImpl{
|
||||
lazy: &mut lazy_mems,
|
||||
ctx: ctx.clone(),
|
||||
sys: ctx.clone(),
|
||||
basepath: &[],
|
||||
path: Substack::Bottom,
|
||||
};
|
||||
@@ -156,9 +156,12 @@ fn extension_main_logic(data: ExtensionData) {
|
||||
Some(MemberRecord::Gen(path, cb)) => (path, cb),
|
||||
};
|
||||
let tree = cb.build(path.clone());
|
||||
let ctx = SysCtx::new(*sys_id, &sys.cted, &logger, req.reqnot());
|
||||
let reply_tree = tree.into_api(&mut TIACtxImpl{ ctx: ctx.clone(), lazy, path: Substack::Bottom, basepath: &path });
|
||||
req.handle(get_tree, &reply_tree)
|
||||
req.handle(get_tree, &tree.into_api(&mut TIACtxImpl{
|
||||
sys: SysCtx::new(*sys_id, &sys.cted, &logger, req.reqnot()),
|
||||
path: Substack::Bottom,
|
||||
basepath: &path,
|
||||
lazy,
|
||||
}))
|
||||
}
|
||||
api::HostExtReq::VfsReq(api::VfsReq::GetVfs(get_vfs@api::GetVfs(sys_id))) => {
|
||||
let systems_g = systems.lock().unwrap();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use orchid_base::interner::Tok;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
@@ -9,6 +8,7 @@ use lazy_static::lazy_static;
|
||||
use never::Never;
|
||||
use orchid_api_traits::Encode;
|
||||
use orchid_base::error::OrcRes;
|
||||
use orchid_base::interner::Tok;
|
||||
use orchid_base::name::Sym;
|
||||
use trait_set::trait_set;
|
||||
|
||||
@@ -27,12 +27,12 @@ pub trait ExprFunc<I, O>: Clone + Send + Sync + 'static {
|
||||
fn apply(&self, v: Vec<ExprHandle>) -> OrcRes<GenExpr>;
|
||||
}
|
||||
|
||||
lazy_static!{
|
||||
lazy_static! {
|
||||
static ref FUNS: Mutex<HashMap<Sym, (u8, Arc<dyn FunCB>)>> = Mutex::default();
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Fun{
|
||||
pub(crate) struct Fun {
|
||||
path: Sym,
|
||||
args: Vec<ExprHandle>,
|
||||
arity: u8,
|
||||
@@ -64,8 +64,8 @@ impl OwnedAtom for Fun {
|
||||
if new_args.len() == self.arity.into() {
|
||||
(self.fun)(new_args).to_expr()
|
||||
} else {
|
||||
Self {
|
||||
args: new_args, arity: self.arity, fun: self.fun.clone(), path: self.path.clone() }.to_expr()
|
||||
Self { args: new_args, arity: self.arity, fun: self.fun.clone(), path: self.path.clone() }
|
||||
.to_expr()
|
||||
}
|
||||
}
|
||||
fn call(self, arg: ExprHandle) -> GenExpr { self.call_ref(arg) }
|
||||
@@ -83,10 +83,10 @@ impl OwnedAtom for Fun {
|
||||
|
||||
mod expr_func_derives {
|
||||
use orchid_base::error::OrcRes;
|
||||
use crate::func_atom::GenExpr;
|
||||
|
||||
use super::ExprFunc;
|
||||
use crate::conv::{TryFromExpr, ToExpr};
|
||||
use crate::func_atom::ExprHandle;
|
||||
use crate::conv::{ToExpr, TryFromExpr};
|
||||
use crate::func_atom::{ExprHandle, GenExpr};
|
||||
|
||||
macro_rules! expr_func_derive {
|
||||
($arity: tt, $($t:ident),*) => {
|
||||
@@ -106,18 +106,18 @@ mod expr_func_derives {
|
||||
}
|
||||
};
|
||||
}
|
||||
expr_func_derive!(1, A);
|
||||
expr_func_derive!(2, A, B);
|
||||
expr_func_derive!(3, A, B, C);
|
||||
expr_func_derive!(4, A, B, C, D);
|
||||
expr_func_derive!(5, A, B, C, D, E);
|
||||
expr_func_derive!(6, A, B, C, D, E, F);
|
||||
expr_func_derive!(7, A, B, C, D, E, F, G);
|
||||
expr_func_derive!(8, A, B, C, D, E, F, G, H);
|
||||
expr_func_derive!(9, A, B, C, D, E, F, G, H, I);
|
||||
expr_func_derive!(1, A);
|
||||
expr_func_derive!(2, A, B);
|
||||
expr_func_derive!(3, A, B, C);
|
||||
expr_func_derive!(4, A, B, C, D);
|
||||
expr_func_derive!(5, A, B, C, D, E);
|
||||
expr_func_derive!(6, A, B, C, D, E, F);
|
||||
expr_func_derive!(7, A, B, C, D, E, F, G);
|
||||
expr_func_derive!(8, A, B, C, D, E, F, G, H);
|
||||
expr_func_derive!(9, A, B, C, D, E, F, G, H, I);
|
||||
expr_func_derive!(10, A, B, C, D, E, F, G, H, I, J);
|
||||
expr_func_derive!(11, A, B, C, D, E, F, G, H, I, J, K);
|
||||
expr_func_derive!(12, A, B, C, D, E, F, G, H, I, J, K, L);
|
||||
expr_func_derive!(13, A, B, C, D, E, F, G, H, I, J, K, L, M);
|
||||
expr_func_derive!(14, A, B, C, D, E, F, G, H, I, J, K, L, M, N);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,17 +55,12 @@ pub trait Lexer: Send + Sync + Sized + Default + 'static {
|
||||
|
||||
pub trait DynLexer: Send + Sync + 'static {
|
||||
fn char_filter(&self) -> &'static [RangeInclusive<char>];
|
||||
fn lex<'a>(&self, tail: &'a str, ctx: &'a LexContext<'a>)
|
||||
-> OrcRes<(&'a str, GenTokTree<'a>)>;
|
||||
fn lex<'a>(&self, tail: &'a str, ctx: &'a LexContext<'a>) -> OrcRes<(&'a str, GenTokTree<'a>)>;
|
||||
}
|
||||
|
||||
impl<T: Lexer> DynLexer for T {
|
||||
fn char_filter(&self) -> &'static [RangeInclusive<char>] { T::CHAR_FILTER }
|
||||
fn lex<'a>(
|
||||
&self,
|
||||
tail: &'a str,
|
||||
ctx: &'a LexContext<'a>,
|
||||
) -> OrcRes<(&'a str, GenTokTree<'a>)> {
|
||||
fn lex<'a>(&self, tail: &'a str, ctx: &'a LexContext<'a>) -> OrcRes<(&'a str, GenTokTree<'a>)> {
|
||||
T::lex(tail, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ pub trait DynSystemCard: Send + Sync + 'static {
|
||||
/// Atoms supported by this package which may appear in all extensions.
|
||||
/// The indices of these are bitwise negated, such that the MSB of an atom index
|
||||
/// marks whether it belongs to this package (0) or the importer (1)
|
||||
fn general_atoms() -> &'static [Option<&'static dyn AtomDynfo>] { &[/*Some(Fun::INFO)*/] }
|
||||
fn general_atoms() -> &'static [Option<&'static dyn AtomDynfo>] {
|
||||
&[/*Some(Fun::INFO)*/]
|
||||
}
|
||||
|
||||
pub fn atom_info_for(
|
||||
sys: &(impl DynSystemCard + ?Sized),
|
||||
|
||||
@@ -8,8 +8,7 @@ use itertools::Itertools;
|
||||
use orchid_base::interner::{intern, Tok};
|
||||
use orchid_base::location::Pos;
|
||||
use orchid_base::name::Sym;
|
||||
use orchid_base::tree::{ttv_to_api, TokTree, Token};
|
||||
use ordered_float::NotNan;
|
||||
use orchid_base::tree::{TokTree, Token};
|
||||
use substack::Substack;
|
||||
use trait_set::trait_set;
|
||||
|
||||
@@ -28,13 +27,6 @@ pub fn do_extra(f: &AtomFactory, r: Range<u32>, ctx: SysCtx) -> api::TokenTree {
|
||||
api::TokenTree { range: r, token: api::Token::Atom(f.clone().build(ctx)) }
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GenMacro {
|
||||
pub pattern: Vec<GenTokTree<'static>>,
|
||||
pub priority: NotNan<f64>,
|
||||
pub template: Vec<GenTokTree<'static>>,
|
||||
}
|
||||
|
||||
pub struct GenItem {
|
||||
pub item: GenItemKind,
|
||||
pub comments: Vec<(String, Pos)>,
|
||||
@@ -43,11 +35,6 @@ pub struct GenItem {
|
||||
impl GenItem {
|
||||
pub fn into_api(self, ctx: &mut impl TreeIntoApiCtx) -> api::Item {
|
||||
let kind = match self.item {
|
||||
GenItemKind::Rule(m) => api::ItemKind::Rule(api::Macro {
|
||||
pattern: ttv_to_api(m.pattern, &mut |f, r| do_extra(f, r, ctx.sys())),
|
||||
priority: m.priority,
|
||||
template: ttv_to_api(m.template, &mut |f, r| do_extra(f, r, ctx.sys())),
|
||||
}),
|
||||
GenItemKind::Raw(item) => api::ItemKind::Raw(Vec::from_iter(
|
||||
item.into_iter().map(|t| t.to_api(&mut |f, r| do_extra(f, r, ctx.sys()))),
|
||||
)),
|
||||
@@ -84,21 +71,9 @@ pub fn root_mod(
|
||||
}
|
||||
pub fn fun<I, O>(exported: bool, name: &str, xf: impl ExprFunc<I, O>) -> GenItem {
|
||||
let fac = LazyMemberFactory::new(move |sym| GenMemberKind::Const(Fun::new(sym, xf).to_expr()));
|
||||
let mem = GenMember{ exported, name: intern(name), kind: GenMemberKind::Lazy(fac) };
|
||||
let mem = GenMember { exported, name: intern(name), kind: GenMemberKind::Lazy(fac) };
|
||||
GenItemKind::Member(mem).at(Pos::Inherit)
|
||||
}
|
||||
pub fn rule(
|
||||
priority: f64,
|
||||
pat: impl IntoIterator<Item = GenTokTree<'static>>,
|
||||
tpl: impl IntoIterator<Item = GenTokTree<'static>>,
|
||||
) -> GenItem {
|
||||
GenItemKind::Rule(GenMacro {
|
||||
pattern: pat.into_iter().collect(),
|
||||
priority: NotNan::new(priority).expect("Rule created with NaN prio"),
|
||||
template: tpl.into_iter().collect(),
|
||||
})
|
||||
.at(Pos::Inherit)
|
||||
}
|
||||
|
||||
pub fn comments<'a>(cmts: impl IntoIterator<Item = &'a str>, mut val: GenItem) -> GenItem {
|
||||
val.comments.extend(cmts.into_iter().map(|c| (c.to_string(), Pos::Inherit)));
|
||||
@@ -122,7 +97,6 @@ impl Clone for LazyMemberFactory {
|
||||
pub enum GenItemKind {
|
||||
Member(GenMember),
|
||||
Raw(Vec<GenTokTree<'static>>),
|
||||
Rule(GenMacro),
|
||||
}
|
||||
impl GenItemKind {
|
||||
pub fn at(self, position: Pos) -> GenItem {
|
||||
@@ -140,7 +114,7 @@ impl GenMember {
|
||||
api::Member {
|
||||
name: self.name.marker(),
|
||||
exported: self.exported,
|
||||
kind: self.kind.into_api(&mut ctx.push_path(self.name))
|
||||
kind: self.kind.into_api(&mut ctx.push_path(self.name)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,20 +144,20 @@ pub trait TreeIntoApiCtx {
|
||||
}
|
||||
|
||||
pub struct TIACtxImpl<'a, 'b> {
|
||||
pub ctx: SysCtx,
|
||||
pub sys: SysCtx,
|
||||
pub basepath: &'a [Tok<String>],
|
||||
pub path: Substack<'a, Tok<String>>,
|
||||
pub lazy: &'b mut HashMap<api::TreeId, MemberRecord>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> TreeIntoApiCtx for TIACtxImpl<'a, 'b> {
|
||||
fn sys(&self) -> SysCtx { self.ctx.clone() }
|
||||
fn sys(&self) -> SysCtx { self.sys.clone() }
|
||||
fn push_path(&mut self, seg: Tok<String>) -> impl TreeIntoApiCtx {
|
||||
TIACtxImpl {
|
||||
ctx: self.ctx.clone(),
|
||||
sys: self.sys.clone(),
|
||||
lazy: self.lazy,
|
||||
basepath: self.basepath,
|
||||
path: self.path.push(seg)
|
||||
path: self.path.push(seg),
|
||||
}
|
||||
}
|
||||
fn with_lazy(&mut self, fac: LazyMemberFactory) -> api::TreeId {
|
||||
|
||||
Reference in New Issue
Block a user