From c9917c8bcdf9ffecfd7661ea8597312c0d311b09 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sun, 31 Jul 2022 20:58:42 +0800 Subject: [PATCH] new API --- src/data/mod.rs | 1 + src/data/program.rs | 147 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 src/data/program.rs diff --git a/src/data/mod.rs b/src/data/mod.rs index 0c116cdf..a0cbfa9a 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -8,4 +8,5 @@ pub(crate) mod triple; pub(crate) mod value; pub(crate) mod tuple; pub(crate) mod expr; +pub(crate) mod program; diff --git a/src/data/program.rs b/src/data/program.rs new file mode 100644 index 00000000..d8531ed7 --- /dev/null +++ b/src/data/program.rs @@ -0,0 +1,147 @@ +use std::collections::BTreeMap; + +use smallvec::SmallVec; +use smartstring::{LazyCompact, SmartString}; + +use crate::data::attr::Attribute; +use crate::data::expr::{Expr, Op}; +use crate::data::keyword::Keyword; +use crate::data::value::DataValue; +use crate::{EntityId, Validity}; + +#[derive(Clone, Debug, Default)] +pub enum Aggregation { + #[default] + Todo, +} + +pub(crate) struct InputProgram { + prog: BTreeMap>, +} + +pub(crate) struct StratifiedNormalFormProgram(Vec); + +pub(crate) struct NormalFormProgram { + prog: BTreeMap>, +} + +pub(crate) struct StratifiedMagicProgram(Vec); + +pub(crate) struct MagicProgram { + prog: BTreeMap>, + keep_rules: Vec, +} + +enum MagicKeyword { + Muggle { + name: SmartString, + }, + Magic { + name: SmartString, + adornment: SmallVec<[bool; 8]>, + }, + Input { + to: SmartString, + adornment: SmallVec<[bool; 8]>, + }, + Sup { + deriving: SmartString, + rule_idx: u16, + sup_idx: u16, + }, +} + +pub(crate) struct InputRule { + head: Vec, + aggr: Vec>, + body: Vec, + vld: Validity, +} + +pub(crate) struct NormalFormRule { + head: Vec, + aggr: Vec>, + body: Vec, + vld: Validity, +} + +pub(crate) struct MagicRule { + head: Vec, + aggr: Vec>, + body: Vec, + vld: Validity, +} + +pub(crate) enum InputAtom { + AttrTriple(InputAttrTripleAtom), + Rule(InputRuleApplyAtom), + Predicate(Expr), + Negation(Box), + Conjunction(Vec), + Disjunction(Vec), + Unification(Unification), +} + +pub(crate) enum NormalFormAtom { + AttrTriple(NormalFormAttrTripleAtom), + Rule(NormalFormRuleApplyAtom), + Predicate(Expr), + Negation(Box), + Unification(Unification), +} + +pub(crate) enum MagicAtom { + AttrTriple(MagicAttrTripleAtom), + Rule(MagicRuleApplyAtom), + Predicate(Expr), + Negation(Box), + Unification(Unification), +} + +#[derive(Clone, Debug)] +pub struct InputAttrTripleAtom { + pub(crate) attr: Attribute, + pub(crate) entity: InputTerm, + pub(crate) value: InputTerm, +} + +pub struct NormalFormAttrTripleAtom { + attr: Attribute, + entity: Keyword, + value: Keyword, +} + +pub(crate) struct MagicAttrTripleAtom { + attr: Attribute, + entity: Keyword, + value: Keyword, + entity_is_bound: bool, + value_is_bound: bool, +} + +#[derive(Clone, Debug)] +pub struct InputRuleApplyAtom { + pub(crate) name: Keyword, + pub(crate) args: Vec>, +} + +pub struct NormalFormRuleApplyAtom { + name: Keyword, + args: Vec, +} + +pub(crate) struct MagicRuleApplyAtom { + name: MagicKeyword, + args: Vec, +} + +#[derive(Clone, Debug)] +pub enum InputTerm { + Var(Keyword), + Const(T), +} + +pub struct Unification { + binding: Keyword, + expr: Expr, +}