summary refs log tree commit diff stats
path: root/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm.rs')
-rw-r--r--src/vm.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/vm.rs b/src/vm.rs
index 5b27a36..44675f3 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -1,4 +1,23 @@
+/*
+ * This file is part of Datafu
+ * Copyright (C) 2021  Soni L.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
 use crate::KVPair;
+use crate::RefOwn;
 use crate::PatternTypes;
 use crate::Predicate;
 use crate::errors::MatchError;
@@ -23,7 +42,7 @@ pub(crate) struct PatternConstants<T: PatternTypes> {
     // NOTE these are part of the constant pool and so have lifetime analogous
     // to 'a (consistently used to indicate constant pool lifetime) when used
     // elsewhere. In particular, they can't be yielded by the iterator.
-    pub(crate) defs: Vec<T::Value>,
+    pub(crate) defs: Vec<T::Own>,
 }
 
 /// A pattern element.
@@ -49,7 +68,7 @@ impl<T: PatternTypes> Clone for PatternElement<T> {
 }
 
 struct Frame<'a, 'b, T: PatternTypes> {
-    obj: &'b T::Value,
+    obj: RefOwn<'b, T::Ref, T::Own>,
     ops: &'a Vec<PatternElement<T>>,
     iar: Option<usize>,
     depth: usize,
@@ -97,7 +116,7 @@ enum HolderState<'a, 'b, T: PatternTypes> {
     EmptyKey,
     EmptySubtree,
     Key(KVPair<'b, T>),
-    Subtree(Matches<'a, 'b, T>, &'b T::Value),
+    Subtree(Matches<'a, 'b, T>, RefOwn<'b, T::Ref, T::Own>),
 }
 
 impl<'a, 'b, T: PatternTypes> Clone for HolderState<'a, 'b, T> {
@@ -120,8 +139,8 @@ impl<'a, 'b, T: PatternTypes> HolderState<'a, 'b, T> {
         matches!(self, HolderState::EmptySubtree | HolderState::Subtree {..})
     }
 
-    fn value(&self) -> Option<&'b T::Value> {
-        match self {
+    fn value(&self) -> Option<RefOwn<'b, T::Ref, T::Own>> {
+        match *self {
             HolderState::Key((_, value)) => Some(value),
             HolderState::Subtree(_, value) => Some(value),
             _ => None
@@ -136,7 +155,7 @@ impl<'a, 'b, T: PatternTypes> HolderState<'a, 'b, T> {
 struct Holder<'a, 'b, T: PatternTypes> {
      name: Option<&'a str>,
      value: HolderState<'a, 'b, T>,
-     parent: Option<&'b T::Value>,
+     parent: Option<RefOwn<'b, T::Ref, T::Own>>,
      iterator: Box<dyn Iterator<Item=KVPair<'b, T>> + 'b>,
      filters: Vec<Box<dyn for<'c> Fn(&'c mut HolderState<'a, 'b, T>) + 'a>>,
 }
@@ -176,7 +195,7 @@ pub struct Matcher<'a, 'b, T: PatternTypes> {
 }
 
 impl<'a, 'b, T: PatternTypes> Matcher<'a, 'b, T> {
-    pub(crate) fn new(obj: &'b T::Value, defs: &'a PatternConstants<T>, proto: usize, rlimit: usize) -> Result<Self, MatchError> {
+    pub(crate) fn new(obj: RefOwn<'b, T::Ref, T::Own>, defs: &'a PatternConstants<T>, proto: usize, rlimit: usize) -> Result<Self, MatchError> {
         let depth = rlimit.checked_sub(1).ok_or(MatchError::StackOverflow)?;
         let ops: &Vec<_> = &defs.protos[proto];
         Ok(Self {